-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
165 lines (140 loc) · 4.5 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// This webpack config is used to transpile src to dist, compile externals,
// compile executables, etc
const { EnvironmentPlugin, DefinePlugin, BannerPlugin } = require('webpack');
const ThreadsPlugin = require('threads-plugin');
const { verifyEnvironment } = require('./expect-env');
const nodeExternals = require('webpack-node-externals');
const debug = require('debug')(`${require('./package.json').name}:webpack-config`);
let env = {};
try {
require('fs').accessSync('.env');
env = require('dotenv').config().parsed;
debug('new env vars: %O', env);
} catch (e) {
debug(`env support disabled; reason: ${e}`);
}
verifyEnvironment();
const envPlugins = [
// ? Load our .env results as the defaults (overridden by process.env)
new EnvironmentPlugin({ ...env, ...process.env }),
// ? Create shim process.env for undefined vars (per my tastes!)
new DefinePlugin({ 'process.env': '{}' })
];
const externals = [
nodeExternals(),
({ request }, cb) =>
// ? Externalize all .json imports (required as commonjs modules)
/\.json$/.test(request) ? cb(null, `commonjs ${request}`) : cb()
];
/* const libConfig = {
name: 'lib',
mode: 'production',
target: 'node',
node: false,
entry: `${__dirname}/src/index.ts`,
output: {
filename: 'index.js',
path: `${__dirname}/dist`,
// ! ▼ Only required for libraries
// ! ▼ Note: ESM outputs are handled by Babel ONLY!
libraryTarget: 'commonjs2'
},
externals,
externalsPresets: { node: true },
stats: {
orphanModules: true,
providedExports: true,
usedExports: true,
errorDetails: true
},
resolve: { extensions: ['.ts', '.wasm', '.mjs', '.cjs', '.js', '.json'] },
module: {
rules: [{ test: /\.(ts|js)x?$/, loader: 'babel-loader', exclude: /node_modules/ }]
},
optimization: { usedExports: true },
ignoreWarnings: [/critical dependency:/i, /Conflicting values for 'process.env.NODE_ENV'/],
plugins: [...envPlugins]
}; */
const externalsConfig = {
name: 'externals',
mode: 'production',
target: 'node',
node: false,
entry: {
'ban-hammer': `${__dirname}/external-scripts/ban-hammer.ts`,
'prune-data': `${__dirname}/external-scripts/prune-data.ts`,
'generate-activity': `${__dirname}/external-scripts/generate-activity.ts`,
'simulate-activity': `${__dirname}/external-scripts/simulate-activity.ts`
},
output: {
filename: '[name].js',
path: `${__dirname}/external-scripts/bin`
},
externals,
externalsPresets: { node: true },
stats: {
orphanModules: true,
providedExports: true,
usedExports: true,
errorDetails: true
},
resolve: {
extensions: ['.ts', '.wasm', '.mjs', '.cjs', '.js', '.json'],
// ! If changed, also update these aliases in tsconfig.json,
// ! jest.config.js, next.config.ts, and .eslintrc.js
alias: {
universe: `${__dirname}/src/`,
multiverse: `${__dirname}/lib/`,
testverse: `${__dirname}/test/`,
externals: `${__dirname}/external-scripts/`,
types: `${__dirname}/types/`
}
},
module: {
rules: [{ test: /\.(ts|js)x?$/, loader: 'babel-loader', exclude: /node_modules/ }]
},
optimization: { usedExports: true },
ignoreWarnings: [
/critical dependency:/i,
/Conflicting values for 'process.env.NODE_ENV'/
],
plugins: [
...envPlugins,
// * ▼ For non-bundled externals, make entry file executable w/ shebang
new BannerPlugin({ banner: '#!/usr/bin/env node', raw: true, entryOnly: true }),
// * ▼ For threads.js support @ https://threads.js.org/getting-started
new ThreadsPlugin()
]
};
/*const cliConfig = {
name: 'cli',
mode: 'production',
target: 'node',
node: false,
entry: `${__dirname}/src/cli.ts`,
output: {
filename: 'cli.js',
path: `${__dirname}/dist`
},
externals,
externalsPresets: { node: true },
stats: {
orphanModules: true,
providedExports: true,
usedExports: true,
errorDetails: true
},
resolve: { extensions: ['.ts', '.wasm', '.mjs', '.cjs', '.js', '.json'] },
module: {
rules: [{ test: /\.(ts|js)x?$/, loader: 'babel-loader', exclude: /node_modules/ }]
},
optimization: { usedExports: true },
ignoreWarnings: [/critical dependency:/i, /Conflicting values for 'process.env.NODE_ENV'/],
plugins: [
...envPlugins,
// * ▼ For bundled CLI applications, make entry file executable w/ shebang
new BannerPlugin({ banner: '#!/usr/bin/env node', raw: true, entryOnly: true })
]
};*/
module.exports = [/*libConfig,*/ externalsConfig /*, cliConfig*/];
debug('exports: %O', module.exports);