-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
99 lines (97 loc) · 2.35 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
var path = require('path')
var SpritesmithPlugin = require('webpack-spritesmith')
var ExtractTextPlugin = require("extract-text-webpack-plugin")
var webpack = require('webpack')
var HtmlPlugin = require('html-webpack-plugin');
var uglify = require('uglifyjs-webpack-plugin');
function resolve(dir) {
return path.join(__dirname, dir)
}
module.exports = {
devtool: 'cheap-module-source-map',
entry: resolve('/src/index.js'),
output: {
path: resolve('/public'),
filename: '[hash].bundle.js'
},
module: {
loaders: [
{
test: /.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
include: [resolve('src'), resolve('test')]
},
{
test: /\.(css|scss|sass)$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [{
loader: 'css-loader',
options: {
sourceMap: true
}
}, {
loader: 'postcss-loader',
options: {
sourceMap: true
}
}, {
loader: 'sass-loader',
options: {
sourceMap: true
}
}],
publicPath: '/'
})
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url-loader',
query: {
limit: 10000,
name: 'images/[hash].[name].[ext]'
}
}
]
},
plugins: [
new ExtractTextPlugin({
filename: "style/[name].css?[hash]-[chunkhash]-[contenthash]-[name]",
disable: false,
allChunks: true
}),
new webpack.LoaderOptionsPlugin({
minimize: true
}),
new SpritesmithPlugin({
// 目标小图标
src: {
cwd: resolve('/src/assets/images/icons'),
glob: '*.png'
},
// 输出雪碧图文件及样式文件
target: {
image: resolve('/public/images/sprites/sprite.png'),
css: resolve('/public/images/sprites/sprite.css')
},
// 样式文件中调用雪碧图地址写法
apiOptions: {
cssImageRef: './sprite.png'
},
spritesmithOptions: {
algorithm: 'top-down'
}
}),
new HtmlPlugin({
title: 'Gy-Cli',
filename: resolve('/public/index.html')
}),
new uglify()
],
devServer: {
contentBase: './public',
historyApiFallback: true,
inline: true
}
}