-
Notifications
You must be signed in to change notification settings - Fork 64
/
webpack.config.js
121 lines (112 loc) · 2.86 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
var webpack = require('webpack');
var HtmlWebPackPlugin = require('html-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var path = require('path');
var config = {
entry: {
index: './src/pages/route.js'
},
output: {
path: __dirname + '/assets',
filename: 'js/[name].js',
chunkFilename: 'js/[name].[chunkhash:8].js',
publicPath: '/react-redux-chat/'
},
plugins: [
// new ExtractTextPlugin('[name].css', {
// allChunks: true
// }),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendors'
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.NoErrorsPlugin(),
new ExtractTextPlugin('css/[name].[chunkhash:8].css'),
],
resolve: {
extensions: ['', '.js', '.jsx', '.scss'],
alias: {
src : __dirname + '/src',
}
},
module: {
loaders: [
{
test: /\.scss$/,
loader: 'style-loader!css?-minimize!autoprefixer?{browsers:["last 2 version", "> 1%", "iOS 7"]}!sass?sourceMap'
},
// { test: /\.scss$/i, loader: ExtractTextPlugin.extract('style','css?sourceMap&modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!sass?sourceMap') },
{
test: /\.(woff|woff2|ttf|eot|svg)$/,
loader: 'file-loader?name=fonts/[name].[hash:8].[ext]'
},
{
test: /\.(png|jpg|jpeg|gif)$/,
loader: 'url-loader?limit=8192&name=images/[name].[hash:8].[ext]'
}
]
},
};
if (process.env.NODE_ENV === 'development') {
config.devtool = 'eval-source-map';
config.module.loaders.push({
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: 'babel',
query: {
presets: ['react', 'es2015', 'stage-0', 'react-hmre'],
plugins: ['add-module-exports',"transform-runtime"]
}
});
// webpack-dev-server配置
config.devServer= {
port:8085,
// host:"dev.honeybadger8.com",
historyApiFallback: true,
noInfo: false,
publicPath: config.output.publicPath,
stats: {
colors: true,
chunks: false
}
};
config.plugins.push(new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("development")
},
__DEBUG__: true
}));
config.plugins.push(new webpack.HotModuleReplacementPlugin());
}else{
config.module.loaders.push({
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: 'babel',
query: {
presets: ['react', 'es2015', 'stage-0'],
plugins: ['add-module-exports',"transform-runtime"]
}
});
config.plugins.push(new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production")
},
__DEBUG__: false
}));
config.plugins.push(new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
},
output: {
comments: false,
}
}));
config.plugins.push(new HtmlWebPackPlugin({
filename: path.resolve(__dirname, 'assets/index.html'),
template: "index.html",
inject: false
}));
}
module.exports = config;