问题描述
我正在使用Aurelia的Webpack示例(https://aurelia.io/docs/build-systems/webpack/a-basic-example#basic-config-example)设置我的Webpack配置:
const { AureliaPlugin } = require('aurelia-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { resolve } = require('path')
module.exports = function(mode) {
return {
mode: mode || 'development',resolve: {
extensions: ['.ts','.js'],modules: [resolve(__dirname,'src'),resolve(__dirname,'node_modules')],},entry: {
addOn: './dist/ContentScript/WebExtContentScriptApp.js',// the 'aurelia-bootstrapper' entry point is responsible for resolving your app code
app: ['aurelia-bootstrapper'],output: {
filename: '[name].js',path: resolve(__dirname,'dist'),watch: mode === 'development',devtool: mode === 'development' ? 'inline-source-map' : 'source-map',devServer: {
contentBase: './dist',module: {
rules: [
{ test: /\.html$/i,loader: 'html-loader' },{ test: /\.ts$/i,loader: 'ts-loader' },],plugins: [
// the AureliaPlugin translates Aurelia's conventions to something Webpack understands
// and must be included in order for Webpack to work
new AureliaPlugin(),new HtmlWebpackPlugin({
template: 'index.ejs',chunks: ['app'],Metadata: { dev: mode !== 'production' },}),}
}
我添加了另一个entry
配置addOn
。现在运行webpack
会按预期生成两个块:app
和addOn
。唯一意外的(不需要的)是,两个块都与aurelia
模块捆绑在一起。只有app
与aurelia
模块捆绑在一起。
我如何确定应与aurelia
模块捆绑在一起的块?
解决方法
可以使用对象文字将要使用的entry
传递给AureliaPlugin
的构造函数:
new AureliaPlugin({
entry: 'app',})
entry
选项和其他选项可以在这里找到:https://github.com/aurelia/webpack-plugin/wiki/AureliaPlugin-options。