-
-
Notifications
You must be signed in to change notification settings - Fork 92
/
webpack.config.cjs
65 lines (59 loc) · 1.95 KB
/
webpack.config.cjs
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
const { makeConfig } = require('@anansi/webpack-config');
const fs = require('fs');
const { isAbsolute } = require('path');
const generateConfig = makeConfig({
basePath: 'src',
serverDir: 'dist',
babelLoader: {
rootMode: 'upward',
},
});
module.exports = (env, argv) => {
const config = generateConfig(env, argv);
if (!config.experiments) config.experiments = {};
config.experiments.backCompat = false;
config.experiments.outputModule = true;
config.output.chunkFormat = 'module';
// we want to inline the local packages, so no externals for us
config.externals = [];
config.entry = {
index: {
import: './src/index.ts',
library: {
type: 'module',
},
},
};
config.output.devtoolModuleFilenameTemplate = context => {
let path = context.absoluteResourcePath;
context.resourcePath;
// For regular files, this statement is true.
if (isAbsolute(path)) {
if (path.includes('/examples')) {
if (fs.existsSync(path)) return path;
for (const f of [
path.replace('examples/src', 'packages/normalizr/src'),
path.replace('examples/src', 'packages/endpoint/src'),
path.replace('examples/src', 'packages/core/src'),
]) {
if (fs.existsSync(f)) return f;
}
console.log('could not find file to map: ', path);
}
for (const f of [
path.replace('data-client/src', 'data-client/packages/normalizr/src'),
path.replace('data-client/src', 'data-client/packages/endpoint/src'),
path.replace('data-client/src', 'data-client/packages/core/src'),
path.replace('src/state', 'data-client/packages/core/src/state'),
]) {
if (fs.existsSync(f)) return f;
}
console.log('could not find file to map: ', path);
return path;
} else {
// Mimic Webpack's default behavior:
return `webpack://${context.namespace}/${context.resourcePath}`;
}
};
return config;
};