-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.base.js
93 lines (91 loc) · 2.39 KB
/
webpack.config.base.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
/**
* Created by thh on 2018/3/28.
*/
const path = require('path');
const Webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const extractTextWebpackPlugin = require('extract-text-webpack-plugin');
const STATIC = 'static';
const extractStyle = new extractTextWebpackPlugin(`${STATIC}/css/style.[hash].css`);
module.exports = {
entry: {
main: path.resolve(__dirname, 'src/Index.jsx'),
vendor: ['babel-polyfill', 'react', 'react-dom', 'react-router'],
libs: ['jquery', 'nprogress']
},
output: {
publicPath: "/",
path: path.resolve(__dirname, 'build'),
filename: `${STATIC}/js/[name].[hash].js`
},
resolve: {
extensions: ['.js', '.jsx', '.css', '.scss']
},
module: {
rules: [
{
test: /\.jsx?$/,
use: ['babel-loader'],
exclude: path.join(__dirname, 'node_modules')
},
{
test: /\.(css|scss)$/,
use: extractStyle.extract(['css-loader', 'postcss-loader', 'sass-loader'])
},
{
test: /\.(png|jpg|svg|gif)$/,
include: path.join(__dirname, 'src'),
use: [
{
loader: 'url-loader',
options: {
limit: 10,
name: `${STATIC}/images/[name].[hash].[ext]`
}
}
]
},
{
test: /\.ico$/,
include: path.join(__dirname, 'src'),
use: [
{
loader: 'url-loader',
options: {
name: `${STATIC}/images/[name].[ext]`
}
}
]
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
include: path.join(__dirname, 'src/fonts'),
use: [
{
loader: 'url-loader',
options: {
limit: 10,
name: `${STATIC}/fonts/[hash].[ext]`
}
}
]
}
]
},
plugins: [
extractStyle,
new HtmlWebpackPlugin({
title: 'react16-staging',
filename: 'index.html',
template: path.resolve(__dirname, 'src/index.html'),
inject: true,
favicon: path.resolve(__dirname, 'src/images/favicon.ico')
}),
new CleanWebpackPlugin(['build']),
new Webpack.HashedModuleIdsPlugin(), // 公共模块不重复编译
new Webpack.LoaderOptionsPlugin({
minimize: true // 压缩loader读取的文件
})
]
};