-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.babel.js
114 lines (112 loc) · 3.34 KB
/
webpack.config.babel.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
import path from 'path';
import webpack from 'webpack';
import { settings } from '@easytool/proxy-config';
import define from '@easytool/define-config';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin';
import WebpackBundleAnalyzer from 'webpack-bundle-analyzer';
import { devEnvironments } from './package.json';
const { servers, proxies, globals } = devEnvironments;
const BUILD_PATH = 'build';
const ASSETS_PATH = 'assets';
export default {
mode: 'development',
devtool: 'cheap-module-eval-source-map',
devServer: {
host: '0.0.0.0',
port: servers.local,
inline: true,
compress: true, // 开起 gzip 压缩
disableHostCheck: true,
historyApiFallback: true, // browserHistory路由
contentBase: path.resolve(__dirname, BUILD_PATH),
proxy: {
...settings(proxies)
}
},
entry: {
main: ['./test/app.js']
},
output: {
publicPath: '/',
path: path.resolve(__dirname, BUILD_PATH),
filename: `${ASSETS_PATH}/js/[name].[chunkhash].js`
},
resolve: {
extensions: ['.js', '.jsx', '.css', '.less', '.scss']
},
module: {
rules: [{
/**
* eslint代码规范校验
*/
test: /\.(js|jsx)$/,
enforce: 'pre',
include: path.resolve(__dirname, 'src'),
use: [{
loader: 'eslint-loader',
options: {
fix: true,
configFile: '.eslintrc.json'
}
}]
}, {
/**
* JS加载器
*/
test: /\.(js|jsx)?$/,
exclude: path.resolve(__dirname, 'node_modules'),
use: [{
loader: 'babel-loader',
options: {
cacheDirectory: true
}
}]
}, {
/**
* CSS加载器
*/
test: /\.css$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: true,
localIdentName: '[local]__[hash:base64:5]'
}
}
]
}, {
/**
* 图片加载器
*/
test: /\.(png|jpg|jpeg|gif|svg)$/,
use: [{
loader: 'url-loader',
options: {
limit: 10,
name: `${ASSETS_PATH}/images/[name]_[hash].[ext]`
}
}]
}]
},
plugins: [
// 清除编译目录
new CleanWebpackPlugin(),
// index.html 模板插件
new HtmlWebpackPlugin({
filename: 'index.html',
template: './test/template.html'
}),
// 文件大小写检测
new CaseSensitivePathsPlugin(),
// check package size
// new WebpackBundleAnalyzer.BundleAnalyzerPlugin(),
// 配置全局变量
new webpack.DefinePlugin({
...define(globals)
})
]
};