This repository has been archived by the owner on Jun 23, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 156
/
webpack.config.base.js
85 lines (69 loc) · 1.75 KB
/
webpack.config.base.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
/* eslint-disable */
const { resolve } = require('path');
const merge = require('webpack-merge');
const createStyledComponentsTransformer = require('typescript-plugin-styled-components').default;
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
/* eslint-enable */
const INCLUDE = resolve(__dirname, 'src');
const dev = process.env.ENV === 'dev';
const styledComponentsTransformer = createStyledComponentsTransformer({
minify: true,
displayName: dev,
});
function getExternals(externals) {
const res = {};
for (const e of externals) {
res[e] = `require('${e}')`;
}
return res;
}
const config = {
mode: dev ? 'development' : 'production',
devtool: dev ? 'eval-source-map' : 'none',
plugins: [],
output: {
path: resolve(__dirname, 'build'),
filename: '[name].bundle.js',
libraryTarget: 'var',
},
module: {
rules: [
{
test: /\.tsx|ts$/,
use: [
'cache-loader',
{
loader: 'ts-loader',
options: {
experimentalWatchApi: true,
transpileOnly: true,
getCustomTransformers: () => ({
before: [styledComponentsTransformer],
}),
},
},
],
include: INCLUDE,
},
],
},
node: {
__dirname: false,
__filename: false,
},
resolve: {
modules: ['node_modules'],
extensions: ['.js', '.jsx', '.tsx', '.ts', '.json'],
alias: {
'~': INCLUDE,
},
},
externals: getExternals(['iohook', 'node-window-manager', 'extract-file-icon']),
};
if (dev) {
config.plugins.push(new ForkTsCheckerWebpackPlugin());
}
function getConfig(...cfg) {
return merge(config, ...cfg);
}
module.exports = { getConfig, dev };