【问题标题】:Webpack 2 chunk name contains undefinedWebpack 2 块名称包含未定义
【发布时间】:2017-04-13 17:13:37
【问题描述】:

我正在尝试升级到 Webpack 2。我成功地使用了 Webpack 1 的代码拆分和按需加载(使用 require.ensure)。但是,对于 webpack 2,块的文件名包含一个“未定义”,导致它变为 404。

webpack.config.js

{
  entry: {
    'main': 'index.ts',
    'vendor': 'vendor.ts'
  },

  output: {
    filename: '[name].[hash].bundle.js',
    chunkFilename: '[hash].js',
    path: path.resolve(__dirname, '../dist')
  },

  devServer: {
    proxy: {
      //proxy info
    }
  },
  resolve: {
    modules: [
      helper.root('src'),
      'node_modules'
    ],
    extensions: ['.ts', '.js', '.json'],
  },

  cache: false,
  devtool: 'cheap-source-map',
  plugins: [
    new webpack.optimize.CommonsChunkPlugin({
      name: 'vendor',
       minChunks: function (module) {
        return module.context && module.context.indexOf('node_modules') !== -1;
      }
    }),
    new webpack.optimize.CommonsChunkPlugin({ 
      name: 'manifest'
    }),
    new ExtractTextPlugin({
      filename:'[name]-[hash].css',
      allChunks: true
    }),
    new HtmlWebpackPlugin({
      template: './src/index.html',
      inject: true
    }),
    new ngAnnotatePlugin({
      add: true
    }),
    new OptimizeCssAssetsPlugin({
      assetNameRegExp: /\.optimize\.css$/g,
      cssProcessor: require('cssnano'),
      cssProcessorOptions: { discardComments: { removeAll: true } },
      canPrint: true
    }),
    new webpack.LoaderOptionsPlugin(require('../tslint.json')),
    new webpack.LoaderOptionsPlugin({
      configFile: './.htmlhintrc'
    }),
    new webpack.LoaderOptionsPlugin({
      configFile: './.sass-lint.yml'
    }),
    new DashboardPlugin(),
    new webpack.ContextReplacementPlugin(/moment[\\\/]locale$/, /^\.\/(de|en|fr|ko|ja|zh-cn)$/)
  ],
  module: {
    rules: loaders
  },
}

我已经尝试过chunkFilename 的不同变体(在许多组合中使用[name]、[id]、[chunkhash])。它们都不起作用。我该如何解决这个问题?

【问题讨论】:

    标签: webpack webpack-dev-server webpack-2


    【解决方案1】:

    发现问题。我将__webpack_public_path 设置为未定义的变量。

    【讨论】:

      猜你喜欢
      • 2021-08-16
      • 2019-12-04
      • 2016-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-09
      • 2020-05-05
      相关资源
      最近更新 更多