先执行webpack.dll.js

  1. const path = require('path');
  2. const webpack = require('webpack');
  3. const { CleanWebpackPlugin } = require('clean-webpack-plugin');
  4. module.exports = {
  5. entry:{
  6. vendor:['./src/vendor/index.js']
  7. },
  8. output:{
  9. filename: '[name].dll2.js',
  10. path: path.resolve(__dirname,'dll'),
  11. library: "[name]_library",
  12. },
  13. plugins:[
  14. new CleanWebpackPlugin(),
  15. new webpack.DllPlugin({
  16. path: __dirname + "/dll/[name]-manifest.json",
  17. name: "[name]_library"
  18. })
  19. ]
  20. }

其次执行webpack.config.js

这里引入了vendor-manifest.json来自webpack.dll.js生成的

 config.plugins.push(new webpack.DllReferencePlugin({
   manifest: require("./dll/vendor-manifest.json") // eslint-disable-line
 }))