-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.base.config.js
77 lines (74 loc) · 2.62 KB
/
webpack.base.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
const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const webpack = require('webpack');
// 源代码的根目录
const BUILD_PATH = path.resolve('../hello/www');
const DEBUG = process.env.NODE_ENV !== 'production' ? true : false;
const svgDirs = [
require.resolve('antd-mobile').replace(/warn\.js$/, ''),
path.resolve(__dirname, 'src/asserts')
];
module.exports = {
// devtool: 'eval-source-map',
entry: {
index: './src/Root.js',
vendor: ["react", "react-dom", "react-router-dom", "redux", "react-redux"]
},
output: {
path: BUILD_PATH,
publicPath: '/',
filename: 'js/[name].[hash].js',
chunkFilename: 'js/[name].[hash].js'
},
plugins: [
// 每次打包前,先清空原来目录中的内容
new CleanWebpackPlugin([BUILD_PATH], { verbose: false }),
// 生成一个html文件,并用script标签引用所有的webpack包
new HtmlWebpackPlugin({
template: './src/index.html', // 根据指定的模板文件生成特定的html文件
inject: 'body', // script标签位于html文件的body底部
filename: 'index.html'
}),
new ExtractTextPlugin({filename: 'css/[name].css',
allChunks: true
})
],
resolve: {
modules: [path.resolve(__dirname, 'node_modules'), path.join(__dirname, 'src')],
extensions: ['.web.js', '.jsx', '.js', '.json'],
alias: {
'src': path.resolve(__dirname, './src'),
'asserts': path.resolve(__dirname, './src/asserts'),
'utils': path.resolve(__dirname, './src/utils'),
'styles': path.resolve(__dirname, './src/styles')
}
},
module: {
loaders: [{
test: /\.(js)$/, // 用正则来匹配文件路径,这段意思是匹配 js 或者 jsx
exclude: /node_modules/,
loader: ['babel-loader', 'eslint-loader'],
}, {
test: /\.(svg)$/i,
loader: 'svg-sprite-loader',
include: svgDirs
}, {
test: /\.json?$/,
loader: 'json-loader'
}, {
test: /\.scss$/, // 加上modules启用css modules
loader: DEBUG
? 'style-loader!css-loader?modules&localIdentName=[name]---[local]---[hash:base64:5]!sass-loader'
: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: 'css-loader?modules&localIdentName=[name]---[local]---[hash:base64:5]!sass-loader' })
}, {
test: /\.(css|less|sass)$/,
loader: 'style-loader!css-loader!less-loader'
}, {
test: /\.woff(2)?(\?[a-z0-9#=&.]+)?$/, loader: 'url?limit=10000&mimetype=application/font-woff'
}]
}
};