-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
64 lines (61 loc) · 1.73 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
const webpack = require('webpack')
const config = require('./config.json')
const HtmlWebPackPlugin = require("html-webpack-plugin")
const TerserPlugin = require('terser-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin')
module.exports = env => {
const base_url = env.prod ? '/couchdb-react-boilerplate/' : '/'
return {
entry: './src/index.jsx',
devServer: { historyApiFallback: true },
mode: env.prod ? 'production' : 'development',
module: {
rules: [
{
enforce: "pre",
test: [/\.js$/, /\.jsx$/],
exclude: /node_modules/,
loader: "eslint-loader"
},
{
test: [/\.js$/, /\.jsx$/],
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
"presets": [
"@babel/react",
[
"@babel/preset-env",
{
targets: "> 0.25%, not dead",
useBuiltIns: "usage",
}
]
]
}
}
}
]
},
optimization: env.prod && {
minimizer: [new TerserPlugin()]
},
plugins: [
new HtmlWebPackPlugin({
template: './src/index.html',
base: base_url
}),
new CopyPlugin([
{ from: 'assets/', to: 'assets/' },
]),
new webpack.DefinePlugin({
WP_CONF_BASE_URL: JSON.stringify(base_url),
WP_CONF_REMOTE_DB_URL: JSON.stringify(
env.prod ? config.remote_db_url_prod : config.remote_db_url_dev),
WP_CONF_REMOTE_DB_NAME: JSON.stringify(
env.prod ? config.remote_db_name_prod : config.remote_db_name_dev)
})
]
}
}