代码拉取完成,页面将自动刷新
'use strict';
const Path = require('path');
const Clean = require('clean-webpack-plugin');
const Extract = require('extract-text-webpack-plugin');
const Html = require('html-webpack-plugin');
const Stats = require('webpack-stats-plugin').StatsWriterPlugin;
const Webpack = require('webpack');
if (!process.env.NODE_ENV) {
process.env.NODE_ENV = 'development';
}
const env = process.env.NODE_ENV;
const outputPath = Path.join(__dirname, env);
const extractCSS = new Extract({filename: 'styles-[contenthash].css', allChunks: true});
const getCSSLoaders = (env) => {
if (env === 'development') {
return [
{ loader: 'style-loader' },
{ loader: 'css-loader',
options: {modules: true, localIdentName: '[local]__[hash:base64:5]'},
},
];
}
return extractCSS.extract([
{ loader: 'css-loader',
// this must be `query`. if it is `option` the imported classNames are all `undefined`.
query: {modules: true, localIdentName: '[hash:base64:5]'},
},
]);
};
const getPluginsForEnv = (env) => {
if (env === 'production') {
return [extractCSS];
}
return [];
}
module.exports = {
entry: Path.join(__dirname, 'app', 'index.js'),
output: {
path: outputPath,
filename: '[name]_[hash].js',
},
resolve: {
extensions: ['.js', '.css'],
},
module: {
rules: [
{ test: /\.js$/,
exclude: /node_modules/,
use: [
{ loader: 'babel-loader',
query: {
presets: [['es2015', {modules: false}]],
plugins: ['transform-runtime'],
},
},
],
},
{ test: /\.css$/,
loader: getCSSLoaders(env),
},
],
},
plugins: [
new Webpack.EnvironmentPlugin('NODE_ENV'),
new Clean(outputPath),
new Stats({fields: null}),
new Html({
template: 'index.template',
inject: 'body',
}),
new Webpack.LoaderOptionsPlugin({
debug: true,
options: {
context: Path.join(__dirname, 'app')
},
})
].concat(getPluginsForEnv(env)),
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。