Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infrastructure: Update build tooling to use webpack v5 #5792

Merged
merged 203 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
203 commits
Select commit Hold shift + click to select a range
8af1aec
Update build tooling to use webpack v5
swissspidy Jan 4, 2021
ac62f42
Update karma-webpack to work with webpack 5
swissspidy Jan 4, 2021
c0dd4e0
Remove usage of `process`
swissspidy Jan 4, 2021
11de457
Tests: Define `process.env.RTL_SKIP_AUTO_CLEANUP`
swissspidy Jan 4, 2021
7a80f98
Use `window` instead of `global`
swissspidy Jan 4, 2021
407c5d3
Fix dynamic imports
swissspidy Jan 4, 2021
04d51fc
Add some safeguard
swissspidy Jan 4, 2021
9be2516
Lint fixes
swissspidy Jan 4, 2021
ff5e07d
Fix JS tests
swissspidy Jan 5, 2021
7437b9d
Lint fix
swissspidy Jan 5, 2021
e09fdbe
webpack: hide deprecation warnings for now
swissspidy Jan 5, 2021
b33834d
Improve webpack test config
swissspidy Jan 5, 2021
8efadc8
Update docs
swissspidy Jan 5, 2021
c40b487
Lint fix
swissspidy Jan 5, 2021
bf86991
Merge branch 'main' into chore/update-webpack
swissspidy Jan 15, 2021
f40e847
Fix global usage
swissspidy Jan 15, 2021
64cd792
Merge branch 'main' into chore/update-webpack
swissspidy Jan 29, 2021
ee04b2c
lint fixes
swissspidy Jan 29, 2021
e827eaa
Merge branch 'main' into chore/update-webpack
swissspidy Feb 1, 2021
bb024e6
Merge branch 'main' into chore/update-webpack
swissspidy Feb 4, 2021
b77b2d9
Merge branch 'main' into chore/update-webpack
swissspidy Feb 17, 2021
35e9041
Update storybook to make webpack 5 compatible
swissspidy Feb 22, 2021
a22ec0b
Merge branch 'main' into chore/update-webpack
swissspidy Feb 22, 2021
0cd6dc1
Update isDevelopment check
swissspidy Feb 22, 2021
209b203
Add webpack 5 builder
swissspidy Feb 22, 2021
c32ee7b
Update webpack-cli
swissspidy Feb 22, 2021
8357a3e
Fix DefinePlugin usage
swissspidy Feb 22, 2021
e3b2dd0
Fix storybook config
swissspidy Feb 22, 2021
462e85a
fix fonts package imports
swissspidy Feb 22, 2021
9b591cf
Update webpack usage
swissspidy Feb 22, 2021
6f198d0
Fix `global` usage
swissspidy Feb 22, 2021
e939dbb
More storybook updates
swissspidy Feb 22, 2021
47931ea
Lint fix
swissspidy Feb 22, 2021
9769524
Update karma config
swissspidy Feb 22, 2021
e4a12a0
Update jest config
swissspidy Feb 22, 2021
76be61b
Merge branch 'main' into chore/update-webpack
swissspidy Mar 10, 2021
dcddc4f
Update stylelintignore
swissspidy Mar 10, 2021
6461b61
Add missing `Object.defineProperty` call
swissspidy Mar 10, 2021
bb93116
back to commonjs
swissspidy Mar 11, 2021
41d863c
Merge branch 'main' into chore/update-webpack
swissspidy Mar 11, 2021
1c3a395
Merge branch 'main' into chore/update-webpack
swissspidy Mar 11, 2021
b263b65
Merge branch 'main' into chore/update-webpack
swissspidy Mar 11, 2021
24e9bb1
update deps
swissspidy Mar 11, 2021
adaa476
Update patch-package
swissspidy Mar 11, 2021
5458940
update deps once again
swissspidy Mar 11, 2021
e652c6b
Merge branch 'main' into chore/update-webpack
swissspidy Mar 12, 2021
9b42f2c
Revert some more changes
swissspidy Mar 12, 2021
cc25f86
Merge branch 'main' into chore/update-webpack
swissspidy Mar 12, 2021
da4d88e
Merge branch 'main' into chore/update-webpack
swissspidy Mar 15, 2021
2ab6a48
Update patch file name
swissspidy Mar 15, 2021
00eb44e
Update lock file
swissspidy Mar 15, 2021
2092354
Undo change to distignore
swissspidy Mar 15, 2021
251073a
lint fixes
swissspidy Mar 15, 2021
143d741
fix peer deps
swissspidy Mar 15, 2021
e987d80
Update regex for compressed-size-action
swissspidy Mar 15, 2021
3743ed5
Patch storybook-rtl-addon
swissspidy Mar 15, 2021
138eae0
Update to latest storybook beta
swissspidy Mar 15, 2021
73f3320
Merge branch 'main' into chore/update-webpack
swissspidy Mar 19, 2021
1a5bd6b
Update storybook
swissspidy Mar 19, 2021
337b31f
Update css-loader
swissspidy Mar 19, 2021
36c1a3d
Lint fix
swissspidy Mar 19, 2021
95f8238
Fix import from block.json
swissspidy Mar 19, 2021
16feb56
Merge branch 'main' into chore/update-webpack
swissspidy Apr 15, 2021
9de3311
Remove storybook-rtl-addon patch
swissspidy Apr 15, 2021
5efa5a1
Update react-refresh-webpack-plugin
swissspidy Apr 15, 2021
e5a8514
Update some packages
swissspidy Apr 15, 2021
bb03746
Update lock file
swissspidy Apr 15, 2021
011b06e
Update lock file
swissspidy Apr 15, 2021
edf4965
Merge branch 'main' into chore/update-webpack
swissspidy May 18, 2021
044a105
Merge branch 'main' into chore/update-webpack
swissspidy May 18, 2021
33c27b8
Update jest config
swissspidy May 18, 2021
df804f6
Add todo
swissspidy May 18, 2021
f003e0b
Merge branch 'main' into chore/update-webpack
swissspidy May 18, 2021
72dc280
Merge branch 'main' into chore/update-webpack
swissspidy May 18, 2021
47a5d10
Merge branch 'main' into chore/update-webpack
swissspidy Jul 2, 2021
8e6660d
Merge branch 'main' into chore/update-webpack
swissspidy Jul 2, 2021
3f9cd4e
Undo changes to babel config
swissspidy Jul 2, 2021
67ea513
Remove Testing Library edge case handling
swissspidy Jul 2, 2021
10fb622
Remove now unneeded import
swissspidy Jul 2, 2021
7245fc0
Fix incorrect `use-debounce` imports
swissspidy Jul 2, 2021
57d1669
Add comment
swissspidy Jul 2, 2021
ccb42d2
Use new `WEB_STORIES_CI` variable
swissspidy Jul 2, 2021
b08d96c
Ignore eslint warnings
swissspidy Jul 2, 2021
dd6ac25
Merge branch 'main' into chore/update-webpack
swissspidy Jul 21, 2021
90b3736
Lint fix
swissspidy Jul 21, 2021
c01dc3b
Merge branch 'main' into chore/update-webpack
swissspidy Jul 22, 2021
fa64dba
Merge branch 'main' into chore/update-webpack
swissspidy Jul 22, 2021
720ad2c
Update ESLint config
swissspidy Jul 22, 2021
e79928b
Update packages
swissspidy Jul 22, 2021
1a483a1
Merge branch 'main' into chore/update-webpack
swissspidy Aug 2, 2021
dfa14c3
Merge branch 'main' into chore/update-webpack
swissspidy Aug 11, 2021
f107262
Merge branch 'main' into chore/update-webpack
swissspidy Aug 17, 2021
2a740aa
Merge branch 'main' into chore/update-webpack
swissspidy Aug 20, 2021
58d0ac1
Fix order of dependencies
swissspidy Aug 20, 2021
22ce0d0
Add missing dependency
swissspidy Aug 20, 2021
a41d36d
Remove thread-loader
swissspidy Aug 20, 2021
321f004
Define missing global
swissspidy Aug 20, 2021
9a5f2b1
Merge branch 'main' into chore/update-webpack
swissspidy Nov 17, 2021
265bac0
Update expose-loader
swissspidy Nov 17, 2021
4c3cab3
Lint fixes
swissspidy Nov 17, 2021
4a3e93a
Karma: output files to tmp folder
swissspidy Nov 17, 2021
c3b7b05
Try using `mangleExports`
swissspidy Nov 17, 2021
159d654
Check for file before retrying
swissspidy Nov 17, 2021
cdbd272
Prevent warning by karma-webpack about configuration
swissspidy Nov 17, 2021
463afd9
Lint fixes
swissspidy Nov 17, 2021
beb6c22
Update storybook packages
swissspidy Nov 17, 2021
baaa09f
Filter out chunks without name
swissspidy Nov 17, 2021
8432a42
Merge branch 'main' into chore/update-webpack
swissspidy Nov 17, 2021
51c2102
Lint fixes
swissspidy Nov 17, 2021
f94f20c
Merge branch 'main' into chore/update-webpack
swissspidy Jan 11, 2022
3f717d9
Fix dep version
swissspidy Jan 11, 2022
7d680ef
Fix accidental broken import
swissspidy Jan 11, 2022
0d924f0
Update `@svgr/webpack`
swissspidy Jan 11, 2022
668b214
Lint fix
swissspidy Jan 11, 2022
58035ed
Merge branch 'main' into chore/update-webpack
swissspidy Feb 1, 2022
684f450
Update eslint config / fix lints
swissspidy Feb 1, 2022
0afe518
Remove eslint disabled
samwhale Feb 1, 2022
78fc4d0
NOT DONE
samwhale Feb 2, 2022
82af79b
Merge branch 'main' into chore/update-webpack
samwhale Feb 3, 2022
d4dc66c
Add missing storybook builder
samwhale Feb 3, 2022
be28ddd
Revert "NOT DONE"
samwhale Feb 3, 2022
15d5371
Some progress with svgr update
samwhale Feb 3, 2022
de47299
Maybe get svgo working, but storybook failing on fonts.json
samwhale Feb 7, 2022
6def948
Merge branch 'main' into chore/update-webpack
swissspidy Feb 8, 2022
fcef06c
Merge branch 'main' into chore/update-webpack
swissspidy Feb 8, 2022
323fee1
Try fixing fonts import
swissspidy Feb 8, 2022
83b1bc7
Storybook works!
samwhale Feb 8, 2022
1ea71c4
remove file-loader from storybook rules
samwhale Feb 8, 2022
fac4f51
Remove deprecated file-loader
samwhale Feb 8, 2022
87f80b8
Remove webpack from dependencies in storybook
samwhale Feb 8, 2022
adde49a
Allow use of multiple loaders
samwhale Feb 8, 2022
1dd7f67
Use default presets
samwhale Feb 8, 2022
a8fd419
Update config to use svgo defaults
samwhale Feb 8, 2022
4e66c25
Add eslint rule for main.cjs webpack import
samwhale Feb 8, 2022
daed85d
Get karma tests working
samwhale Feb 10, 2022
5c874fb
Merge branch 'main' into chore/update-webpack
samwhale Feb 10, 2022
856ff87
Remove double import of webpack
samwhale Feb 10, 2022
cd14157
Fix failing tests + spelling
samwhale Feb 10, 2022
38c8951
Add comment for karma test fix
samwhale Feb 10, 2022
6c33325
Fix lint rules
samwhale Feb 10, 2022
970408b
Don't need empty package.json
samwhale Feb 10, 2022
741da73
Merge branch 'main' into chore/update-webpack
samwhale Feb 10, 2022
56e9f03
Remove unneeded rules!
samwhale Feb 10, 2022
714fc52
Remove dead code
samwhale Feb 10, 2022
b6c820d
Okay maybe we do need this lint rule
samwhale Feb 10, 2022
dbc5e3a
Assorted fixes
samwhale Feb 10, 2022
71a4fab
Import default imports (icons) using a better syntax
samwhale Feb 10, 2022
26f8313
Fix png rule
samwhale Feb 11, 2022
f1b8edc
Merge branch 'main' into chore/update-webpack
samwhale Feb 11, 2022
2b1cc9e
Webpack 5 can use web workers without worker-loader
samwhale Feb 11, 2022
71ba4ac
Updates to svg in moveable package
samwhale Feb 14, 2022
933946a
Merge branch 'main' into chore/update-webpack
samwhale Feb 14, 2022
1f85854
Fix svg loaded in as inline asset
samwhale Feb 15, 2022
0ef1d82
Merge branch 'main' into chore/update-webpack
samwhale Feb 15, 2022
aa32e94
Revert change to `fill`, update comment
samwhale Feb 15, 2022
3cb26ad
Merge branch 'main' into chore/update-webpack
samwhale Feb 15, 2022
8578874
Merge branch 'main' into chore/update-webpack
spacedmonkey Feb 16, 2022
97cc89d
Use current color on svgs that were missing it
samwhale Feb 17, 2022
1f5ce78
Webworker works
samwhale Feb 18, 2022
82e33a2
Merge branch 'main' into chore/update-webpack
samwhale Feb 18, 2022
a1418d8
Fix lint probs
samwhale Feb 18, 2022
f35afad
WIP: Trying to inline blurhash in webworker script
samwhale Feb 21, 2022
c416836
Worker-loader can still work
samwhale Feb 21, 2022
bec18cd
Remove logs and comments from webworker testing
samwhale Feb 21, 2022
3722a9c
Merge branch 'main' into chore/update-webpack
samwhale Feb 21, 2022
862cf5e
Fix svgo: convert colors to `currentColor`
samwhale Feb 21, 2022
665eaf7
Merge branch 'main' into chore/update-webpack
samwhale Feb 21, 2022
9371cb4
Eliminate sourcemap errors for node modules
samwhale Feb 21, 2022
5883989
Merge branch 'main' into chore/update-webpack
samwhale Feb 21, 2022
23d7aed
Remove extra webpack logging
samwhale Feb 21, 2022
4ce26bc
Merge branch 'main' into chore/update-webpack
samwhale Feb 21, 2022
94bc0c4
Fix ESLint config
swissspidy Feb 22, 2022
a00a9cd
Merge branch 'main' into chore/update-webpack
swissspidy Feb 22, 2022
5db3ad4
Ensure same version for all storybook packages
swissspidy Feb 22, 2022
1e773f4
Remove dotenv-webpack agaibn
swissspidy Feb 22, 2022
24900cf
Remove now unused expose-loader
swissspidy Feb 22, 2022
b449e83
Update blurhash package
swissspidy Feb 22, 2022
5f7ff2b
Address deprecation warning in webpack config
swissspidy Feb 22, 2022
3a51353
Make source-map-loader config more specific
swissspidy Feb 22, 2022
5d6ded1
Restore separate SVGO config for images and icons
swissspidy Feb 22, 2022
c421190
Try using `customExports` field for packages
swissspidy Feb 22, 2022
1f7b6b2
Fix JSDoc in Rollup config
swissspidy Feb 22, 2022
d4a4619
Fix Rollup builds by not using `resourceQuery`
swissspidy Feb 22, 2022
f98f4fd
Move all icons to an icons folder
swissspidy Feb 22, 2022
efaa8f2
Restore workaround
swissspidy Feb 22, 2022
030c7c2
Lint fix
swissspidy Feb 22, 2022
795b724
Merge branch 'main' into chore/update-webpack
swissspidy Feb 22, 2022
47a4499
Add todo
swissspidy Feb 22, 2022
e8188a8
Fix storybook: remove addition of `mainFields` to webpack resolve
samwhale Feb 22, 2022
4bc54d3
Remove obsolete `resolve.fallback` config
swissspidy Feb 22, 2022
176fe5d
Fix eslint-import-resolver config for fonts.json
swissspidy Feb 22, 2022
30e02ab
Merge branch 'main' into chore/update-webpack
swissspidy Feb 22, 2022
8481b5d
Update comments for storybook 6.4 hack
samwhale Feb 23, 2022
6f8a75d
Add SVG documentation
samwhale Feb 23, 2022
22e03aa
Merge branch 'main' into chore/update-webpack
samwhale Feb 23, 2022
88e3997
Remove some obsolete Babel plugins
swissspidy Feb 24, 2022
bc13f1d
Merge branch 'main' into chore/update-webpack
swissspidy Feb 25, 2022
a3162d2
Merge branch 'main' into chore/update-webpack
samwhale Feb 28, 2022
e9e0a38
Fix package.json for new packages
swissspidy Feb 28, 2022
9099fbd
Small cleanup
samwhale Feb 28, 2022
670d289
Merge branch 'main' into chore/update-webpack
samwhale Feb 28, 2022
6403518
Merge branch 'main' into chore/update-webpack
samwhale Feb 28, 2022
876420d
Merge branch 'main' into chore/update-webpack
swissspidy Mar 2, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@
"import/resolver": {
"@web-stories-wp/eslint-import-resolver": {
"mapping": {
"^@googleforcreators\\/(.*)\\/(.*)": "./packages/$1/src/$2",
"^@googleforcreators\\/(.*)": "./packages/$1/src/",
"^@web-stories-wp\\/(.*)": "./packages/$1/src/"
}
Expand Down Expand Up @@ -348,7 +349,8 @@
"jasmine"
],
"env": {
"jasmine": true
"jasmine": true,
"node": true
},
"rules": {
"eslint-comments/require-description": "off",
Expand Down
22 changes: 1 addition & 21 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,7 @@ updates:
- Dependencies
- JavaScript
ignore:
# Blocked by https://github.com/googleforcreators/web-stories-wp/pull/5792.
- dependency-name: 'webpack'
versions:
- '>= 5'

# Blocked by https://github.com/googleforcreators/web-stories-wp/pull/5792.
- dependency-name: 'html-webpack-plugin'
versions:
- '>= 5'

# Blocked by https://github.com/googleforcreators/web-stories-wp/pull/5792.
- dependency-name: 'karma-webpack'
versions:
- '>= 5'

# Blocked by https://github.com/googleforcreators/web-stories-wp/pull/5792.
- dependency-name: 'source-map-loader'
versions:
- '>= 2'

# styled components is not yet compatible.
# styled-components is not yet compatible.
- dependency-name: 'stylis-plugin-rtl'
versions:
- '>= 2'
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ jobs:
pattern: '{assets/js/*.js,assets/css/*.css}'
build-script: 'build:js'
minimum-change-threshold: 100
# Ignore webpack content hash in bundle filenames.
strip-hash: '.*-(\w{20})\.js$'
# Ignore chunk and module hashes in bundle filenames.
strip-hash: '.*-(\w{20})|^(\d{2,5})\.js$'

build:
name: Package ZIP files
Expand Down Expand Up @@ -142,7 +142,7 @@ jobs:
- name: Bundle development version
run: |
rm -rf assets/css/* assets/js/*
NODE_ENV=development npx webpack --config webpack.config.cjs
npx webpack --node-env=development
npm run workflow:build-plugin
mv build/web-stories build/web-stories-dev/

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/plugin-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ jobs:
- name: Bundle development version
run: |
rm -rf assets/css/* assets/js/*
NODE_ENV=development npx webpack --config webpack.config.cjs
npx webpack --node-env=development
npm run workflow:build-plugin -- --zip web-stories-dev.zip

- name: Prepare release artifacts
Expand Down
7 changes: 3 additions & 4 deletions .npmpackagejsonlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"files",
"type",
"workspaces",
"customExports",
"exports",
"main",
"module",
Expand Down Expand Up @@ -102,10 +103,8 @@
"require-scripts": "off",
"require-version": "off",
"scripts-type": "error",
"valid-values-author": ["error", [
"Google"
]],
"valid-values-license": [ "error", [ "Apache-2.0" ] ],
"valid-values-author": ["error", ["Google"]],
"valid-values-license": ["error", ["Apache-2.0"]],
"valid-values-private": "off",
"version-format": "error",
"version-type": "error"
Expand Down
229 changes: 164 additions & 65 deletions .storybook/main.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,26 @@
/**
* External dependencies
*/
const path = require('path');
const webpack = require('webpack');
samwhale marked this conversation as resolved.
Show resolved Hide resolved

/**
* Storybook Workaround: https://github.com/storybookjs/storybook/issues/14877#issuecomment-1000441696
*
* @param {string} filePath Original file path
* @param {string} newExtension Extension to use (such as .cjs or .html)
* @return {Object} updated path
*/
const replaceFileExtension = (filePath, newExtension) => {
const { name, root, dir } = path.parse(filePath);
return path.format({
name,
root,
dir,
ext: newExtension,
});
};

module.exports = {
stories: [
'./stories/**/*.js',
Expand All @@ -33,28 +51,59 @@ module.exports = {
'@storybook/addon-essentials',
'@storybook/addon-storysource/register',
],
core: {
builder: 'webpack5',
},
reactOptions: {
fastRefresh: true,
// Disabled due to compatibility issues with webpack 5.
// See https://github.com/pmmmwh/react-refresh-webpack-plugin/issues/308
fastRefresh: false,
strictMode: true,
},
//eslint-disable-next-line require-await -- Negligible.
webpackFinal: async (config) => {
// Modifies storybook's webpack config to use svgr instead of file-loader.
// see https://github.com/storybookjs/storybook/issues/5613

const assetRule = config.module.rules.find(({ test }) => test.test('.svg'));
const assetLoader = {
loader: assetRule.loader,
options: assetRule.options || assetRule.query,
// webpack < 5 used to include polyfills for node.js core modules by default.
// Prevent ModuleNotFoundError for this dependency.
config.resolve = {
...config.resolve,
// Fixes resolving packages in the monorepo so we use the "src" folder, not "dist".
// This should be sync'd with the config in `webpack.config.cjs`.
exportsFields: ['customExports', 'exports'],
};

// Avoid having to provide full file extension for imports.
// See https://webpack.js.org/configuration/module/#resolvefullyspecified

config.module.rules = config.module.rules.map((rule) => ({
...rule,
resolve: {
...rule.resolve,
fullySpecified: false,
},
}));

// These should be sync'd with the config in `webpack.config.cjs`.
config.plugins.push(
new webpack.DefinePlugin({
WEB_STORIES_CI: JSON.stringify(process.env.CI),
WEB_STORIES_ENV: JSON.stringify(process.env.NODE_ENV),
WEB_STORIES_DISABLE_ERROR_BOUNDARIES: JSON.stringify(
process.env.DISABLE_ERROR_BOUNDARIES
),
WEB_STORIES_DISABLE_OPTIMIZED_RENDERING: JSON.stringify(
process.env.DISABLE_OPTIMIZED_RENDERING
),
WEB_STORIES_DISABLE_PREVENT: JSON.stringify(
process.env.DISABLE_PREVENT
),
WEB_STORIES_DISABLE_QUICK_TIPS: JSON.stringify(
process.env.DISABLE_QUICK_TIPS
),
})
);

// These should be sync'd with the config in `webpack.config.cjs`.

config.resolve = {
// Fixes resolving packages in the monorepo so we use the "src" folder, not "dist".
// TODO: Revisit after upgrading to webpack v5 or when splitting repository.
mainFields: ['browser', 'module', 'main', 'source'],
};
config.plugins.push(
new webpack.DefinePlugin({
WEB_STORIES_CI: JSON.stringify(process.env.CI),
Expand All @@ -74,76 +123,126 @@ module.exports = {
})
);

// Ensure SVGR is the only loader used for files with .svg extension.
const assetRule = config.module.rules.find(({ test }) => test.test('.svg'));
assetRule.exclude = /\.svg/;

config.module.rules.unshift(
{
test: /\.svg$/,
use: [
// Use asset SVG and SVGR together.
// Not using resourceQuery because it doesn't work well with Rollup.
// https://react-svgr.com/docs/webpack/#use-svgr-and-asset-svg-in-the-same-project
oneOf: [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we only use one loader. If a url resource query is found on the import (i.e. ./icons/arrow_circle.svg?url) then that asset will be loaded in using the asset/inline asset module.

Importing both in the same file will import one as a reach component, and the other as a data uri ✨

import arrowCircle from './icons/arrow_circle.svg?url';
import ArrowCircle from './icons/arrow_circle.svg';

image

{
loader: '@svgr/webpack',
options: {
titleProp: true,
svgo: true,
memo: true,
svgoConfig: {
plugins: [
{
removeViewBox: false,
removeDimensions: true,
convertColors: {
currentColor: /^(?!url|none)/i,
},
type: 'asset/inline',
include: [/inline-icons\/.*\.svg$/],
},
{
issuer: /\.js?$/,
include: [/\/icons\/.*\.svg$/],
use: [
{
loader: '@svgr/webpack',
options: {
titleProp: true,
svgo: true,
memo: true,
svgoConfig: {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
removeViewBox: false,
convertColors: {
currentColor: /^(?!url|none)/i,
},
},
},
},
'removeDimensions',
],
},
],
},
},
},
],
},
'url-loader',
assetLoader,
],
exclude: [/images\/.*\.svg$/],
},
{
test: /\.svg$/,
use: [
{
loader: '@svgr/webpack',
options: {
titleProp: true,
svgo: true,
memo: true,
svgoConfig: {
plugins: [
{
removeViewBox: false,
removeDimensions: true,
convertColors: {
// See https://github.com/googleforcreators/web-stories-wp/pull/6361
currentColor: false,
},
issuer: /\.js?$/,
include: [/images\/.*\.svg$/],
use: [
{
loader: '@svgr/webpack',
options: {
titleProp: true,
svgo: true,
memo: true,
svgoConfig: {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
removeViewBox: false,
convertColors: {
// See https://github.com/googleforcreators/web-stories-wp/pull/6361
currentColor: false,
},
},
},
},
'removeDimensions',
],
},
],
},
},
},
],
},
'url-loader',
],
include: [/images\/.*\.svg$/],
},
{
test: /\.(png|jpe?g|gif|webp)$/i,
use: [
{
loader: 'file-loader',
options: {
outputPath: 'images',
},
},
],
type: 'asset/resource',
generator: {
outputPath: 'images/',
},
}
);

// only the first matching rule is used when there is a match.
config.module.rules = [{ oneOf: config.module.rules }];
/*
Webpack + Storybook 6.4 - webpack crashing due to plugins
that are compiled to CJS while project uses ESM.
TODO: 10696: Remove with storybook 6.5
*/
// https://github.com/storybookjs/storybook/issues/14877#issuecomment-1000441696

// Find the plugin instance that needs to be mutated
const virtualModulesPlugin = config.plugins.find(
(plugin) => plugin.constructor.name === 'VirtualModulesPlugin'
);

// Change the file extension to .cjs for all files that end with "generated-stories-entry.js"
virtualModulesPlugin._staticModules = Object.fromEntries(
Object.entries(virtualModulesPlugin._staticModules).map(
([key, value]) => {
if (key.endsWith('generated-stories-entry.js')) {
return [replaceFileExtension(key, '.cjs'), value];
}
return [key, value];
}
)
);

// Change the entry points to point to the appropriate .cjs files
config.entry = config.entry.map((entry) => {
if (entry.endsWith('generated-stories-entry.js')) {
return replaceFileExtension(entry, '.cjs');
}
return entry;
});

/* End storybook 6.4 non .cjs extension patch */

return config;
},
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/playground/story-editor/api/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

export async function getFonts(params) {
let { default: fonts } = await import(
/* webpackChunkName: "chunk-fonts" */ '@googleforcreators/fonts/src/fonts.json' //eslint-disable-line import/no-internal-modules -- TODO: Improve export in module.
/* webpackChunkName: "chunk-fonts" */ '@googleforcreators/fonts/fonts.json' // eslint-disable-line import/no-internal-modules -- This is fine here.
);

fonts = fonts.map((font) => ({
Expand Down
6 changes: 0 additions & 6 deletions babel.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ module.exports = function (api) {
plugins: [
'@wordpress/babel-plugin-import-jsx-pragma',
'babel-plugin-styled-components',
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-private-methods',
'babel-plugin-inline-json-import',
'@babel/plugin-syntax-top-level-await',
'@babel/plugin-proposal-optional-chaining',
'@babel/plugin-proposal-nullish-coalescing-operator',
],
sourceMaps: true,
env: {
Expand Down
Loading