-
Notifications
You must be signed in to change notification settings - Fork 385
/
Copy pathcommonWebpackConfig.js
35 lines (27 loc) · 1.2 KB
/
commonWebpackConfig.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
// The source code including full typescript support is available at:
// https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/blob/master/config/webpack/commonWebpackConfig.js
// Common configuration applying to client and server configuration
const { generateWebpackConfig, merge } = require('shakapacker');
const baseClientWebpackConfig = generateWebpackConfig();
const commonOptions = {
resolve: {
extensions: ['.css', '.ts', '.tsx'],
},
};
// add sass resource loader
const sassLoaderConfig = {
loader: 'sass-resources-loader',
options: {
resources: './client/app/assets/styles/app-variables.scss',
},
};
const ignoreWarningsConfig = {
ignoreWarnings: [/Module not found: Error: Can't resolve 'react-dom\/client'/],
};
const scssConfigIndex = baseClientWebpackConfig.module.rules.findIndex((config) =>
'.scss'.match(config.test),
);
baseClientWebpackConfig.module.rules[scssConfigIndex].use.push(sassLoaderConfig);
// Copy the object using merge b/c the baseClientWebpackConfig and commonOptions are mutable globals
const commonWebpackConfig = () => merge({}, baseClientWebpackConfig, commonOptions, ignoreWarningsConfig);
module.exports = commonWebpackConfig;