-
Notifications
You must be signed in to change notification settings - Fork 1
/
razzle.config.js
120 lines (116 loc) · 3.88 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
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
/* jshint -W097 */
/* jshint -W117 */
/* jshint esversion: 6 */
"use strict";
const path = require("path");
const webpack = require("webpack");
const Workbox = require("workbox-webpack-plugin");
module.exports = {
modifyOptions({
webpackObject, // the imported webpack node module
options: {
pluginOptions, // the options passed to the plugin ({ name:'pluginname', options: { key: 'value'}})
razzleOptions, // the default options/ options passed to Razzle in the `options` key in `razzle.config.js` (options: { key: 'value'})
},
}) {
// Do some stuff...
return razzleOptions;
},
modifyPaths({
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'})
},
paths, // the default paths that will be used by Razzle.
}) {
// Do some stuff...
return paths;
},
modifyWebpackOptions({
env: {
target, // the target 'node' or 'web'
dev, // is this a development build? true or false
},
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 default options that will be used to configure webpack/ webpack loaders and plugins
},
paths, // the modified paths that will be used by Razzle.
}) {
if (target === "web") {
// client only
}
if (target === "node") {
// server only
}
if (dev) {
// dev only
} else {
// prod only
}
// Do some stuff...
return webpackOptions;
},
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.
}) {
if (target === "web") {
// client only
if (process.env.MODE === "server") {
webpackConfig.entry.client = path.join(__dirname, '/src/server_client');
}
}
if (target === "node") {
// server only
webpackConfig.plugins.push(
new webpack.EnvironmentPlugin(['MODE', 'NODE_ENV'])
);
}
if (dev) {
// dev only
} else {
// prod only
}
// webpackConfig.plugins.push(
// new Workbox.InjectManifest({
// swSrc: "./src/service_worker.ts",
// swDest: "public/service_worker.js",
// modifyURLPrefix: {
// "/public": "",
// },
// exclude: [
// "server.js",
// "static_export.js",
// ],
// })
// );
// Do some stuff...
return webpackConfig;
},
modifyJestConfig({
jestConfig, // the created jest 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'})
},
paths, // the modified paths that will be used by Razzle.
}) {
// Do some stuff...
return jestConfig;
},
};