This repository has been archived by the owner on Jun 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
128 lines (124 loc) · 3.1 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
var isProd = (process.env.NODE_ENV === 'production');
var path = require('path');
var webpack = require('webpack');
var autoprefixer = require('autoprefixer');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var cssFilename = 'css/main.min.css';
function resolveApp(relativePath) {
return path.resolve(__dirname, relativePath);
}
var paths = {
appIndexJs: resolveApp('src/js/index.js'),
appSrc: resolveApp('src/js'),
appContext: resolveApp('src'),
appBuild: resolveApp('build'),
}
module.exports = {
context: __dirname + "/src",
devtool: isProd ? 'source-map' : 'eval',
entry: [
'webpack-dev-server/client?http://localhost:8080/',
'webpack/hot/only-dev-server',
paths.appIndexJs
],
module: {
loaders: [{
exclude: [
/\.html$/,
/\.(js|jsx)$/,
/\.css$/,
/\.json$/,
/\.svg$/,
/\.sass$/,
/\.scss$/,
/node_modules/
],
loader: 'url',
query: {
limit: 10000,
name: 'build/media/[name].[ext]'
}
}, {
test: /\.js$/,
exclude: /node_modules/,
loaders: ['react-hot'],
include: paths.appContext
}, {
test: /\.js?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
query: {
presets: ['react', 'es2015', 'stage-0'],
plugins: ['react-html-attrs', 'transform-class-properties',
'transform-decorators-legacy'
]
},
include: paths.appContext
}, {
test: /\.scss$/,
loader: isProd ? ExtractTextPlugin.extract('style',
'css?importLoaders=1!sass!postcss') : "style!css!sass!postcss"
}]
},
output: {
path: paths.appBuild,
filename: "js/build.min.js"
},
// We use PostCSS for autoprefixing only.
postcss: function() {
return [
autoprefixer({
browsers: [
'>1%',
'last 4 versions',
'Firefox ESR',
'not ie < 9', // React doesn't support IE8 anyway
]
}),
];
},
resolve: {
extensions: ['', '.js']
},
plugins: !isProd ? [
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('development')
}
})
] : [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
}),
// This helps ensure the builds are consistent if source hasn't changed:
new webpack.optimize.OccurrenceOrderPlugin(),
// Try to dedupe duplicated modules, if any:
new webpack.optimize.DedupePlugin(),
// Minify the code.
new webpack.optimize.UglifyJsPlugin({
compress: {
screw_ie8: true, // React doesn't support IE8
warnings: false
},
mangle: {
screw_ie8: true
},
output: {
comments: false,
screw_ie8: true
}
}),
// Note: this won't work without ExtractTextPlugin.extract(..) in `loaders`.
new ExtractTextPlugin(cssFilename)
],
devServer: {
hot: true,
contentBase: './src',
// proxy: {
// "/api/*": "http://localhost:3000"
// }
}
};