Skip to content

Commit

Permalink
fix(react): load svg component in buildable library
Browse files Browse the repository at this point in the history
added svg and url loaders to rollup config of buildabel react library, like in webpack for react
app.

ISSUES CLOSED: #6761
  • Loading branch information
YehudaGold committed Sep 25, 2022
1 parent 90604d8 commit e24aa69
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -73,6 +73,7 @@
"@rollup/plugin-image": "^2.1.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.0.4",
"@rollup/plugin-url": "^7.0.0",
"@schematics/angular": "~14.2.0",
"@storybook/addon-essentials": "~6.5.9",
"@storybook/addon-knobs": "~6.3.0",
Expand All @@ -82,6 +83,7 @@
"@storybook/core-server": "~6.5.9",
"@storybook/manager-webpack5": "~6.5.9",
"@storybook/react": "~6.5.9",
"@svgr/rollup": "^6.1.2",
"@svgr/webpack": "^6.1.2",
"@swc-node/register": "^1.4.2",
"@swc/cli": "~0.1.55",
Expand Down
2 changes: 2 additions & 0 deletions packages/react/package.json
Expand Up @@ -43,6 +43,8 @@
"@nrwl/webpack": "file:../webpack",
"@nrwl/workspace": "file:../workspace",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.7",
"@rollup/plugin-url": "^7.0.0",
"@svgr/rollup": "^6.1.2",
"@svgr/webpack": "^6.1.2",
"chalk": "4.1.0",
"css-loader": "^6.4.0",
Expand Down
17 changes: 17 additions & 0 deletions packages/react/plugins/bundle-rollup.ts
@@ -1,5 +1,8 @@
import * as rollup from 'rollup';

import url from '@rollup/plugin-url';
import svg from '@svgr/rollup';

function getRollupOptions(options: rollup.RollupOptions) {
const extraGlobals = {
react: 'React',
Expand All @@ -8,6 +11,7 @@ function getRollupOptions(options: rollup.RollupOptions) {
'@emotion/react': 'emotionReact',
'@emotion/styled': 'emotionStyled',
};

if (Array.isArray(options.output)) {
options.output.forEach((o) => {
o.globals = { ...o.globals, ...extraGlobals };
Expand All @@ -21,6 +25,19 @@ function getRollupOptions(options: rollup.RollupOptions) {
},
};
}

options.plugins = [
svg({
svgo: false,
titleProp: true,
ref: true,
}),
url({
limit: 10000, // 10kB
}),
...options.plugins,
];

return options;
}

Expand Down
28 changes: 26 additions & 2 deletions yarn.lock
Expand Up @@ -4216,6 +4216,15 @@
is-module "^1.0.0"
resolve "^1.19.0"

"@rollup/plugin-url@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@rollup/plugin-url/-/plugin-url-7.0.0.tgz#571f6fd51c3d0e00f7404c67efdb93492bfac7f8"
integrity sha512-cIWcEObrmEPAU8q8NluGWlCPlQDuoSKvkyI3eOFO4fx6W02mLNj4ZEiUT0X2mKMIvQzoWL1feEK9d1yr1ICgrw==
dependencies:
"@rollup/pluginutils" "^4.2.1"
make-dir "^3.1.0"
mime "^2.4.6"

"@rollup/pluginutils@^3.0.8", "@rollup/pluginutils@^3.0.9", "@rollup/pluginutils@^3.1.0":
version "3.1.0"
resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-3.1.0.tgz#706b4524ee6dc8b103b3c995533e5ad680c02b9b"
Expand All @@ -4225,7 +4234,7 @@
estree-walker "^1.0.1"
picomatch "^2.2.2"

"@rollup/pluginutils@^4.1.2":
"@rollup/pluginutils@^4.1.2", "@rollup/pluginutils@^4.2.1":
version "4.2.1"
resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-4.2.1.tgz#e6c6c3aba0744edce3fb2074922d3776c0af2a6d"
integrity sha512-iKnFXr7NkdZAIHiIWE+BX5ULi/ucVFYWD6TbAV+rZctiRTY2PL6tsIKhoIOaoskiWAkgu+VsbXgUVDNLHf+InQ==
Expand Down Expand Up @@ -5604,6 +5613,21 @@
deepmerge "^4.2.2"
svgo "^2.8.0"

"@svgr/rollup@^6.1.2":
version "6.3.1"
resolved "https://registry.yarnpkg.com/@svgr/rollup/-/rollup-6.3.1.tgz#cf59c39f1f145383dfdeea7068ec18149360668e"
integrity sha512-TXcRT7pwsNU30bXxgooGAZQIXmPy7fxUnN/v5cuCpLiondRtKiV321kh/S/qhcQ6gSs6DvJmNDpbiqPZF66usw==
dependencies:
"@babel/core" "^7.18.5"
"@babel/plugin-transform-react-constant-elements" "^7.17.12"
"@babel/preset-env" "^7.18.2"
"@babel/preset-react" "^7.17.12"
"@babel/preset-typescript" "^7.17.12"
"@rollup/pluginutils" "^4.2.1"
"@svgr/core" "^6.3.1"
"@svgr/plugin-jsx" "^6.3.1"
"@svgr/plugin-svgo" "^6.3.1"

"@svgr/webpack@^6.1.2":
version "6.3.1"
resolved "https://registry.yarnpkg.com/@svgr/webpack/-/webpack-6.3.1.tgz#001d03236ebb03bf47c0a4b92d5423e05095ebe6"
Expand Down Expand Up @@ -16544,7 +16568,7 @@ mime@3.0.0:
resolved "https://registry.yarnpkg.com/mime/-/mime-3.0.0.tgz#b374550dca3a0c18443b0c950a6a58f1931cf7a7"
integrity sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==

mime@^2.4.4:
mime@^2.4.4, mime@^2.4.6:
version "2.6.0"
resolved "https://registry.yarnpkg.com/mime/-/mime-2.6.0.tgz#a2a682a95cd4d0cb1d6257e28f83da7e35800367"
integrity sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg==
Expand Down

0 comments on commit e24aa69

Please sign in to comment.