-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
146 lines (131 loc) · 4.24 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
var path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const NpmInstallPlugin = require('npm-install-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin')
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var cssExtractPlugin = new ExtractTextPlugin('css/style.css?[contenthash:16]');
const TARGET = process.env.npm_lifecycle_event;
const PATHS = {
src: path.join(__dirname, 'src'),
dist: path.join(__dirname, 'dist')
};
process.env.NODE_ENV = TARGET;
process.env.BABEL_ENV = TARGET;
const common = {
entry: [
PATHS.src + '/assets/libs/es5-shim.js',
PATHS.src + '/assets/libs/es5-sham.js',
PATHS.src + '/assets/libs/json3.js',
'./node_modules/console-polyfill/index.js',
PATHS.src
],
output: {
publicPath : '/',
path: PATHS.dist,
filename: 'bundle/bundle.js?[hash]'
},
externals: [{
}],
module: {
loaders: [
{ test: /\.html$/, loader: "html" },
{ test: /\.(css|scss)$/, exclude: /node_modules/, loader: ExtractTextPlugin.extract("style", "css!sass")},
{ test: /\.jsx?$/, exclude: /(node_modules|bower_components)/, loaders: ['babel?cacheDirectory']},
{ test: /\.woff(2)?(\?t=\d+)?$/, loader: "url-loader?name=font/[name].[ext]?[hash]&limit=10000&minetype=application/font-woff" },
{ test: /\.(ttf|eot|svg)(\?t=\d+)?$/, loader: "file-loader?name=font/[name].[ext]?[hash:16]" },
{ test: /\.jpg$/, loader: "file-loader?name=img/[name].[ext]?[hash:16]" },
{ test: /\.png$/, loader: 'url-loader?name=img/[name].[ext]?[hash:16]&limit=8192' }
],
postLoaders: [{
test: /\.jsx?$/,
loaders: ['es3ify-loader'],
}],
},
plugins: [
cssExtractPlugin,
new HtmlWebpackPlugin({
title: 'React',
template:PATHS.src+'/assets/index.html'
})],
resolve: {
// you can now require('file') instead of require('file.coffee')
root:[path.resolve(PATHS.src+'/assets')],
extensions: ['', '.jsx','.js', '.json','.scss','.css']
},
htmlLoader: {
ignoreCustomFragments: [/\{\{.*?}}/]
}
}
if(TARGET === 'dev' || !TARGET) {
module.exports = merge(common, {
devtool: 'inline-source-map',
devServer: {
contentBase: PATHS.dist,
// Enable history API fallback so HTML5 History API based
// routing works. This is a good default that will come
// in handy in more complicated setups.
historyApiFallback: false,
hot: true,
inline: true,
progress: true,
// Display only errors to reduce the amount of output.
stats: 'errors-only',
// Parse host and port from env so this is easy to customize.
//
// If you use Vagrant or Cloud9, set
// host: process.env.HOST || '0.0.0.0';
//
// 0.0.0.0 is available to all network devices unlike default
// localhost
host: '0.0.0.0',
port: process.env.PORT
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new NpmInstallPlugin({
save: true // --save
})
]
});
}
if(TARGET === 'dev-ie8' || !TARGET) {
module.exports = merge(common, {
devtool: 'inline-source-map',
devServer: {
contentBase: PATHS.dist,
// Enable history API fallback so HTML5 History API based
// routing works. This is a good default that will come
// in handy in more complicated setups.
historyApiFallback: false,
hot: false,
inline: false,
progress: true,
// Display only errors to reduce the amount of output.
stats: 'errors-only',
// Parse host and port from env so this is easy to customize.
//
// If you use Vagrant or Cloud9, set
// host: process.env.HOST || '0.0.0.0';
//
// 0.0.0.0 is available to all network devices unlike default
// localhost
host: '0.0.0.0',
port: process.env.PORT
},
plugins: [
new NpmInstallPlugin({
save: true // --save
})
]
});
}
if(TARGET === 'build' || TARGET === 'production') {
module.exports = merge(common, {
plugins:[
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"'+TARGET+'"'
})
]
})
}