-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
76 lines (74 loc) · 2.15 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
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const CommonsChunkPlugin = webpack.optimize.CommonsChunkPlugin;
module.exports = {
context: path.resolve(__dirname, 'client'),
entry: {
index: [path.resolve(__dirname, 'client/index.js')],
vendor: ['react', 'react-dom', 'prop-types'],
},
output: {
path: path.resolve(__dirname, 'public'),
filename: '[name].[chunkhash:8].bundle.js',
chunkFilename: '[name].[chunkhash:8].js',
},
resolve: {
modules: [path.resolve(__dirname, 'client'), 'node_modules'],
extensions: ['.js', '.jsx', '.json'],
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
},
{
test: /\.css$/,
// css-loader file-loader url-loader style-loader 4个一起安装
// use: ['style-loader', 'css-loader'], // 输出到脚本,脚本通过 style 标签输出到页面
use: ExtractTextPlugin.extract({
use: 'css-loader',
}),
},
{
test: /\.(jpe?g|png|gif)$/i,
loader: 'url-loader',
options: {
limit: 1000,
name: 'assets/imgs/[name].[hash:8].[ext]',
},
},
{
test: /\.(woff2?|eot|ttf|otf|svg)$/i,
loader: 'url-loader',
options: {
limit: 10000,
name: 'assets/fonts/[name].[hash:8].[ext]',
},
},
],
},
plugins: [
new CleanWebpackPlugin([ 'public/*' ], {
root: path.resolve(__dirname),
verbose: true,
dry: false,
exclude: [ '.gitkeep' ],
}),
new CommonsChunkPlugin({
names: ['vendor', 'manifest'],
filename: '[name].[chunkhash:8].js',
}),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'client/index.html'),
filename: 'index.html',
inject: 'body',
chunks: ['manifest', 'vendor', 'index'],
}),
new ExtractTextPlugin('[name].[chunkhash:8].css'),
],
};