-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
96 lines (94 loc) · 2.83 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
var path = require('path');
var webpack = require('webpack');
// 编译后自动打开浏览器
var OpenBrowserPlugin = require('open-browser-webpack-plugin');
// 产出html模板
var HtmlWebpackPlugin = require("html-webpack-plugin");
// 单独样式文件
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var node_modules = path.resolve(__dirname, 'node_modules');
/**
* 标识开发环境和生产环境
* @type {webpack.DefinePlugin}
*/
var definePlugin = new webpack.DefinePlugin({
__DEV__: JSON.stringify(JSON.parse(process.env.BUILD_DEV || 'true')),
__PRERELEASE__: JSON.stringify(JSON.parse(process.env.BUILD_PRERELEASE || 'false'))
});
module.exports = {
devServer: {
historyApiFallback: true,
hot: true,
inline: true,
contentBase: './build',
port: 8080,
stats: { colors: true }
},
entry: {
index: [
'webpack/hot/dev-server',
'webpack-dev-server/client?http://localhost:8080',
path.resolve(__dirname, 'app/index.js')
],
vendor: ['react', 'react-dom']
},
output: {
path: path.resolve(__dirname, 'build'),
filename: "[name].js",
publicPath: '/'
},
resolve: {
extension: ['', '.jsx', '.js', '.json'],
// 提高webpack搜索的速度
alias: { }
},
devtool: 'source-map',
'display-error-details': true,
// 使用externals可以将react分离,然后用<script>单独将react引入
externals: [],
module: {
// 使用module.noParse针对单独的react.min.js这类没有依赖的模块,速度会更快
noParse: [
path.resolve(node_modules, 'react/dist/react.min.js'),
path.resolve(node_modules, 'react-dom/dist/react-dom.min.js')
],
loaders: [
{
test: /\.js[x]?$/,
loaders: ['react-hot', 'babel'],
exclude: path.resolve(__dirname, 'node_modules')
},
{
test: /\.css/,
loader: ExtractTextPlugin.extract("style-loader", "css-loader")
},
{
test: /\.less/,
loader: ExtractTextPlugin.extract("style-loader", "css-loader!less-loader")
},
{
test: /\.(png|jpg)$/,
loader: 'url?limit=8192'
},
{
test: /\.(woff|woff2|ttf|svg|eot)(\?v=\d+\.\d+\.\d+)?$/,
loader: "url?limit=10000"
}
]
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
definePlugin,
new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.js'),
new HtmlWebpackPlugin({
title: 'your app title',
template: './app/index.html',
}),
new OpenBrowserPlugin({ url: 'http://localhost:8080' }),
new ExtractTextPlugin("main.css", {
allChunks: true,
disable: false
}),
]
};