-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebpack.config.js
executable file
·99 lines (89 loc) · 2.54 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const path = require('path');
const webpack = require('webpack'); // eslint-disable-line import/no-extraneous-dependencies
const { merge } = require('webpack-merge'); // eslint-disable-line import/no-extraneous-dependencies
const parts = require('../../webpack.parts');
// For externals
const localPkg = require('./package.json');
const rootPkg = require('../../package.json');
// List of utility filenames
const utilities = require('./src');
const PATHS = {
app: path.join(__dirname, 'src'),
lib: path.join(__dirname, 'lib'),
public: '/',
};
const entry = {};
utilities.forEach((utilityPath) => {
if (utilityPath === 'constants/index'
|| utilityPath === 'config/index'
|| utilityPath === 'db/index'
|| utilityPath === 'http/index'
|| utilityPath === 'location/index'
|| utilityPath === 'metrics/index'
|| utilityPath === 'middleware/index') {
entry[utilityPath.split('/')[0]] = `${PATHS.app}/${utilityPath}.ts`;
} else {
const pathSplit = utilityPath.split('/');
const name = pathSplit[pathSplit.length - 1];
entry[name] = `${PATHS.app}/${utilityPath}.ts`;
}
});
const common = merge([
{
entry,
output: {
path: PATHS.lib,
filename: '[name].js',
publicPath: PATHS.public,
libraryTarget: 'umd',
library: 'Therr Public Library: Utilities',
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
},
target: 'node',
node: {
__dirname: false,
},
optimization: {
emitOnErrors: true,
moduleIds: 'deterministic',
},
externals: [
...Object.keys(localPkg.peerDependencies || {}),
...Object.keys(rootPkg.dependencies || {}),
],
},
parts.lintJavaScript({
paths: PATHS.app,
options: {
emitWarning: true,
},
}),
parts.clean(),
parts.processTypescript([PATHS.app], false),
parts.generateSourcemaps('source-map'),
parts.deDupe(),
]);
const buildDev = () => merge([
common,
{
mode: 'development',
},
parts.minifyJavaScript({ useSourceMap: true }),
]);
const buildProd = () => merge([
common,
{
mode: 'production',
},
// parts.analyzeBundle(),
parts.minifyJavaScript({ useSourceMap: false }),
]);
module.exports = (env) => {
process.env.BABEL_ENV = env;
if (env.production) {
return [buildProd()];
}
return [buildDev()];
};