-
Notifications
You must be signed in to change notification settings - Fork 56
/
razzle.config.js
67 lines (62 loc) · 2.17 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
"use strict";
const LoadableWebpackPlugin = require("@loadable/webpack-plugin");
const { loadableTransformer } = require("loadable-ts-transformer");
const path = require("path");
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
module.exports = {
plugins: ["typescript", "scss"],
resolve: {
alias: {
styles: path.join(__dirname, "src/style/")
}
},
options: {
buildType: "iso"
},
modifyWebpackConfig({
env: {
target, // the target 'node' or 'web'
dev // is this a development build? true or false
},
webpackConfig, // the created webpack config
webpackObject, // the imported webpack node module
options: {
pluginOptions, // the options passed to the plugin ({ name:'pluginname', options: { key: 'value'}})
razzleOptions, // the modified options passed to Razzle in the `options` key in `razzle.config.js` (options: { key: 'value'})
webpackOptions // the modified options that was used to configure webpack/ webpack loaders and plugins
},
paths // the modified paths that will be used by Razzle.
}) {
// Do some stuff to webpackConfig
if (target === "web") {
const filename = path.resolve(__dirname, "build");
// saving stats file to build folder
// without this, stats files will go into
// build/public folder
webpackConfig.plugins.push(
new LoadableWebpackPlugin({
outputAsset: true,
writeToDisk: { filename }
})
);
}
// Enable TS aliases
const tsAliases = {
"@ui": path.join(__dirname, "src/common/features/ui/")
};
webpackConfig.resolve.alias = {
...webpackConfig.resolve.alias,
...tsAliases
};
// Enable SSR lazy-loading
const tsLoader = webpackConfig.module.rules.find(
(rule) => !(rule.test instanceof Array) && rule.test && rule.test.test(".tsx")
);
tsLoader.use[0].options.getCustomTransformers = () => ({ before: [loadableTransformer] });
if (target === "web" && dev) {
webpackConfig.plugins.push(new BundleAnalyzerPlugin());
}
webpackConfig.devtool = dev ? "source-map" : false;
return webpackConfig;
}
};