Webpack Aurelia-如何配置并非所有块都与Aurelia捆绑在一起?

问题描述

我正在使用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会按预期生成两个块:appaddOn。唯一意外的(不需要的)是,两个块都与aurelia模块捆绑在一起。只有appaurelia模块捆绑在一起。

我如何确定应与aurelia模块捆绑在一起的块?

解决方法

可以使用对象文字将要使用的entry传递给AureliaPlugin的构造函数:

new AureliaPlugin({
  entry: 'app',})

entry选项和其他选项可以在这里找到:https://github.com/aurelia/webpack-plugin/wiki/AureliaPlugin-options