Skip to content

Commit b108712

Browse files
authored
Merge pull request #1849 from SUI-Components/feat/experimental-spritemaps
feat(packages/sui-bundler): add experimental spritemaps
2 parents ad29323 + e25b96e commit b108712

File tree

7 files changed

+238
-7
lines changed

7 files changed

+238
-7
lines changed

package-lock.json

Lines changed: 170 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@
8282
"stylelint": {
8383
"extends": "./node_modules/@s-ui/lint/stylelint.config.js"
8484
}
85-
}
85+
}

packages/sui-bundler/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,51 @@ There are two ways to activate the statics cache option:
227227

228228
> Statics will be cached but no offline page will be activated
229229
230+
### SVG Spritemaps
231+
232+
Generate SVG spritemaps by using [svg-spritemap-webpack-plugin](https://github.com/cascornelissen/svg-spritemap-webpack-plugin) as follows:
233+
234+
```json
235+
{
236+
"sui-bundler": {
237+
"spritemaps": [
238+
{
239+
"path": ["icons/src/fotocasa/**/*.svg"],
240+
"options": {
241+
"output": {
242+
"filename": "fotocasa.[contenthash].svg",
243+
"chunk": {
244+
"name": "fotocasa"
245+
}
246+
},
247+
"sprite": {
248+
"generate": {
249+
"title": false
250+
}
251+
}
252+
}
253+
},
254+
{
255+
"path": ["icons/src/habitaclia/**/*.svg"],
256+
"options": {
257+
"output": {
258+
"filename": "habitaclia.[contenthash].svg",
259+
"chunk": {
260+
"name": "habitaclia"
261+
}
262+
},
263+
"sprite": {
264+
"generate": {
265+
"title": false
266+
}
267+
}
268+
}
269+
}
270+
]
271+
}
272+
}
273+
```
274+
230275
## Externals Manifest
231276

232277
If your are using an external CDN to store statics assets that are now managed by Webpack, like SVG or IMGs, you can create a manifest.json file in the root of your CDN (likehttps://spa-mock-statics.surge.sh/manifest.json`).

packages/sui-bundler/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,21 @@
4545
"html-webpack-plugin": "5.5.0",
4646
"https-browserify": "1.0.0",
4747
"mini-css-extract-plugin": "2.7.7",
48-
"postcss-loader": "7.3.4",
4948
"postcss": "8.4.31",
49+
"postcss-loader": "7.3.4",
5050
"process": "0.11.10",
5151
"react-refresh": "0.14.0",
5252
"sass": "1.54.5",
5353
"stream-http": "3.2.0",
5454
"strip-ansi": "6.0.1",
5555
"style-loader": "3.3.4",
56+
"svg-spritemap-webpack-plugin": "4.6.0",
5657
"swc-loader": "0.2.6",
5758
"tailwindcss": "3.4.14",
5859
"url": "0.11.0",
60+
"webpack": "5.82.1",
5961
"webpack-dev-server": "5.0.4",
6062
"webpack-manifest-plugin": "5.0.0",
61-
"webpack-node-externals": "3.0.0",
62-
"webpack": "5.82.1"
63+
"webpack-node-externals": "3.0.0"
6364
}
6465
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const SVGSpritemapPlugin = require('svg-spritemap-webpack-plugin')
2+
const {config} = require('./config.js')
3+
4+
const createSVGSpritemapPlugin = () => {
5+
const {spritemaps = []} = config
6+
7+
return spritemaps.map(({path, options = {}}) => {
8+
return new SVGSpritemapPlugin(path, options)
9+
})
10+
}
11+
12+
module.exports = createSVGSpritemapPlugin

packages/sui-bundler/webpack.config.client.dev.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const {withHydrationOverlayWebpack} = require('@builder.io/react-hydration-overl
1212
const {envVars, MAIN_ENTRY_POINT, config, cleanList, when, isTailwindEnabled} = require('./shared/index.js')
1313
const definePlugin = require('./shared/define.js')
1414
const manifestLoaderRules = require('./shared/module-rules-manifest-loader.js')
15+
const createSVGSpritemapPlugin = require('./shared/svg-spritemap')
1516
const {aliasFromConfig, defaultAlias} = require('./shared/resolve-alias.js')
1617
const {supportLegacyBrowsers, cacheDirectory} = require('./shared/config.js')
1718

@@ -88,7 +89,8 @@ const webpackConfig = {
8889
new ReactRefreshWebpackPlugin({overlay: false}),
8990
new HtmlWebpackInjectAttributesPlugin({
9091
crossorigin: 'anonymous'
91-
})
92+
}),
93+
...createSVGSpritemapPlugin()
9294
],
9395
resolveLoader,
9496
module: {

packages/sui-bundler/webpack.config.prod.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const {extractComments, sourceMap, supportLegacyBrowsers, cacheDirectory} = requ
1515
const {resolveLoader} = require('./shared/resolve-loader.js')
1616
const createCompilerRules = require('./shared/module-rules-compiler.js')
1717
const sassRules = require('./shared/module-rules-sass.js')
18+
const createSVGSpritemapPlugin = require('./shared/svg-spritemap')
1819
const definePlugin = require('./shared/define.js')
1920
const manifestLoaderRules = require('./shared/module-rules-manifest-loader.js')
2021
const minifyCss = require('./shared/minify-css.js')
@@ -100,7 +101,8 @@ const webpackConfig = {
100101
template: './index.html'
101102
}),
102103
new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/runtime/]),
103-
new WebpackManifestPlugin({fileName: 'asset-manifest.json'})
104+
new WebpackManifestPlugin({fileName: 'asset-manifest.json'}),
105+
...createSVGSpritemapPlugin()
104106
]),
105107
module: {
106108
rules: cleanList([

0 commit comments

Comments
 (0)