-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.js
104 lines (100 loc) · 3.02 KB
/
webpack.common.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
var webpack = require('webpack');
var path = require('path');
var CleanWebpackPlugin = require("clean-webpack-plugin");
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var extractCSS = new ExtractTextPlugin('assets/css/[name]-one.min.css');
var extractSASS = new ExtractTextPlugin('assets/css/[name]-two.min.css');
var CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = {
entry: {
vendor: ['howler'],
main: path.resolve(__dirname, "src/assets/js/main.js")
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'assets/js/[name].min.js',
},
module: {
rules: [{
test: /(\.jsx|\.js)$/,
use: {
loader: 'babel-loader',
options: {
presets: ["es2015"]
}
},
exclude: /node_modules/,
include: '/src/'
}, {
test: /\.css$/,
include: /src/,
use: extractCSS.extract('css-loader')
}, {
test: /(\.scss|\.sass)$/,
use: extractSASS.extract(['css-loader', 'sass-loader'])
}, {
test: /\.html$/,
use: {
loader: 'html-loader',
options: {
minimize: true,
removeComments: false,
collapseWhitespace: false
}
}
}, {
test: /\.(gif|jpg|png|ico)\??.*$/,
use: {
loader: 'url-loader',
options: {
limit: 1024,
name: '[name].[ext]',
publicPath: '../../',
outputPath: 'assets/img/'
}
}
}, {
test: /\.(svg|woff|otf|ttf|eot)\??.*$/,
use: {
loader: 'url-loader',
options: {
limit: 1024,
name: '[name].[ext]',
publicPath: '../../',
outputPath: 'assets/css/'
}
}
}]
},
plugins: [
//清空dist
new CleanWebpackPlugin(["dist"], {
root: '',
verbose: true,
dry: false
}),
new CopyWebpackPlugin([{
from: path.resolve(__dirname, "src/assets/img"),
to: path.resolve(__dirname, "dist/assets/img")
}, {
from: path.resolve(__dirname, "src/assets/media"),
to: path.resolve(__dirname, "dist/assets/media")
}]),
extractCSS,
extractSASS,
new webpack.optimize.CommonsChunkPlugin({
names: "vendor",
minChunks: Infinity,
}),
new HtmlWebpackPlugin({
template: './src/index.html',
inject: 'body',
hash: true,
minify: {
removeComments: true,
collapseWhitespace: true
}
})
]
};