@emulsify/core 3.5.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/.cli/init.js +40 -31
  2. package/.storybook/_drupal.js +129 -8
  3. package/.storybook/css-components.js +13 -0
  4. package/.storybook/css-dist.js +5 -0
  5. package/.storybook/emulsifyTheme.js +9 -6
  6. package/.storybook/main.js +397 -106
  7. package/.storybook/manager.js +9 -16
  8. package/.storybook/preview.js +88 -110
  9. package/.storybook/utils.js +69 -74
  10. package/README.md +110 -59
  11. package/config/.stylelintrc.json +2 -6
  12. package/config/a11y.config.js +9 -5
  13. package/config/babel.config.js +6 -11
  14. package/config/eslint.config.js +31 -3
  15. package/config/postcss.config.js +5 -0
  16. package/config/vite/entries.js +227 -0
  17. package/config/vite/environment.js +39 -0
  18. package/config/vite/platforms.js +70 -0
  19. package/config/vite/plugins/copy-src-assets.js +76 -0
  20. package/config/vite/plugins/copy-twig-files.js +84 -0
  21. package/config/vite/plugins/css-asset-relativizer.js +40 -0
  22. package/config/vite/plugins/index.js +105 -0
  23. package/config/vite/plugins/mirror-components.js +358 -0
  24. package/config/vite/plugins/require-context.js +311 -0
  25. package/config/vite/plugins/source-file-index.js +184 -0
  26. package/config/vite/plugins/svg-sprite.js +117 -0
  27. package/config/vite/plugins/twig-extension-installers.js +36 -0
  28. package/config/vite/plugins/twig-module.js +1251 -0
  29. package/config/vite/plugins/virtual-twig-asset-sources.js +404 -0
  30. package/config/vite/plugins/virtual-twig-globs.js +136 -0
  31. package/config/vite/plugins/vituum-patch.js +167 -0
  32. package/config/vite/plugins/yaml-module.js +133 -0
  33. package/config/vite/plugins.js +12 -0
  34. package/config/vite/project-config.js +192 -0
  35. package/config/vite/project-extensions.js +177 -0
  36. package/config/vite/project-structure.js +447 -0
  37. package/config/vite/twig-extensions.js +109 -0
  38. package/config/vite/utils/fs-safe.js +66 -0
  39. package/config/vite/utils/paths.js +40 -0
  40. package/config/vite/utils/react-singleton.js +85 -0
  41. package/config/vite/utils/unique.js +36 -0
  42. package/config/vite/vite.config.js +161 -0
  43. package/package.json +164 -75
  44. package/scripts/a11y.js +70 -16
  45. package/scripts/audit-twig-stories.js +378 -0
  46. package/scripts/audit.js +1602 -0
  47. package/scripts/check-node-version.js +18 -0
  48. package/scripts/loadYaml.js +5 -1
  49. package/src/extensions/index.js +8 -0
  50. package/src/extensions/react/index.js +12 -0
  51. package/src/extensions/react/register.js +45 -0
  52. package/src/extensions/shared/attributes.js +308 -0
  53. package/src/extensions/shared/html.js +41 -0
  54. package/src/extensions/shared/lists.js +38 -0
  55. package/src/extensions/shared/object.js +22 -0
  56. package/src/extensions/twig/function-map.js +20 -0
  57. package/src/extensions/twig/functions/add-attributes.js +39 -0
  58. package/src/extensions/twig/functions/bem.js +166 -0
  59. package/src/extensions/twig/index.js +13 -0
  60. package/src/extensions/twig/register.js +52 -0
  61. package/src/extensions/twig/tag-map.js +16 -0
  62. package/src/extensions/twig/tags/switch.js +266 -0
  63. package/src/storybook/index.js +14 -0
  64. package/src/storybook/main-config.js +132 -0
  65. package/src/storybook/platform-behaviors.js +60 -0
  66. package/src/storybook/preview-parameters.js +81 -0
  67. package/src/storybook/render-twig.js +295 -0
  68. package/src/storybook/twig/drupal-filters.js +7 -0
  69. package/src/storybook/twig/include-function.js +109 -0
  70. package/src/storybook/twig/include.js +28 -0
  71. package/src/storybook/twig/reference-paths.js +294 -0
  72. package/src/storybook/twig/resolver.js +318 -0
  73. package/src/storybook/twig/setup.js +39 -0
  74. package/src/storybook/twig/source-events.js +5 -0
  75. package/src/storybook/twig/source-extensions.js +24 -0
  76. package/src/storybook/twig/source-function.js +239 -0
  77. package/src/storybook/twig/source.js +39 -0
  78. package/.all-contributorsrc +0 -45
  79. package/.editorconfig +0 -5
  80. package/.github/ISSUE_TEMPLATE/BUG_REPORT_TEMPLATE.md +0 -18
  81. package/.github/ISSUE_TEMPLATE/FEATURE_REQUEST_TEMPLATE.md +0 -11
  82. package/.github/PULL_REQUEST_TEMPLATE.md +0 -19
  83. package/.github/dependabot.yml +0 -6
  84. package/.github/workflows/addtoprojects.yml +0 -21
  85. package/.github/workflows/contributors.yml +0 -37
  86. package/.github/workflows/lint.yml +0 -22
  87. package/.github/workflows/semantic-release.yml +0 -24
  88. package/.husky/commit-msg +0 -2
  89. package/.husky/pre-commit +0 -2
  90. package/.nvmrc +0 -1
  91. package/.prettierignore +0 -4
  92. package/.storybook/polyfills/twig-include.js +0 -40
  93. package/.storybook/polyfills/twig-resolver.js +0 -70
  94. package/.storybook/polyfills/twig-source.js +0 -65
  95. package/.storybook/webpack.config.js +0 -269
  96. package/CODE_OF_CONDUCT.md +0 -56
  97. package/commitlint.config.js +0 -5
  98. package/config/jest.config.js +0 -19
  99. package/config/webpack/app.js +0 -1
  100. package/config/webpack/loaders.js +0 -167
  101. package/config/webpack/optimizers.js +0 -26
  102. package/config/webpack/plugins.js +0 -283
  103. package/config/webpack/resolves.js +0 -157
  104. package/config/webpack/sdc-loader.js +0 -16
  105. package/config/webpack/webpack.common.js +0 -272
  106. package/config/webpack/webpack.dev.js +0 -41
  107. package/config/webpack/webpack.prod.js +0 -6
  108. package/release.config.cjs +0 -30
  109. package/scripts/a11y.test.js +0 -172
  110. package/scripts/loadYaml.test.js +0 -30
