This repository was archived by the owner on Dec 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.config.js
66 lines (59 loc) · 1.65 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
'use strict'
const path = require('path')
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
const OnBuildPlugin = require('on-build-webpack')
const webpackConfig = require('hjs-webpack')
const _ = require('lodash')
const cpr = require('cpr')
const renderHTML = require('./webpack/html')
const addStyleLoaders = require('./webpack/styles')
const SRC = path.resolve(__dirname, 'src')
const nodeEnv = process.env.NODE_ENV || 'development'
const configEnv = process.env.CONFIG_ENV || 'development'
const isDev = nodeEnv === 'development'
const config = addStyleLoaders(
webpackConfig({
isDev,
in: `${SRC}/main.js`,
out: 'build',
port: 3031,
urlLoaderLimit: 1,
clearBeforeBuild: true,
output: { hash: true },
hostname: 'localhost',
devServer: { contentBase: 'public', noInfo: true },
replace: {
config: `src/config/${configEnv}.js`,
},
define: {
'process.env.API_URL': JSON.stringify(process.env.API_URL),
},
html: (context) => ({ 'index.html': renderHTML(context) }),
}),
{ src: SRC, isDev }
)
// Allow for src/lib files to be required without relative paths
config.resolve.alias = {
lib: path.resolve(__dirname, 'src', 'lib'),
}
if (process.env.WEBPACK_ANALYZE) {
config.plugins.push(new BundleAnalyzerPlugin())
}
if (configEnv === 'static') {
config.plugins.push(
new OnBuildPlugin(
_.once(() =>
cpr(
path.resolve(__dirname, '..', 'api', '.export'),
path.resolve(__dirname, 'build', 'json'),
{
deleteFirst: false,
overwrite: false,
},
_.noop
)
)
)
)
}
module.exports = config