DEV Community

Discussion on: I maintain webpack, ask me anything!

Collapse
 
xybin1990 profile image
Nic • Edited

hi,Sean.
i use DllPlugin to produces bundle.dll.js and put it on cdn.
then,i use externals extract the library,but there is an error i dont understand

  • webpack.bundle.dll.js
const webpack = require('webpack');
const path = require('path');

module.exports = {
    entry: {
        bundle: [
            'vue',
            'vuex',
            'axios',
            "vue-router"
        ],
    },
    output: {
        path: path.join(__dirname, 'dll'),
        filename: '[name].dll.js'
    },
    plugins: [
        new webpack.DllPlugin({
            path: path.join(__dirname, 'dll', '[name]-manifest.json'),
            name: '[name]',
        }),
        new webpack.optimize.UglifyJsPlugin({
            beautify: false,
            comments: false,
            compress: {
                warnings: false,
                drop_console: true, //no console
            }
        }),
    ]
};
  • webpack.config.js
externals: {
    'vue': 'vue',
     "vuex": 'vuex',
     'axios': 'axios',
     'vue-router': 'vue-router'
},
new webpack.DllReferencePlugin({
      context: path.join(__dirname),
      manifest: require('./dll/bundle-manifest.json')
})

the error

index.min.js?b40cc7a554404568b02b:2844 Uncaught ReferenceError: vue is not defined
    at Object.<anonymous> (index.min.js?b40cc7a554404568b02b:2844)
    at __webpack_require__ (index.min.js?b40cc7a554404568b02b:689)
    at fn (index.min.js?b40cc7a554404568b02b:110)
    at Object.<anonymous> (index.min.js?b40cc7a554404568b02b:5096)
    at __webpack_require__ (index.min.js?b40cc7a554404568b02b:689)
    at fn (index.min.js?b40cc7a554404568b02b:110)
    at Object.<anonymous> (index.min.js?b40cc7a554404568b02b:13318)
    at __webpack_require__ (index.min.js?b40cc7a554404568b02b:689)
    at module.exports (index.min.js?b40cc7a554404568b02b:790)
    at index.min.js?b40cc7a554404568b02b:793