This repository has been archived by the owner on Feb 26, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.babel.js
116 lines (110 loc) · 2.61 KB
/
webpack.config.babel.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
import {resolve} from 'path';
import {
DefinePlugin,
LoaderOptionsPlugin,
HotModuleReplacementPlugin,
NamedModulesPlugin,
NoEmitOnErrorsPlugin,
} from 'webpack';
import HTMLPlugin from 'html-webpack-plugin';
import CopyPlugin from 'copy-webpack-plugin';
import CleanPlugin from 'clean-webpack-plugin';
import BabiliPlugin from 'babili-webpack-plugin';
import ExtractTextPlugin, {extract} from 'extract-text-webpack-plugin';
const host = 'localhost';
const port = process.env.PORT || 3000;
const url = `http://${host}:${port}/`;
const src = 'src';
const dest = 'app';
const clean = [dest];
const copy = [
{
from: 'content',
},
];
const cssLoader = {
loader: 'css-loader',
options: {
sourceMap: true,
modules: true,
localIdentName: '[name]__[local]___[hash:base64:5]',
},
};
function config({dev} = {}) {
const env = dev ? 'development' : 'production';
return {
devtool: dev ? 'eval-source-map' : 'hidden-source-map',
entry: [
...(dev ? [
`webpack-dev-server/client?${url}`,
'webpack/hot/only-dev-server',
'react-hot-loader/patch',
] : []),
'babel-polyfill',
`./${src}/index.jsx`,
],
output: {
path: resolve(__dirname, dest),
filename: `bundle${dev ? '' : '.[chunkhash]'}.js`,
},
module: {
rules: [
{
test: /\.jsx?$/,
include: resolve(__dirname, src),
loader: 'babel-loader',
options: {
cacheDirectory: dev,
forceEnv: env,
},
},
{
test: /\.css$/,
include: resolve(__dirname, src),
use: dev ? [
'style-loader',
cssLoader,
] : extract({
fallback: 'style-loader',
use: cssLoader,
}),
},
],
},
plugins: [
new CleanPlugin(clean),
new CopyPlugin(copy),
new HTMLPlugin({
template: `${src}/template.ejs`,
inject: false,
}),
new DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(env),
}),
new LoaderOptionsPlugin({
minimize: !dev,
debug: dev,
options: {
context: __dirname,
},
}),
...(dev ? [
new HotModuleReplacementPlugin(),
new NamedModulesPlugin(),
new NoEmitOnErrorsPlugin(),
] : [
new ExtractTextPlugin({
filename: `style${dev ? '' : '.[contenthash]'}.css`,
allChunks: true,
}),
new BabiliPlugin(),
]),
],
resolve: {
extensions: ['.js', '.jsx', '.json'],
},
};
}
export {
config as default,
};