UNPKG

1.97 kBPlain TextView Raw
1import * as path from 'path'
2import Berun from '@berun/berun'
3
4/**
5 * Add core webpack configuration including
6 * main entry sources, output paths,
7 * resolution strategy, and miscellaneous variables such as
8 * mode, bail, devtool module filename template, empty node proxies,
9 * performance hints, and module strict export presence
10 */
11export default (berun: Berun, _) => {
12 const ISPRODUCTION = process.env.NODE_ENV === 'production'
13 const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false'
14
15 berun.webpack
16 .entry('main')
17 .when(!ISPRODUCTION, entry =>
18 entry.add(require.resolve('react-dev-utils/webpackHotDevClient'))
19 )
20 .add(berun.options.paths.appIndexJs)
21 .end()
22
23 berun.webpack.output
24 .when(
25 ISPRODUCTION,
26 o => o.path(berun.options.paths.appBuild),
27 o => o.pathinfo(true)
28 )
29 .filename(
30 ISPRODUCTION ? 'static/js/[name].[chunkhash:8].js' : 'static/js/[name].js'
31 )
32 .chunkFilename(
33 ISPRODUCTION
34 ? 'static/js/[name].[chunkhash:8].chunk.js'
35 : 'static/js/[name].chunk.js'
36 )
37 .publicPath(berun.options.paths.publicPath)
38 .devtoolModuleFilenameTemplate(
39 ISPRODUCTION
40 ? info =>
41 path
42 .relative(berun.options.paths.appSrc, info.absoluteResourcePath)
43 .replace(/\\/g, '/')
44 : info => path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')
45 )
46
47 berun.webpack
48 .mode(ISPRODUCTION ? 'production' : 'development')
49 .bail(!!ISPRODUCTION)
50 .devtool(
51 // eslint-disable-next-line no-nested-ternary
52 ISPRODUCTION
53 ? shouldUseSourceMap
54 ? 'source-map'
55 : false
56 : 'cheap-module-source-map'
57 )
58 .node.set('dgram', 'empty')
59 .set('fs', 'empty')
60 .set('net', 'empty')
61 .set('tls', 'empty')
62 .set('childProcess', 'empty')
63 .end()
64 .performance.hints(false)
65 .end()
66 .module.set('strictExportPresence', true)
67 .end()
68}