2017-04-13 59 views
0

Chunk name contains undefined的WebPack 2块名称包含未定义

我想升级到的WebPack 2.我用代码分裂与按需加载(使用require.ensure)用的WebPack 1成功。然而,随着的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(使用[名],[id],[chunkhash])。他们都没有工作。我该如何解决?

回答

0

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