-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.babel.js
65 lines (56 loc) · 1.69 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
/* eslint-disable import/no-extraneous-dependencies, no-console */
import { resolve } from 'path';
import { DefinePlugin, HotModuleReplacementPlugin, NamedModulesPlugin, NoErrorsPlugin } from 'webpack';
export const basePath = resolve(`${__dirname}/src`);
export const distributionPath = resolve(`${__dirname}/dist`);
const isDevEnvironment = environment => environment === 'dev';
export default function (options = {}) {
const environment = options.prod ? 'production' : 'dev';
console.log(`=> Building wordcloud for '${environment}' environment.`);
const environmentConfigurations = isDevEnvironment ? {
entry: [
'webpack/hot/poll?1000',
basePath,
],
devtool: 'cheap-module-eval-source-map',
} : {
entry: basePath,
};
const environmentOutput = isDevEnvironment ? {
hotUpdateChunkFilename: 'hot/[id].[hash].hot-update.js',
hotUpdateMainFilename: 'hot/[hash].hot-update.json',
} : {};
const environmentPlugins = isDevEnvironment ? [
new HotModuleReplacementPlugin(),
new NamedModulesPlugin(),
new NoErrorsPlugin(),
] : [];
const fileName = environment === 'dev' ? 'wordcloud.dev.js' : 'wordcloud.js';
return ({
...environmentConfigurations,
devServer: { inline: true },
target: 'node',
output: {
...environmentOutput,
path: distributionPath,
filename: fileName,
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /(node_modules)/,
loader: ['babel', 'eslint'],
},
],
},
plugins: [
...environmentPlugins,
new DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(environment),
},
}),
],
});
}