-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.pro.js
140 lines (133 loc) · 3.13 KB
/
webpack.pro.js
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
* Created by zhongwangsheng on 2017/12/4.
*/
const webpack = require('webpack')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')
let plugins = []
//0. 定义环境
plugins.push(new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production') //定义编译环境
}
}));
//1.独立css
plugins.push(new ExtractTextPlugin({
filename:'[name].css'
}));
//2.动态嵌入静态资源
plugins.push(new HtmlWebpackPlugin({
title : '抚琴知音',
filename: '../built/index.html',
template: './src/Template/index.html',
hash: true
}));
//3.抽取公共js
plugins.push(new webpack.optimize.CommonsChunkPlugin({
name : "vendor",
filename :"vendor.[hash:8].js"
}));
//4.压缩JS
plugins.push(new webpack.optimize.UglifyJsPlugin({
output : { comments: false },
compress : { warnings: false }
}));
//清除旧文件
plugins.push(new CleanWebpackPlugin(['./built']));
module.exports = {
entry: {
app: './src/Main',
vendor: [
"react",
"react-dom",
"lodash",
"moment"
]
},
output: {
publicPath : './',
path : __dirname + '/built',
filename: '[name].[hash:8].js'
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /^node_modules$/,
use: [
{
loader: "babel-loader",
options: {
presets: ['es2015','react', 'stage-2'],
compact: 'false',
plugins: [
'syntax-dynamic-import',
["import", { "libraryName": "antd", "libraryDirectory": "es", "style": "css" }] // `style: true` 会加载 less 文件
]
}
},
//{ loader :'eslint-loader' }
]
},
{
test: /\.css$/,
exclude: /^node_modules$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: [
{
loader: 'css-loader',
options: { importLoaders: 1 }
},
{ loader: 'postcss-loader'},
]
})
},
{
test: /\.scss/,
exclude: /^node_modules$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: [
{
loader: 'css-loader',
options: {
importLoaders: 1
}
},
{ loader: 'sass-loader'},
{ loader: 'postcss-loader'},
]
})
},
{
test: /\.(eot|woff|svg|ttf|woff2|gif|appcache)(\?|$)/,
exclude: /^node_modules$/,
use: [
{
loader: "file-loader",
options: { name: '/font/[name].[ext]' }
}
]
},
{
test: /\.(png|jpg)$/,
exclude: /^node_modules$/,
use: [
{
loader: "url-loader",
options: {
limit: 20000,
name: '[name].[ext]'
}
}
]
}
]
},
resolve: {
extensions: ['.js', '.jsx']
},
plugins
};