web-xiangsonghua/dwt-ems/webpack-ems/webpack.config.js
2024-12-23 15:13:57 +08:00

112 lines
3.4 KiB
JavaScript

let path = require('path');
let entry = require('./webpack.entry.js');
let htmlPlugins = require('./webpack.html.js');
let ReleaseHandlePlugin = require('./releaseHandlePlugin');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
var CleanWebpackPlugin = require('clean-webpack-plugin');
let config = {
context: __dirname,
entry: entry,
output: {
path: path.resolve('./dist/'),
publicPath: '', // 插入到html中的静态文件的路径前缀
filename: '[name].[hash].js'
},
module: {
rules: [{
test: /\.js$/,
exclude: function (path) {
// 路径中含有 node_modules 的就不去解析。
var isNpmModule = !!path.match(/node_modules/);
return isNpmModule;
},
loaders: [{
loader: 'babel-loader',
query: {
presets: ['es2015']
}
}],
},
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
minimize: true //css压缩
}
},
{
loader: 'sass-loader',
options: {
minimize: true //css压缩
}
},
]
})
}, {
test: /\.css$/,
use: [{
loader: 'style-loader' // 将 JS 字符串生成为 style 节点
}, {
loader: 'css-loader' // 将 CSS 转化成 CommonJS 模块
}]
}, {
test: /\.(woff2?|eot|svg|ttf|otf)(\?.*)?$/,
use: [{
loader: 'url-loader'
}]
}, {
test: /\.ejs$/,
use: [{
loader: 'ejs-loader'
}]
}]
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: 'common',
minChunks: ({resource}) => {
resource &&
resource.indexOf('node_modules') &&
resource.match(/\.js$/)
}
}),
new webpack.ProvidePlugin({
Promise: 'es6-promise-promise'
}),
new ExtractTextPlugin('[name].[hash].css')
].concat(htmlPlugins)
};
if (process.env.NODE_ENV == 'development') {
config.devServer = {
inline: true,
historyApiFallback: true,
port: 8081,
host: 'ems.dianwutong.com'
};
config.plugins.push(new webpack.DllReferencePlugin({
context: __dirname,
manifest: require('./build/dev/vendor-manifest.json')
}));
} else if (process.env.NODE_ENV == 'test') {
config.plugins.push(new CleanWebpackPlugin(['dist']));
config.plugins.push(new ReleaseHandlePlugin({ env: 'test' }));
config.plugins.push(new webpack.optimize.UglifyJsPlugin());
} else if (process.env.NODE_ENV == 'production') {
config.plugins.push(new CleanWebpackPlugin(['dist']));
config.plugins.push(new webpack.optimize.UglifyJsPlugin());
config.plugins.push(new ReleaseHandlePlugin({ env: 'production' }));
}
module.exports = config;