我有一个webpack项目,在这里我想将一些常用的依赖项拆分为一个“供应商”捆绑包。我有一个现有的设置,非常适合采用第三方节点模块库。这是一个Web应用程序,每个页面都有“延迟加载”捆绑包。我有一个要在其中几个捆绑文件中引用的JSON文件,但它约为2 MB,默认情况下,webpack为每个实例创建一个副本,大大增加了我的构建大小。
因此,在我的vendor.webpack.config.js
中:
const config = {
entry: {
common: [/* A bunch of npm libaries */],
assets: ["./assets/myfile.json"]
},
output: {
filename: "[name].bundle.js",
path: path.resolve(__dirname, "common-dist"),
// The name of the global variable which the library's
// require() function will be assigned to
library: "[name]_lib"
},
devtool: sourceMap,
plugins: []
};
config.plugins = [
new webpack.DllPlugin({
path: "common-dist/[name]-manifest.json",
name: "[name]_lib"
})
];
module.exports = config;
构建dll会给我2套捆绑软件,一套用于“ common”,另一套用于“ assets”。每个捆绑包看起来都是正确的。
然后在webpack.config.json中我拥有
new webpack.DllReferencePlugin({
context: '.',
manifest: require('./common-dist/common-manifest.json')
}),
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require("./common-dist/assets-manifest.json"),
}),
然后在我的应用程序中
// somefile.js
import SomeThing from "assets"
但是,运行构建失败,因为无法解决该导入。
如何引用assets-manifest.json
以使myFile.json可在应用程序中导入?它有一个出口,由清单正确识别:
// asssets-manifest.json
{"name":"assets_lib","content":{"./assets/myFile.json":{"id":"./assets/myFile.json","buildMeta":{"exportsType":"named","providedExports":["SomeThing","default"]}}}}
还是我把这件事搞错了?