This repository has been archived by the owner on Nov 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrazzle.config.js
149 lines (135 loc) · 4.39 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/**
* Replace with custom razzle config when needed.
* @module razzle.config
*/
const jsConfig = require('./jsconfig').compilerOptions;
const path = require('path');
const makeLoaderFinder = require('razzle-dev-utils/makeLoaderFinder');
const fileLoaderFinder = makeLoaderFinder('file-loader');
const urlLoaderFinder = makeLoaderFinder('url-loader');
const projectRootPath = path.resolve('.');
const pathsConfig = jsConfig.paths;
let voltoPath = path.resolve('./node_modules/@plone/volto');
Object.keys(pathsConfig).forEach((pkg) => {
if (pkg === '@plone/volto') {
voltoPath = path.resolve(`./${jsConfig.baseUrl}/${pathsConfig[pkg][0]}`);
}
});
const volto_config = require(`${voltoPath}/razzle.config`);
module.exports = Object.assign({}, volto_config, {
modifyWebpackConfig: ({
env: { target, dev },
webpackConfig,
webpackObject,
options,
}) => {
const base_config = volto_config.modifyWebpackConfig({
env: { target, dev },
webpackConfig,
webpackObject,
options,
});
const fileLoader = base_config.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: [
{ removeTitle: true },
{ convertPathData: false },
{ removeUselessStrokeAndFill: true },
{ removeViewBox: false },
],
},
},
],
};
base_config.module.rules.push(SVG_LOADER);
const urlLoader = base_config.module.rules.find(urlLoaderFinder);
urlLoader.exclude = [/\.(png|jpe?g|webp)$/i, ...(urlLoader.exclude || [])];
// see: node_modules/razzle/config/createConfig.js
const IMG_LOADER = {
test: /\.(png|jpe?g|webp)$/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,
// },
},
],
};
base_config.module.rules.push(IMG_LOADER);
// RegExp.prototype.toJSON = function() { return this.source; };
// console.log(JSON.stringify(base_config.module.rules, null, 2))
webpackConfig.resolve.alias = {
// TODO remove the next two when implemented in core
'@plone/volto/components/theme/Image/Image': path.resolve(
`${projectRootPath}/src/components/Image/Image.jsx`,
),
'@plone/volto/helpers/Image/Image': path.resolve(
`${projectRootPath}/src/components/Image/helpers.js`,
),
...webpackConfig.resolve.alias,
...base_config.resolve.alias,
'../../theme.config$': `${projectRootPath}/theme/theme.config`,
'@plone/volto': `${voltoPath}/src`,
// to be able to reference path uncustomized by webpack
'@plone/volto-original': `${voltoPath}/src`,
// be able to reference current package from customized package
'@italia': `${projectRootPath}/src`, // TODO deprecated: remove in version 8
'design-volto-theme': `${projectRootPath}/src`,
};
return base_config;
},
plugins: [
...(volto_config.plugins || {}),
{
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,
},
},
},
},
},
],
});