This repository has been archived by the owner on May 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
94 lines (82 loc) · 2.8 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
import webpack from 'webpack'
import path from 'path'
import ExtractTextPlugin from 'extract-text-webpack-plugin'
function getEntry(env) {
const entry = []
if (env === 'development') {
entry.push('webpack-hot-middleware/client')
}
entry.push('./src/index')
return entry
}
function getPlugins(env) {
const plugins = [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.DefinePlugin({'process.env.NODE_ENV': JSON.stringify(env), __DEV__: env === 'development'}) // Tells React to build in prod mode
]
switch (env) {
case 'production':
plugins.push(new ExtractTextPlugin('styles.css', { allChunks: true }))
plugins.push(new webpack.optimize.DedupePlugin())
plugins.push(new webpack.optimize.UglifyJsPlugin())
break
case 'development':
plugins.push(new webpack.HotModuleReplacementPlugin())
plugins.push(new webpack.NoErrorsPlugin())
break
}
return plugins
}
function getLoaders(env) {
const loaders = [{
test: /\.js$/,
include: path.join(__dirname, 'src'),
loaders: ['babel', 'eslint']
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
loaders: ['file']
}]
if (env === 'production' ) {
// generate separate physical stylesheet for production build using ExtractTextPlugin.
// This provides separate caching and avoids a flash of unstyled content on load.
loaders.push({
test: /(\.css|\.scss)$/,
loader: ExtractTextPlugin.extract('style', 'css?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!postcss-loader')
})
loaders.push({
test: /isIterable/,
loader: 'imports?Symbol=>false'
})
} else {
loaders.push({
test: /(\.css|\.scss)$/,
loader: 'style?sourceMap!css?modules&importLoaders=1&localIdentName=[path]___[name]__[local]___[hash:base64:5]!postcss-loader'
})
}
return loaders
}
function getConfig(env) {
return {
debug: true,
devtool: env === 'production' ? 'source-map' : 'cheap-module-eval-source-map', // more info:https://webpack.github.io/docs/build-performance.html#sourcemaps and https://webpack.github.io/docs/configuration.html#devtool
noInfo: true, // set to false to see a list of every file being bundled.
entry: getEntry(env),
output: env === 'test' ? {
libraryTarget: 'commonjs2'
} : {
path: __dirname + '/dist', // Note: Physical files are only output by the production build task `npm run build`.
publicPath: '',
filename: 'bundle.js'
},
module: { loaders: getLoaders(env) },
plugins: getPlugins(env),
target: env === 'test' ? 'node' : 'web', // necessary per https://webpack.github.io/docs/testing.html#compile-and-test
postcss: [
require('autoprefixer'),
require('postcss-calc'),
require('postcss-nested')
]
}
}
export default getConfig