-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
73 lines (72 loc) · 2.05 KB
/
Copy pathwebpack.config.js
File metadata and controls
73 lines (72 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
commonConfig = {
entry: {
app: [
path.join(__dirname, 'src/index.js')
],
vendor: ['react', 'react-router-dom', 'redux', 'react-dom', 'react-redux']
},
output: {
path: path.join(__dirname, './dist'),
filename: 'js/[name].[chunkhash].js',
chunkFilename: 'js/[name].[chunkhash].js',
publicPath: "/"
},
module: {
rules: [{
test: /\.js|jsx$/,
use: ['babel-loader?cacheDirectory', {
loader: 'eslint-loader',
options: {
fix:true,
formatter: require('eslint-friendly-formatter')
}
}],
include: path.join(__dirname, 'src')
}, {
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: ['css-loader?modules&minimize', 'postcss-loader']
})
}, {
test: /\.scss$/,
include: path.join(__dirname, 'src'),
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: ['css-loader?sourceMap&minimize', 'postcss-loader', 'sass-loader']
})
}, {
test: /\.(png|jpg|gif)$/,
loader: ['url-loader?limit=8192&name=images/[name].[hash:8].[ext]']
}]
},
plugins: [
//⚙设置编译环境
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
}),
//创建HTML文件
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.join(__dirname, 'src/index.tpl.html')
}),
new webpack.HashedModuleIdsPlugin(),
//拆分公共模块
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor'
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'runtime'
}),
new ExtractTextPlugin({
filename: 'css/[name].[contenthash:5].css',
allChunks: true,
disable: process.env.NODE_ENV != 'production' //非生产环境不分离css
})
]
};
module.exports = commonConfig;