我的問題是這樣的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