我正在尝试将我的 Aurelia 应用程序从 System.js + JSPM 移植到 Webpack。该应用程序有多个条目 html: index.html
, index2.html
.
由于我是 Webpack 的新手,我从使用 easy-webpack 的 aurelia 骨架开始,并尝试逐渐添加我的应用程序特定代码。
对于单一条目的最基本情况,index.html
骨架工作得很好。我还添加了我的本地模块,node_modules
并在app
.
但是,我无法为多条目 html 正确设置配置。这就是我的webpack.config.js
(显示修改的部分)的样子:
const baseConfig = {
entry: {
'app': [/* this is filled by the aurelia-webpack-plugin */],
'aurelia-bootstrap': coreBundles.bootstrap,
'aurelia': coreBundles.aurelia.filter(pkg => coreBundles.bootstrap.indexOf(pkg) === -1),
'some-common-script': path.resolve('src/some-common-script.js'),
'index1-script': path.resolve('src/index1-script'), //needed exclusively in index.html
'index2-script': path.resolve('src/index2-script') //needed exclusively in index2.html
}, ...
};
switch (ENV) {
...
default:
case 'development':
process.env.NODE_ENV = 'development';
config = generateConfig(
baseConfig,
...
require('@easy-webpack/config-common-chunks-simple')
({ appChunkName: 'app', firstChunk: 'aurelia-bootstrap' }),
require('@easy-webpack/config-generate-index-html')
({ minify: false, overrideOptions: { excludeChunks: ["index2-script"] } }),
require('@easy-webpack/config-generate-index-html')
({
minify: false, overrideOptions: {
chunks: ['some-common-script', 'index2-script'],
filename: 'index2.html',
template: 'index2.html',
}
}),...
);
break;
}
module.exports = config;
问题如下:
index2-script
如果我从默认值中排除config-generate-index-html
,则添加脚本的顺序index.html
变为app.bundle.js, aurelia-bootstrap.bundle.js, ...
,而不是aurelia-bootstrap.bundle.js, app.bundle.js, ...
,这会导致Uncaught ReferenceError: webpackJsonp is not defined...
.- 根据我的理解,错误是由于
easy-webpack/config-common-chunks-simple
(wrapper aroundwebpack.optimize.CommonsChunkPlugin
)将初始代码和通用代码打包到aurelia-bootstrap.bundle.js
(“bootstrap”块)中而引起的。因此,我也尝试过require('@easy-webpack/config-common-chunks-simple')({ appChunkName: 'app', firstChunk: 'aurelia-bootstrap' })
,但得到了Uncaught TypeError: Reflect.getOwnMetadata is not a function
从aurelia-metadata.js
, 和Uncaught TypeError: Cannot read property 'call' of undefined
fromwebpack:///webpack/bootstrap <hash>
,这似乎是因为找不到模块而引发的。
我对接下来应该尝试什么感到完全困惑。请建议。