我的问题是这样的Wepback - 包括脚本标签,如果环境设置为生产
https://github.com/petehunt/webpack-howto/issues/46
或 - 我如何获得的WebPack包括基于关我的环境的脚本代码插入HTML?如果我在生产环境中运行,我只想包含某个脚本标记。
这是我目前的webpack文件的样子(我正在使用webpack 2)。
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const VENDOR_LIBS = [
'axios', 'react', 'react-dom', 'react-router', 'react-apollo', 'prop-types'
];
module.exports = {
entry: {
bundle: './client/src/index.js',
vendor: VENDOR_LIBS
},
output: {
path: path.join(__dirname, 'dist'),
publicPath: '/',
filename: '[name].[chunkhash].js'
},
module: {
rules: [
{
use: 'babel-loader',
test: /\.js$/,
exclude: /node_modules/
},
{
test: /\.scss$/,
use: [{
loader: "style-loader"
}, {
loader: "css-loader"
}, {
loader: "sass-loader"
}]
},
{
test: /\.(jpe?g|png|gif|svg|)$/,
use: [
{
loader: 'url-loader',
options: {limit: 40000}
},
'image-webpack-loader'
]
}
]
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
names: ['vendor', 'manifest']
}),
new HtmlWebpackPlugin({
template: './client/src/index.html'
})
]
};
了解此脚本标记的用途以及为什么只需要它用于生产会很有帮助。 – hansn