-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
85 lines (83 loc) · 2.11 KB
/
webpack.config.js
File metadata and controls
85 lines (83 loc) · 2.11 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
74
75
76
77
78
79
80
81
82
83
84
85
var webpack = require('webpack');
var path = require('path');
var extractTextPlugin = require("extract-text-webpack-plugin");
var htmlWebpackPlugin = require('html-webpack-plugin');
var openBrowserPlugin = require('open-browser-webpack-plugin');
// 定义路径
const PATHS = {
src: path.resolve(__dirname, 'src'),
dist: path.resolve(__dirname),
node_modules: path.resolve(__dirname, 'node_modules')
};
module.exports = {
entry: {
app: './src/js/app.js',
},
output: {
path: PATHS.dist,
filename: 'js/[name].bundle.js'
},
module: {
rules: [
{
test: /\.less$/,
use: extractTextPlugin.extract({
fallback: "style-loader",
use: ['css-loader?importLoaders=1&minimize=1','postcss-loader','less-loader'],
publicPath: PATHS.dist
}),
exclude: path.resolve(__dirname, 'node_modules'),
},
{
test: /\.(png|jpg|svg|gif)$/,
use: [ 'url-loader?limit=128&name=images/[hash:8].[name].[ext]' ]
},
{
test: /\.html$/,
use: [ 'html-loader' ],
},
{
test: /\.js$/,
use: {
loader:'babel-loader',
options: {
presets: ['babel-preset-es2015']
}
},
exclude: PATHS.node_modules,
include: PATHS.src
},
]
},
plugins:[
// 公有模块抽离
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: Infinity
}),
// css 文件导出
new extractTextPlugin("css/style.css"),
// 代码混淆
new webpack.optimize.UglifyJsPlugin({
output: { comments: false },
compress: { warnings: false }
}),
// html 文件导出
new htmlWebpackPlugin({
template: './src/index.html',
filename: './index.html',
inject: 'body',
favicon: './src/images/favicon.ico',
minify: {
collapseBooleanAttributes: true,
collapseWhitespace: true,
collapseInlineTagWhitespace: true,
removeComments: true,
}
}),
// 打开浏览器
new openBrowserPlugin({
url: 'http://localhost:8080'
})
],
};