-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.config.babel.js
More file actions
90 lines (82 loc) · 2.13 KB
/
webpack.config.babel.js
File metadata and controls
90 lines (82 loc) · 2.13 KB
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
import HtmlWebpackPlugin from 'html-webpack-plugin'
import webpack from 'webpack'
import path from 'path'
import autoprefixer from 'autoprefixer'
import ExtractTextPlugin from 'extract-text-webpack-plugin'
const npmCommand = process.env.BABEL_ENV = process.env.npm_lifecycle_event
const isProduction = npmCommand === 'production'
const paths = {
app: path.join(__dirname, 'app'),
production: path.join(__dirname, 'production'),
development: path.join(__dirname, 'development'),
}
const htmlWebpackPluginConfig = {
filename: 'index.html',
template: path.join(paths.app, 'index.html'),
inject: 'body',
}
const baseConfig = {
entry: [
paths.app
],
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel'
},
{
test: /(\.scss|\.css)$/,
loader: ExtractTextPlugin.extract('style', 'css?sourceMap&modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!postcss!sass')
},
],
},
postcss: [autoprefixer],
sassLoader: {
data: '@import "theme/_config.scss";',
includePaths: [path.resolve(__dirname, './app')]
},
resolve: {
root: path.resolve('./app'),
extensions: ['', '.scss', '.css', '.js', '.json'],
},
}
const productionConfig = {
devtool: 'cheap-inline-source-map',
output: {
path: paths.production,
filename: 'index_bundle.js',
},
plugins: [
new ExtractTextPlugin('index_bundle.css', { allChunks: true }),
new HtmlWebpackPlugin(htmlWebpackPluginConfig),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production'),
},
}),
],
}
const developmentConfig = {
devtool: 'inline-source-map',
output: {
path: paths.development,
filename: 'index_bundle.js',
},
devSever: {
contentBase: paths.development,
hot: true,
inline: true,
progress: true,
},
plugins: [
new ExtractTextPlugin('index_bundle.css', { allChunks: true }),
new HtmlWebpackPlugin(htmlWebpackPluginConfig),
]
}
const finalConfig = {
...baseConfig,
...(isProduction ? productionConfig : developmentConfig)
}
export default finalConfig