0

我在我的开发环境中使用 DllPlugin,但是当我将引导程序添加到构建中时,我​​的供应商 dll 会中断。如果我注释掉引导程序,所有其他参考都在工作。这是我的配置文件的相关部分。

对于供应商构建

    entry: {
        vendor: [
            'bootstrap',
            'event-source-polyfill',
            'font-awesome/css/font-awesome.css',
            'ionicons/dist/css/ionicons.css',
            'isomorphic-fetch',
            'jquery',
        ],
    },            
    output: {
        path: path.join(__dirname, 'assets'),                
        filename: '[name].js',
        library: '[name]_[hash]',
    },
    plugins: [
        new CleanWebpackPlugin('assets'),
        extractCss,
        new webpack.ProvidePlugin({
            $: 'jquery',
            jQuery: 'jquery',
            'window.jQuery': 'jquery',
            Popper: ['popper.js', 'default'],
        }),
        new webpack.DllPlugin({
            path: path.join(__dirname, 'assets', '[name]-manifest.json'),
            name: '[name]_[hash]',
        }),
    ],

在运行时配置中,我只是引用链接,所以

    new webpack.DllReferencePlugin({
        context: __dirname,
        manifest: require('./assets/vendor-manifest.json'),
    }),

清单输出是

{"name":"vendor_c0cb30d4f33754762565","content":{"./node_modules/event-source-polyfill/src/eventsource.js":{"id":5,"meta":{}},"./node_modules/font-awesome/css/font-awesome.css":{"id":6,"meta":{}},"./node_modules/ionicons/dist/css/ionicons.css":{"id":7,"meta":{}},"./node_modules/isomorphic-fetch/fetch-npm-browserify.js":{"id":8,"meta":{}},"./node_modules/jquery/dist/jquery.js":{"id":0,"meta":{}},"./node_modules/whatwg-fetch/fetch.js":{"id":9,"meta":{}},"./node_modules/bootstrap/dist/js/bootstrap.js":{"id":2,"meta":{}},"./node_modules/popper.js/dist/esm/popper.js":{"id":3,"meta":{"harmonyModule":true},"exports":["default"]},"./node_modules/webpack/buildin/global.js":{"id":4,"meta":{}}}}

最后错误是

..\external "vendor_c0cb30d4f33754762565":1 Uncaught ReferenceError: vendor_c0cb30d4f33754762565 is not defined
    at Object.dll-reference vendor_c0cb30d4f33754762565 (..\external "vendor_c0cb30d4f33754762565":1)
    at __webpack_require__ (bootstrap ab071247d46d1a97c83e:678)
    at fn (bootstrap ab071247d46d1a97c83e:88)
    at Object../node_modules/webpack/buildin/global.js (global.js from dll-reference vendor_c0cb30d4f33754762565:1)
    at __webpack_require__ (bootstrap ab071247d46d1a97c83e:678)
    at fn (bootstrap ab071247d46d1a97c83e:88)
    at Object../node_modules/punycode/punycode.js (punycode.js:533)
    at __webpack_require__ (bootstrap ab071247d46d1a97c83e:678)
    at fn (bootstrap ab071247d46d1a97c83e:88)
    at Object../node_modules/url/url.js (url.js:24)

我是 DllPlugin 的新手,但设置看起来很简单。谢谢。

4

1 回答 1

0

在 DLL 捆绑配置中设置 ouput.library 选项

于 2018-05-03T13:36:24.323 回答