Skip to content

Commit 08f7f4f

Browse files
committed
feat: update Webpack build to minify SVG icons through SVGO — used for server-side pre-rendering SVGs
1 parent faaa75b commit 08f7f4f

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

packages/build-tools/create-webpack-config.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const WriteFilePlugin = require('write-file-webpack-plugin');
1515
const npmSass = require('npm-sass');
1616
const merge = require('webpack-merge');
1717
const SassDocPlugin = require('@bolt/sassdoc-webpack-plugin');
18+
const svgoConfig = require('./svgo-config');
1819
const { getConfig } = require('@bolt/build-utils/config-store');
1920
const { boltWebpackProgress } = require('@bolt/build-utils/webpack-helpers');
2021
const {
@@ -269,6 +270,35 @@ async function createWebpackConfig(buildConfig) {
269270
},
270271
module: {
271272
rules: [
273+
// @todo: uncomment once future updates to handle SVG icon spritesheet in place
274+
// {
275+
// test: /\.svg$/,
276+
// include: path.dirname(require.resolve('@bolt/components-icons/package.json')),
277+
// use: [
278+
// 'svg-sprite-loader',
279+
// 'svgo-loader'
280+
// ]
281+
// },
282+
283+
// minify non spritesheet SVGs icons
284+
{
285+
test: /\.svg$/,
286+
// exclude: ,
287+
use: [
288+
{
289+
loader: 'file-loader',
290+
options: {
291+
name: path.join(path.dirname(require.resolve('@bolt/components-icons/package.json')), 'dist/[name].min.[ext]',)
292+
},
293+
},
294+
{
295+
loader: 'svgo-loader',
296+
options: {
297+
plugins: svgoConfig,
298+
},
299+
},
300+
],
301+
},
272302
{
273303
test: /\.(ts|tsx)$/,
274304
loader: 'ts-loader',
@@ -314,7 +344,7 @@ async function createWebpackConfig(buildConfig) {
314344
},
315345
},
316346
{
317-
test: /\.(cur|svg)$/,
347+
test: /\.(cur)$/,
318348
loader: 'file-loader',
319349
options: {
320350
name: '[name].[ext]',

packages/build-tools/package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
"bin": {
1616
"bolt": "index.js"
1717
},
18-
"browserslist": [
19-
"extends @bolt/browserslist-config"
20-
],
2118
"scripts": {
2219
"test": "FORCE_COLOR=1 npx lerna exec --scope @bolt/build-tools--test* --concurrency 1 -- npm run test"
2320
},
21+
"browserslist": [
22+
"extends @bolt/browserslist-config"
23+
],
2424
"dependencies": {
2525
"@babel/core": "^7.4.5",
2626
"@bolt/api": "^2.6.0",
@@ -56,7 +56,7 @@
5656
"eslint": "^5.16.0",
5757
"eslint-loader": "^2.1.2",
5858
"express": "^4.17.1",
59-
"file-loader": "^3.0.1",
59+
"file-loader": "^4.2.0",
6060
"front-matter": "^3.0.2",
6161
"fs-extra": "^8.0.1",
6262
"globby": "^9.2.0",
@@ -86,7 +86,9 @@
8686
"sharp": "^0.22.1",
8787
"string-replace-loader": "^2.1.1",
8888
"style-loader": "^0.23.1",
89-
"svgo": "^1.2.2",
89+
"svg-sprite-loader": "^4.1.6",
90+
"svgo": "^1.3.0",
91+
"svgo-loader": "^2.2.1",
9092
"ts-loader": "^6.0.2",
9193
"typescript": "^3.5.1",
9294
"uglifyjs-webpack-plugin": "^2.1.3",
@@ -114,4 +116,4 @@
114116
}
115117
],
116118
"schema": "utils/config.schema.yml"
117-
}
119+
}

0 commit comments

Comments
 (0)