-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
87 lines (84 loc) · 2.43 KB
/
webpack.config.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
/**
* Created by aaron on 2017/4/10.
*/
let path = require('path');
let webpack = require('webpack');
let HtmlWebpackPlugin = require('html-webpack-plugin');
let BrowserSyncPlugin = require('browser-sync-webpack-plugin');
//环境变量,开发环境或者生产环境,npm将通过这个值来区分打包。
let isDev = process.env.NODE_ENV === 'development';
module.exports = {
context: path.join(__dirname, 'src'),
//监听文件改动
watch: isDev,
//入口js文件
entry: {
'index': './index.js'
},
output: {
path: path.resolve(__dirname, 'dist/'),
//文件命名
filename: isDev ? 'js/[name].js?hash=[chunkHash:7]' : 'js/[name].[chunkHash:7].js',
//生成js文件的相对路径
publicPath: './'
},
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html',
template: './tpl.html'
})
].concat(isDev
? [
new BrowserSyncPlugin(
{
server: {
baseDir: "dist",
index: "index.html"
}
},
{reload: true}
)]
: [
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
comments: false,
compress: {warnings: true}
})]
),
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: ['babel-loader']
},
{
test: /\.less/,
exclude: /node_modules/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: true,
localIdentName: '[name]-[local]-[hash:base64:5]',
importLoaders: 1
}
},
'postcss-loader',
'less-loader'
]
},
{
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
use: [{
loader: 'url-loader',
options: {
limit: 2048,
name: './img/[name].[hash:7].[ext]'
}
}]
}
]
}
};