-
Notifications
You must be signed in to change notification settings - Fork 0
/
razzle.config.js
75 lines (67 loc) · 2.08 KB
/
razzle.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
const path = require('path');
const packageJson = require('./package.json');
const workspaces = packageJson.workspaces;
module.exports = {
options: {
enableTargetBabelrc: true, // enable to use .babelrc.node and .babelrc.web
verbose: true, // set to true to get more info/error output
},
modifyWebpackConfig({
env: {
target, // the target 'node' or 'web'
dev, // is this a development build? true or false
},
webpackConfig, // the created webpack config
paths, // the modified paths that will be used by Razzle.
}) {
const config = webpackConfig; // stay immutable here
const defaultResolvePath = path.resolve('./src');
const correctResolvePath = workspaces.map((dir) =>
path.resolve(`${dir}/src`)
);
config.module.rules = config.module.rules.map((rule) => {
if (
Array.isArray(rule.include) &&
rule.include.includes(defaultResolvePath)
) {
rule.include = [
...rule.include.filter((r) => r !== defaultResolvePath),
...correctResolvePath,
];
}
return rule;
});
config.resolve.alias = {
...config.resolve.alias,
'@global': path.resolve('./client/src/global'),
'@layouts': path.resolve('./client/src/layouts'),
};
config.resolve.fallback = {
fs: false,
path: require.resolve('path-browserify'),
};
if (target === 'node') {
// Replace default server entry of ./src/server.js with server entry
if (dev) {
config.entry.server = [
...config.entry.server.slice(0, -1),
path.resolve('./server/src/index.js'),
];
} else {
config.entry.server = path.resolve('./server/src/index.js');
}
}
if (target === 'web') {
// Replace default entry with client project's entry
if (dev) {
config.entry.client = [
...config.entry.client.slice(0, -1),
path.resolve('./client/src/index.js'),
];
} else {
config.entry.client = path.resolve('./client/src/index.js');
}
}
return config;
},
};