-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.config.js
108 lines (87 loc) · 1.92 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
const path = require('path');
const webpack = require('webpack');
const HTMLWebpackPlugin = require('html-webpack-plugin');
const nodeEnv = process.env.NODE_ENV || 'development';
const isProd = nodeEnv === 'production';
const devtool = isProd ? 'hidden-source-map' : 'source-map';
const mode = isProd ? 'production' : 'development';
const performance = isProd ? {} : {
hints: false
};
const entry = isProd ? './src/dom-to-react/index.js' : './src/main.js';
const output = {
path: path.join(__dirname, 'dist'),
filename: 'dom-to-react.js',
};
if (isProd) {
output.libraryTarget = 'umd';
output.library = 'dom-to-react';
}
const externals = isProd ? {
react: {
root: 'React',
commonjs2: 'react',
commonjs: 'react',
amd: 'react',
},
} : {};
const rules = [];
const babelLoader = {
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: 'babel-loader',
};
rules.push(babelLoader);
if (!isProd) {
const jsonLoader = {
test: /\.json$/,
use: 'json-loader',
};
rules.push(jsonLoader);
}
const resolve = {
extensions: ['.js', '.jsx'],
modules: [
path.resolve(__dirname, 'src'),
'node_modules',
],
};
const plugins = [];
if (!isProd) {
const htmlWebpackPlugin = new HTMLWebpackPlugin({
title: 'dom-to-react Demo',
template: 'src/assets/index.ejs',
});
plugins.push(htmlWebpackPlugin);
}
const definePlugin = new webpack.DefinePlugin({
NO_WRITE_FS: true,
'process.env': {
'NODE_ENV': JSON.stringify(nodeEnv),
},
});
plugins.push(definePlugin);
if (!isProd) {
const namedModulesPlugin = new webpack.NamedModulesPlugin();
plugins.push(namedModulesPlugin);
const NoEmitOnErrorsPlugin = new webpack.NoEmitOnErrorsPlugin();
plugins.push(NoEmitOnErrorsPlugin);
}
const devServer = {
inline: true,
host: '0.0.0.0',
};
module.exports = {
devtool,
mode,
performance,
entry,
output,
externals,
module: {
rules,
},
resolve,
plugins,
devServer,
};