forked from italia/design-comuni-plone-theme
-
Notifications
You must be signed in to change notification settings - Fork 1
/
razzle.extend.js
118 lines (107 loc) · 3.39 KB
/
razzle.extend.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
/**
* Replace with custom razzle config when needed.
* @module razzle.config
*/
const makeLoaderFinder = require('razzle-dev-utils/makeLoaderFinder');
const fileLoaderFinder = makeLoaderFinder('file-loader');
const urlLoaderFinder = makeLoaderFinder('url-loader');
const lessLoaderFinder = makeLoaderFinder('less-loader');
const babelLoaderFinder = makeLoaderFinder('babel-loader');
const plugins = (defaultPlugins) => {
const newPlugins = defaultPlugins.filter((plugin) => plugin !== 'scss');
newPlugins.push({
name: 'scss',
options: {
sass: {
dev: {
sassOptions: {
includePaths: ['node_modules'],
outputStyle: 'expanded',
sourceMap: true,
quiet: true,
quietDeps: true,
},
},
prod: {
sassOptions: {
includePaths: ['node_modules'],
outputStyle: 'expanded',
sourceMap: true,
quiet: true,
quietDeps: true,
},
},
},
},
});
return newPlugins;
};
const modify = (webpackConfig, { target, dev }, webpackObject) => {
const fileLoader = webpackConfig.module.rules.find(fileLoaderFinder);
fileLoader.exclude = [
/bootstrap-italia\/src\/svg\/.*\.svg$/,
...fileLoader.exclude,
];
const SVG_LOADER = {
test: /bootstrap-italia\/src\/svg\/.*\.svg$/,
use: [
{
loader: 'svg-loader',
},
{
loader: 'svgo-loader',
options: {
plugins: [
{ name: 'removeTitle', params: { removeTitle: true } },
{ name: 'convertPathData', params: { convertPathData: false } },
{
name: 'removeUselessStrokeAndFill',
params: { removeUselessStrokeAndFill: true },
},
{ name: 'removeViewBox', params: { removeViewBox: false } },
'removeDimensions',
],
},
},
],
};
webpackConfig.module.rules.push(SVG_LOADER);
const urlLoader = webpackConfig.module.rules.find(urlLoaderFinder);
urlLoader.exclude = [/\.(png|jpe?g)$/i, ...(urlLoader.exclude || [])];
// see: node_modules/razzle/config/createConfig.js
const IMG_LOADER = {
test: /\.(png|jpe?g)$/i,
use: [
{
loader: 'url-loader',
options: {
limit: 8192,
name: 'static/media/[name].[hash:8].[ext]',
emitFile: target === 'web',
},
},
{
// currently webpack 5 w/ asset is not supported by webpack-image-resize-loader
// see https://github.com/Calvin-LL/webpack-image-resize-loader/issues/491
// when Volto moves to webpack 5 w/ asset, this loader need to be reevaluated
// or substituted by responsive-loader
loader: 'webpack-image-resize-loader',
// see https://github.com/Calvin-LL/webpack-image-resize-loader for options.
// options: {
// width: 1000,
// },
},
],
};
webpackConfig.module.rules.push(IMG_LOADER);
const lessLoader = webpackConfig.module.rules.find(lessLoaderFinder);
lessLoader.include.push(/node_modules\/volto-data-grid-widget/);
// See https://github.com/italia/design-react-kit/pull/885#issuecomment-1420886066
const babelLoader = webpackConfig.module.rules.find(babelLoaderFinder);
babelLoader.include.push(/node_modules\/design-react-kit/);
return webpackConfig;
};
module.exports = {
modify,
plugins,
};