@@ -1,65 +0,0 @@
1
- import { getProjectMachineName } from '../utils.js';
2
-
3
- const namespace = getProjectMachineName();
4
-
5
- // Constants used by the `source()` polyfill.
6
- const PUBLIC_ASSET_BASE =
7
- typeof window !== 'undefined' &&
8
- window.location &&
9
- window.location.hostname &&
10
- window.location.hostname.endsWith('github.io')
11
- ? `/${namespace}/assets/`
12
- : '/assets/';
13
-
14
- const INLINE_ASSET_EXTS = new Set([
15
- 'svg',
16
- 'html',
17
- 'twig',
18
- 'css',
19
- 'js',
20
- 'json',
21
- 'txt',
22
- 'md',
23
- ]);
24
- const IMAGE_ASSET_EXTS = new Set(['png', 'jpg', 'jpeg', 'gif', 'webp', 'avif']);
25
-
26
- /**
27
- * Twig `source()` polyfill.
28
- * Returns an <img> tag or URL for @assets paths.
29
- * @param {string} assetPath
30
- * @return {string}
31
- */
32
- function twigSource(Twig) {
33
- Twig.extendFunction('source', (assetPath) => {
34
- if (typeof assetPath !== 'string') return '';
35
-
36
- // Strip Drupal-style alias and extract file extension.
37
- const relPath = assetPath.replace(/^@assets\//, '');
38
- const extension = relPath.split('.').pop().toLowerCase();
39
-
40
- // Inline raw content for textual assets.
41
- if (INLINE_ASSET_EXTS.has(extension)) {
42
- try {
43
- const xhr = new XMLHttpRequest();
44
- xhr.open('GET', `${PUBLIC_ASSET_BASE}${relPath}`, false); // synchronous
45
- xhr.send(null);
46
- if (xhr.status >= 200 && xhr.status < 300) {
47
- return xhr.responseText;
48
- }
49
- console.error(`source(): ${xhr.status} while fetching ${relPath}`);
50
- } catch (err) {
51
- console.error(`source(): failed to fetch ${relPath}`, err);
52
- }
53
- }
54
-
55
- // Auto-render raster images.
56
- if (IMAGE_ASSET_EXTS.has(extension)) {
57
- return `<img src="${PUBLIC_ASSET_BASE}${relPath}" alt="" role="img">`;
58
- }
59
-
60
- // Fallback: return public URL.
61
- return `${PUBLIC_ASSET_BASE}${relPath}`;
62
- });
63
- }
64
-
65
- export default twigSource;
@@ -1,269 +0,0 @@
1
- import { dirname, resolve } from 'path';
2
- import { createRequire } from 'module';
3
- import globImporter from 'node-sass-glob-importer';
4
- import _StyleLintPlugin from 'stylelint-webpack-plugin';
5
- import webpack from 'webpack';
6
- import resolves from '../config/webpack/resolves.js';
7
- import emulsifyConfig from '../../../../project.emulsify.json' with { type: 'json' };
8
-
9
- const require = createRequire(import.meta.url);
10
-
11
- // Create __filename from import.meta.url without fileURLToPath
12
- let _filename = decodeURIComponent(new URL(import.meta.url).pathname);
13
-
14
- // On Windows, remove the leading slash (e.g. "/C:/path" -> "C:/path")
15
- if (process.platform === 'win32' && _filename.startsWith('/')) {
16
- _filename = _filename.slice(1);
17
- }
18
-
19
- /**
20
- * Directory name of the current file.
21
- * @type {string}
22
- */
23
- const _dirname = dirname(_filename);
24
-
25
- /**
26
- * Absolute path to the project root directory.
27
- * @type {string}
28
- */
29
- const projectDir = resolve(_dirname, '../../../../..');
30
-
31
- /**
32
- * Webpack plugin to resolve custom namespace imports.
33
- * Transforms `<prefix>:<component>` into `<prefix>/<component>` paths.
34
- */
35
- class ProjectNameResolverPlugin {
36
- /**
37
- * @param {object} options - Plugin options.
38
- * @param {string} options.projectName - Prefix for the project namespace.
39
- */
40
- constructor(options = {}) {
41
- this.prefix = options.projectName;
42
- }
43
-
44
- /**
45
- * Apply the webpack resolver hook.
46
- * @param {object} resolver - The webpack resolver instance.
47
- */
48
- apply(resolver) {
49
- const target = resolver.ensureHook('resolve');
50
- resolver.getHook('before-resolve').tapAsync(
51
- 'ProjectNameResolverPlugin',
52
- /**
53
- * @param {object} request - The resolve request object.
54
- * @param {object} resolveContext - Context for resolving.
55
- * @param {Function} callback - Callback to continue resolution.
56
- */
57
- (request, resolveContext, callback) => {
58
- const requestPath = request.request;
59
-
60
- if (requestPath && requestPath.startsWith(`${this.prefix}:`)) {
61
- const newRequestPath = requestPath.replace(
62
- `${this.prefix}:`,
63
- `${this.prefix}/`,
64
- );
65
- const newRequest = {
66
- ...request,
67
- request: newRequestPath,
68
- };
69
-
70
- resolver.doResolve(
71
- target,
72
- newRequest,
73
- `Resolved ${this.prefix} URI`,
74
- resolveContext,
75
- callback,
76
- );
77
- } else {
78
- callback();
79
- }
80
- },
81
- );
82
- }
83
- }
84
-
85
- /**
86
- * Export a function to customize the Webpack config for Storybook.
87
- * @param {object} param0 - The Storybook configuration object.
88
- * @param {object} param0.config - The existing webpack config to modify.
89
- * @returns {object} The updated webpack config.
90
- */
91
- export default async function ({ config }) {
92
- config.resolve = config.resolve || {};
93
- config.plugins = config.plugins || [];
94
-
95
- config.module = config.module || {};
96
- config.module.rules = config.module.rules || [];
97
-
98
- const hasLoader = (rule, loaderName) => {
99
- if (!rule) {
100
- return false;
101
- }
102
-
103
- if (typeof rule.loader === 'string' && rule.loader.includes(loaderName)) {
104
- return true;
105
- }
106
-
107
- const use = rule.use;
108
- if (typeof use === 'string') {
109
- return use.includes(loaderName);
110
- }
111
- if (Array.isArray(use)) {
112
- return use.some((entry) => {
113
- if (typeof entry === 'string') {
114
- return entry.includes(loaderName);
115
- }
116
- return (
117
- entry &&
118
- typeof entry.loader === 'string' &&
119
- entry.loader.includes(loaderName)
120
- );
121
- });
122
- }
123
-
124
- return false;
125
- };
126
-
127
- const hasRule = (testRegex, loaderName) =>
128
- config.module.rules.some(
129
- (rule) =>
130
- rule &&
131
- rule.test &&
132
- String(rule.test) === String(testRegex) &&
133
- hasLoader(rule, loaderName),
134
- );
135
-
136
- const pushRuleOnce = (rule, loaderName) => {
137
- if (!hasRule(rule.test, loaderName)) {
138
- config.module.rules.push(rule);
139
- }
140
- };
141
-
142
- // Alias
143
- Object.assign(config.resolve.alias, resolves.TwigResolve.alias);
144
-
145
- // Twig loader
146
- pushRuleOnce(
147
- {
148
- /**
149
- * @type {RegExp}
150
- */
151
- test: /\.twig$/,
152
- use: [
153
- {
154
- /**
155
- * Custom loader for svg/spritemap integration.
156
- * @type {string}
157
- */
158
- loader: resolve(_dirname, '../config/webpack/sdc-loader.js'),
159
- options: {
160
- /**
161
- * Name of the Emulsify project for resolving.
162
- * @type {string}
163
- */
164
- projectName: emulsifyConfig.project.name,
165
- },
166
- },
167
- {
168
- /**
169
- * Standard Twig JS loader.
170
- * @type {string}
171
- */
172
- loader: 'twigjs-loader',
173
- },
174
- ],
175
- },
176
- 'twigjs-loader',
177
- );
178
-
179
- // SCSS Loader configuration
180
- pushRuleOnce(
181
- {
182
- test: /\.s[ac]ss$/i,
183
- use: [
184
- 'style-loader',
185
- {
186
- loader: 'css-loader',
187
- options: {
188
- /**
189
- * Enable source maps for CSS.
190
- * @type {boolean}
191
- */
192
- sourceMap: true,
193
- },
194
- },
195
- {
196
- loader: 'sass-loader',
197
- options: {
198
- sourceMap: true,
199
- sassOptions: {
200
- importer: globImporter(),
201
- },
202
- },
203
- },
204
- ],
205
- },
206
- 'sass-loader',
207
- );
208
-
209
- // YAML loader
210
- pushRuleOnce(
211
- {
212
- /**
213
- * @type {RegExp}
214
- */
215
- test: /\.ya?ml$/,
216
- loader: 'js-yaml-loader',
217
- },
218
- 'js-yaml-loader',
219
- );
220
-
221
- // Keep style linting in the Storybook webpack build. ESLint runs via the
222
- // dedicated npm scripts instead, which avoids coupling Storybook to a
223
- // specific ESLint major version.
224
- config.plugins.push(
225
- new _StyleLintPlugin({
226
- configFile: resolve(projectDir, '../', '.stylelintrc.json'),
227
- context: resolve(projectDir, '../', 'src'),
228
- files: '**/*.scss',
229
- failOnError: false,
230
- quiet: false,
231
- }),
232
- );
233
-
234
- // Custom resolver plugin for namespaced imports
235
- config.resolve.plugins = [
236
- new ProjectNameResolverPlugin({
237
- projectName: emulsifyConfig.project.name,
238
- }),
239
- ];
240
-
241
- // Merge fallbacks so we do not clobber Storybook defaults.
242
- config.resolve.fallback = {
243
- ...(config.resolve.fallback || {}),
244
- process: require.resolve('process/browser'),
245
- /**
246
- * Prevent resolution of components directory if missing.
247
- */
248
- '../../../../components': false,
249
- };
250
-
251
- // Provide global `process` for browser bundles that pull in node-style libs.
252
- const hasProcessProvidePlugin = config.plugins.some(
253
- (plugin) =>
254
- plugin &&
255
- plugin.constructor &&
256
- plugin.constructor.name === 'ProvidePlugin' &&
257
- plugin.definitions &&
258
- Object.prototype.hasOwnProperty.call(plugin.definitions, 'process'),
259
- );
260
- if (!hasProcessProvidePlugin) {
261
- config.plugins.push(
262
- new webpack.ProvidePlugin({
263
- process: 'process/browser',
264
- }),
265
- );
266
- }
267
-
268
- return config;
269
- }
@@ -1,56 +0,0 @@
1
- # Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
-
7
- We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
-
9
- ## Our Standards
10
-
11
- Examples of behavior that contributes to a positive environment for our community include:
12
-
13
- - Demonstrating empathy and kindness toward other people
14
- - Being respectful of differing opinions, viewpoints, and experiences
15
- - Giving and gracefully accepting constructive feedback
16
- - Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
- - Focusing on what is best not just for us as individuals, but for the overall community
18
-
19
- Examples of unacceptable behavior include:
20
-
21
- - The use of sexualized language or imagery, and sexual attention or
22
- advances of any kind
23
- - Trolling, insulting or derogatory comments, and personal or political attacks
24
- - Public or private harassment
25
- - Publishing others' private information, such as a physical or email
26
- address, without their explicit permission
27
- - Other conduct which could reasonably be considered inappropriate in a
28
- professional setting
29
-
30
- ## Enforcement Responsibilities
31
-
32
- Project maintainers are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
-
34
- Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
-
36
- ## Scope
37
-
38
- This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
-
40
- ## Enforcement
41
-
42
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the project maintainers responsible for enforcement at [howdy@fourkitchens.com](mailto:howdy@fourkitchens.com). All complaints will be reviewed and investigated promptly and fairly.
43
-
44
- All project maintainers are obligated to respect the privacy and security of the reporter of any incident.
45
-
46
- ## Attribution
47
-
48
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
49
- available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
50
-
51
- Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
52
-
53
- [homepage]: https://www.contributor-covenant.org
54
-
55
- For answers to common questions about this code of conduct, see the FAQ at
56
- https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
@@ -1,5 +0,0 @@
1
- const Configuration = {
2
- extends: ["@commitlint/config-conventional"],
3
- };
4
-
5
- export default Configuration;
@@ -1,19 +0,0 @@
1
- module.exports = {
2
- testEnvironment: 'jsdom',
3
- coverageDirectory: '.coverage',
4
- // @TODO: once every file has 100% test coverage,
5
- // these thresholds should be updated.
6
- coverageThreshold: {
7
- global: {
8
- branches: 0,
9
- functions: 0,
10
- lines: 0,
11
- statements: 0,
12
- },
13
- },
14
- testPathIgnorePatterns: [
15
- '<rootDir>/dist',
16
- '<rootDir>/vendor',
17
- '<rootDir>/.out',
18
- ],
19
- };
@@ -1 +0,0 @@
1
- // Empty (needed for webpack)
@@ -1,167 +0,0 @@
1
- /**
2
- * @fileoverview Webpack loader configurations for Emulsify Core and per-project overrides.
3
- *
4
- * This module exports a single default object containing loader definitions for:
5
- * - JavaScript (with Babel)
6
- * - Sass/CSS (with PostCSS + Autoprefixer or project overrides)
7
- * - Images
8
- * - SVG sprites
9
- * - Twig templates
10
- *
11
- * It will look for these override files in your project:
12
- * - ./config/emulsify-core/webpack/babel.config.cjs
13
- * - ./config/emulsify-core/webpack/postcss.config.cjs
14
- *
15
- * If not found, it falls back to the package defaults.
16
- */
17
-
18
- import { createRequire } from 'module';
19
- import MiniCssExtractPlugin from 'mini-css-extract-plugin';
20
- import globImporter from 'node-sass-glob-importer';
21
- import fs from 'fs-extra';
22
- import path from 'path';
23
-
24
- const require = createRequire(import.meta.url);
25
-
26
- /** @type {string} Path to the active Babel config file. */
27
- const babelConfig = fs.existsSync(
28
- './config/emulsify-core/webpack/babel.config.cjs',
29
- )
30
- ? './config/emulsify-core/webpack/babel.config.cjs'
31
- : require.resolve('@emulsify/core/config/babel.config.js');
32
-
33
- /** @type {string} Path to the active PostCSS config file. */
34
- const postcssConfigPath = fs.existsSync(
35
- './config/emulsify-core/webpack/postcss.config.cjs',
36
- )
37
- ? path.resolve('config/emulsify-core/webpack/postcss.config.cjs')
38
- : require.resolve('@emulsify/core/config/postcss.config.js');
39
-
40
- /**
41
- * Resolve the directory of this file (without fileURLToPath).
42
- * @type {string}
43
- */
44
- let _filename = decodeURIComponent(new URL(import.meta.url).pathname);
45
- if (process.platform === 'win32' && _filename.startsWith('/')) {
46
- _filename = _filename.slice(1);
47
- }
48
- const _dirname = path.dirname(_filename);
49
-
50
- /**
51
- * Root of the project (three levels up from this file).
52
- * @type {string}
53
- */
54
- const projectDir = path.resolve(_dirname, '../../../../..');
55
-
56
- /** Absolute path to the folder that contains sprite source icons. */
57
- const ICONS_DIR = path.resolve(projectDir, 'assets/icons');
58
-
59
- /**
60
- * @type {import('webpack').RuleSetRule}
61
- * JavaScript loader: transpile with Babel.
62
- */
63
- const JSLoader = {
64
- test: /^(?!.*\.(stories|component)\.js$).*\.js$/,
65
- exclude: /node_modules/,
66
- use: {
67
- loader: 'babel-loader',
68
- options: {
69
- configFile: babelConfig,
70
- },
71
- },
72
- };
73
-
74
- /**
75
- * @type {import('webpack').RuleSetRule}
76
- * CSS/Sass loader chain:
77
- * - extract to file
78
- * - css-loader (no URL rewriting)
79
- * - postcss-loader (project or default)
80
- * - sass-loader (with glob importer + compressed output)
81
- */
82
- const CSSLoader = {
83
- test: /\.s[ac]ss$/i,
84
- exclude: /node_modules/,
85
- use: [
86
- MiniCssExtractPlugin.loader,
87
- {
88
- loader: 'css-loader',
89
- options: {
90
- sourceMap: true,
91
- url: false,
92
- },
93
- },
94
- {
95
- loader: 'postcss-loader',
96
- options: {
97
- sourceMap: true,
98
- postcssOptions: {
99
- config: postcssConfigPath,
100
- },
101
- },
102
- },
103
- {
104
- loader: 'sass-loader',
105
- options: {
106
- api: 'legacy',
107
- sourceMap: true,
108
- implementation: require('sass'),
109
- webpackImporter: true,
110
- sassOptions: {
111
- importer: globImporter(),
112
- legacyImporter: true,
113
- outputStyle: 'compressed',
114
- silenceDeprecations: ['legacy-js-api'],
115
- quietDeps: true,
116
- },
117
- },
118
- },
119
- ],
120
- };
121
-
122
- /**
123
- * @type {import('webpack').RuleSetRule}
124
- * Image loader: inlines small assets, emits larger ones.
125
- */
126
- const ImageLoader = {
127
- test: /\.(png|jpe?g|gif)$/i,
128
- type: 'asset',
129
- };
130
-
131
- /**
132
- * @type {import('webpack').RuleSetRule}
133
- * General SVG loader for non-sprite SVGs (logos, illustrations, etc.).
134
- * IMPORTANT: Excludes `assets/icons/` so `svg-spritemap-webpack-plugin`
135
- * can consume those files without being intercepted by this rule.
136
- */
137
- const SVGLoader = {
138
- test: /icons\/.*\.svg$/,
139
- type: 'asset/resource',
140
- generator: {
141
- filename: 'icons.svg',
142
- },
143
- exclude: [ICONS_DIR],
144
- };
145
-
146
- /**
147
- * @type {import('webpack').RuleSetRule}
148
- * Twig.js loader for .twig templates.
149
- */
150
- const TwigLoader = {
151
- test: /\.twig$/,
152
- use: {
153
- loader: 'twigjs-loader',
154
- },
155
- };
156
-
157
- /**
158
- * Default export of all loader configurations.
159
- * @type {{ JSLoader: import('webpack').RuleSetRule, CSSLoader: import('webpack').RuleSetRule, ImageLoader: import('webpack').RuleSetRule, SVGSpriteLoader: import('webpack').RuleSetRule, TwigLoader: import('webpack').RuleSetRule }}
160
- */
161
- export default {
162
- JSLoader,
163
- CSSLoader,
164
- ImageLoader,
165
- SVGLoader,
166
- TwigLoader,
167
- };
@@ -1,26 +0,0 @@
1
- import ImageMinimizerPlugin from 'image-minimizer-webpack-plugin';
2
- import TerserPlugin from 'terser-webpack-plugin';
3
-
4
- const ImageMinimizer = new ImageMinimizerPlugin({
5
- minimizer: {
6
- implementation: ImageMinimizerPlugin.imageminMinify,
7
- options: {
8
- plugins: [
9
- ['jpegtran', { progressive: true }],
10
- ['optipng', { optimizationLevel: 5 }],
11
- ],
12
- },
13
- },
14
- });
15
-
16
- const TerserMinimizer = new TerserPlugin({
17
- terserOptions: {
18
- mangle: {
19
- reserved: ['Drupal', 'drupalSettings', 'once'],
20
- },
21
- },
22
- });
23
-
24
- export default {
25
- minimizer: [ImageMinimizer, TerserMinimizer],
26
- };