【发布时间】:2019-04-04 13:05:59
【问题描述】:
我需要使用带有 Webpack 的生产版本。如果我现在在生产中访问我的网站,图标的背景为红色,这意味着它没有使用生产
当我执行 npm run build 时,它显示 npm ERR!缺少脚本:构建
如何调整 webpack 以便进行生产构建并使我的应用程序更快?
这是我的 webpack 配置:
const webpack = require('webpack');
const config = {
entry: ['babel-polyfill', './src/index.js'],
output: {
filename: 'bundle.js',
},
devServer: {
inline: true,
port: 8080,
historyApiFallback: true,
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
API_KEY: 'API_KEY',
GOOGLE_MAPS_KEY: 'GOOGLE_MAPS_KEY',
GOOGLE_GEOLOCATION_KEY: 'GOOGLE_GEOLOCATION_KEY',
},
}),
],
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['es2015', 'react'],
},
},
{
test: /\.css$/,
loader: 'style!css',
},
],
},
};
module.exports = config;
【问题讨论】: