-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
59 lines (52 loc) · 1.45 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
const path = require('path')
const { merge } = require('webpack-merge')
const parts = require('./webpack.parts')
const { mode, analyze } = require('webpack-nano/argv')
const common = merge([
{
experiments: {
asyncWebAssembly: true
},
resolve: {
alias: {
src: path.resolve(__dirname, 'src')
}
}
},
{ output: { path: path.resolve(process.cwd(), 'public/build') } },
parts.page({ title: 'Sh*t Kanye says' }),
parts.loadSvg(),
parts.svelte(mode),
parts.extractCSS({ loaders: [parts.postcss()] }),
parts.cleanDist(),
parts.useWebpackBar(),
parts.useDotenv()
])
const development = merge([
{ entry: ['./src/index.ts', 'webpack-plugin-serve/client'] },
{ target: 'web' },
parts.generateSourceMaps({ type: 'eval-source-map' }),
parts.esbuild(),
parts.devServer()
])
const production = merge(
[
{ entry: ['./src/index.ts'] },
parts.typescript(),
parts.optimize(),
analyze && parts.analyze()
].filter(Boolean)
)
const getConfig = mode => {
switch (mode) {
case 'production':
return merge(common, production, { mode })
case 'development':
return merge(common, development, { mode })
default:
throw new Error(`Unknown mode, ${mode}`)
}
}
const config = getConfig(mode)
console.log(JSON.stringify(config, null, ' '))
module.exports = config