@modern-js/builder 2.7.0 → 2.9.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # @modern-js/builder
2
2
 
3
+ ## 2.9.0
4
+
5
+ ### Patch Changes
6
+
7
+ - f31a254d78: feat: improve vendor split chunk rule
8
+ feat: 优化针对第三方库的拆包策略
9
+ - 1f047183c3: feat: enable svgo to avoid ID conflicts
10
+ feat: 启用 svgo 以避免 ID 冲突
11
+ - da66232feb: fix: asset url using incorrect path seperator in windows
12
+
13
+ fix: 修复 windows 中 asset url 使用错误的路径分隔符
14
+
15
+ - @modern-js/builder-shared@2.9.0
16
+ - @modern-js/utils@2.9.0
17
+
18
+ ## 2.8.0
19
+
20
+ ### Patch Changes
21
+
22
+ - bd369a89a4: fix(builder): failed to set CDN URL via html.tags
23
+
24
+ fix(builder): 修复 html.tags 无法设置 CDN URL 的问题
25
+
26
+ - Updated dependencies [bd369a89a4]
27
+ - Updated dependencies [1104a9f18b]
28
+ - Updated dependencies [2c1151271d]
29
+ - Updated dependencies [481461a61d]
30
+ - Updated dependencies [1f6ca2c7fb]
31
+ - @modern-js/builder-shared@2.8.0
32
+ - @modern-js/utils@2.8.0
33
+
3
34
  ## 2.7.0
4
35
 
5
36
  ### Minor Changes
package/README.md CHANGED
@@ -5,12 +5,12 @@
5
5
  <p align="center">
6
6
  Modern.js Builder
7
7
  <br/>
8
- <a href="https://modernjs.dev/builder" target="blank">
8
+ <a href="https://modernjs.dev/builder/en" target="blank">
9
9
  modernjs.dev/builder
10
10
  </a>
11
11
  </p>
12
12
  <p align="center">
13
- A Build Engine for web development.
13
+ A build engine for web development.
14
14
  </p>
15
15
 
16
16
  # @modern-js/builder
@@ -24,4 +24,4 @@ This is the core package of Modern.js Builder.
24
24
 
25
25
  ## Contributing
26
26
 
27
- - [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)
27
+ - [Contributing Guide](https://github.com/web-infra-dev/modern.js/blob/main/CONTRIBUTING.md)
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.builderAssetPlugin = void 0;
4
- const path_1 = require("path");
7
+ const path_1 = __importDefault(require("path"));
5
8
  const builder_shared_1 = require("@modern-js/builder-shared");
6
9
  const builderAssetPlugin = (assetType, exts) => ({
7
10
  name: `builder-plugin-${assetType}`,
@@ -16,7 +19,7 @@ const builderAssetPlugin = (assetType, exts) => ({
16
19
  (0, builder_shared_1.chainStaticAssetRule)({
17
20
  rule,
18
21
  maxSize,
19
- filename: (0, path_1.join)(distDir, filename),
22
+ filename: path_1.default.posix.join(distDir, filename),
20
23
  assetType,
21
24
  });
22
25
  });
@@ -66,8 +66,6 @@ async function getChunks(entryName, entryValue) {
66
66
  }
67
67
  return [...dependOn, entryName];
68
68
  }
69
- // Determine if the string is a favicon url
70
- const isFaviconUrl = (str) => str.startsWith('http');
71
69
  const applyInjectTags = (api) => {
72
70
  api.modifyBundlerChain(async (chain, { HtmlPlugin, CHAIN_ID }) => {
73
71
  const config = api.getNormalizedConfig();
@@ -141,7 +139,7 @@ const builderPluginHtml = () => ({
141
139
  templateParameters,
142
140
  };
143
141
  if (favicon) {
144
- if (isFaviconUrl(favicon)) {
142
+ if ((0, builder_shared_1.isURL)(favicon)) {
145
143
  faviconUrls.push({
146
144
  filename,
147
145
  url: favicon,
@@ -35,7 +35,7 @@ const builderPluginInlineChunk = () => ({
35
35
  }
36
36
  const { InlineChunkHtmlPlugin } = await Promise.resolve().then(() => __importStar(require('@modern-js/builder-shared')));
37
37
  const { disableInlineRuntimeChunk, enableInlineStyles,
38
- // todo: not support enableInlineScripts in rspack yet, which will take unknown build error
38
+ // todo: not support enableInlineScripts in Rspack yet, which will take unknown build error
39
39
  enableInlineScripts, } = config.output;
40
40
  chain.plugin(CHAIN_ID.PLUGIN.INLINE_HTML).use(InlineChunkHtmlPlugin, [
41
41
  HtmlPlugin,
@@ -1,4 +1,4 @@
1
1
  import { DefaultBuilderPlugin } from '@modern-js/builder-shared';
2
2
  /** Expect to match path just like "./node_modules/react-router/" */
3
- export declare const createDependenciesRegExp: (...dependencies: string[]) => RegExp;
3
+ export declare const createDependenciesRegExp: (...dependencies: (string | RegExp)[]) => RegExp;
4
4
  export declare function builderPluginSplitChunks(): DefaultBuilderPlugin;
@@ -43,8 +43,13 @@ function getUserDefinedCacheGroups(forceSplitting) {
43
43
  });
44
44
  return cacheGroups;
45
45
  }
46
+ const DEPENDENCY_MATCH_TEMPL = /[\\/]node_modules[\\/](<SOURCES>)[\\/]/.source;
46
47
  /** Expect to match path just like "./node_modules/react-router/" */
47
- const createDependenciesRegExp = (...dependencies) => new RegExp(`[\\\\/]node_modules[\\\\/](${dependencies.join('|')})[\\\\/]`);
48
+ const createDependenciesRegExp = (...dependencies) => {
49
+ const sources = dependencies.map(d => (typeof d === 'string' ? d : d.source));
50
+ const expr = DEPENDENCY_MATCH_TEMPL.replace('<SOURCES>', sources.join('|'));
51
+ return new RegExp(expr);
52
+ };
48
53
  exports.createDependenciesRegExp = createDependenciesRegExp;
49
54
  async function splitByExperience(ctx) {
50
55
  const { isPackageInstalled } = await Promise.resolve().then(() => __importStar(require('@modern-js/utils')));
@@ -52,7 +57,7 @@ async function splitByExperience(ctx) {
52
57
  const experienceCacheGroup = {};
53
58
  const packageRegExps = {
54
59
  react: (0, exports.createDependenciesRegExp)('react', 'react-dom'),
55
- router: (0, exports.createDependenciesRegExp)('react-router', 'react-router-dom', 'history'),
60
+ router: (0, exports.createDependenciesRegExp)('react-router', 'react-router-dom', '@remix-run/router', 'history'),
56
61
  lodash: (0, exports.createDependenciesRegExp)('lodash', 'lodash-es'),
57
62
  };
58
63
  // Detect if the package is installed in current project
@@ -61,13 +66,13 @@ async function splitByExperience(ctx) {
61
66
  packageRegExps.antd = (0, exports.createDependenciesRegExp)('antd');
62
67
  }
63
68
  if (isPackageInstalled('@arco-design/web-react', rootPath)) {
64
- packageRegExps.arco = (0, exports.createDependenciesRegExp)('arco-design');
69
+ packageRegExps.arco = (0, exports.createDependenciesRegExp)(/@?arco-design/);
65
70
  }
66
71
  if (isPackageInstalled('@douyinfe/semi-ui', rootPath)) {
67
- packageRegExps.semi = (0, exports.createDependenciesRegExp)('semi-ui');
72
+ packageRegExps.semi = (0, exports.createDependenciesRegExp)(/@(ies|douyinfe)[\\/]semi-.*/);
68
73
  }
69
74
  if (polyfill === 'entry' || polyfill === 'usage') {
70
- packageRegExps.polyfill = (0, exports.createDependenciesRegExp)('core-js', '@babel/runtime');
75
+ packageRegExps.polyfill = (0, exports.createDependenciesRegExp)('core-js', '@babel/runtime', '@swc/helpers');
71
76
  }
72
77
  Object.entries(packageRegExps).forEach(([name, test]) => {
73
78
  const key = `lib-${name}`;
@@ -1,9 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.builderPluginSvg = exports.getCompiledPath = void 0;
4
- const path_1 = require("path");
7
+ const path_1 = __importDefault(require("path"));
5
8
  const builder_shared_1 = require("@modern-js/builder-shared");
6
- const getCompiledPath = (packageName) => (0, path_1.join)(__dirname, '../../compiled', packageName);
9
+ const getCompiledPath = (packageName) => path_1.default.join(__dirname, '../../compiled', packageName);
7
10
  exports.getCompiledPath = getCompiledPath;
8
11
  const builderPluginSvg = () => {
9
12
  return {
@@ -15,14 +18,14 @@ const builderPluginSvg = () => {
15
18
  const assetType = 'svg';
16
19
  const distDir = (0, builder_shared_1.getDistPath)(config.output, 'svg');
17
20
  const filename = (0, builder_shared_1.getFilename)(config.output, 'svg', isProd);
18
- const outputName = (0, path_1.join)(distDir, filename);
21
+ const outputName = path_1.default.posix.join(distDir, filename);
19
22
  const maxSize = config.output.dataUriLimit[assetType];
20
23
  const rule = chain.module.rule(CHAIN_ID.RULE.SVG).test(builder_shared_1.SVG_REGEX);
21
24
  // If we import SVG from a CSS file, it will be processed as assets.
22
25
  (0, builder_shared_1.chainStaticAssetRule)({
23
26
  rule,
24
27
  maxSize,
25
- filename: (0, path_1.join)(distDir, filename),
28
+ filename: path_1.default.posix.join(distDir, filename),
26
29
  assetType,
27
30
  issuer: {
28
31
  // The issuer option ensures that SVGR will only apply if the SVG is imported from a JS file.
@@ -54,7 +57,7 @@ const builderPluginSvg = () => {
54
57
  .type('javascript/auto')
55
58
  .use(CHAIN_ID.USE.SVGR)
56
59
  .loader(require.resolve('@svgr/webpack'))
57
- .options({ svgo: false })
60
+ .options({ svgo: true })
58
61
  .end()
59
62
  .when(defaultExport === 'url', c => c
60
63
  .use(CHAIN_ID.USE.URL)
package/package.json CHANGED
@@ -2,8 +2,8 @@
2
2
  "name": "@modern-js/builder",
3
3
  "description": "Builder of modern.js.",
4
4
  "homepage": "https://modernjs.dev",
5
- "bugs": "https://github.com/modern-js-dev/modern.js/issues",
6
- "repository": "modern-js-dev/modern.js",
5
+ "bugs": "https://github.com/web-infra-dev/modern.js/issues",
6
+ "repository": "web-infra-dev/modern.js",
7
7
  "license": "MIT",
8
8
  "keywords": [
9
9
  "react",
@@ -14,7 +14,7 @@
14
14
  "engines": {
15
15
  "node": ">=14.0.0"
16
16
  },
17
- "version": "2.7.0",
17
+ "version": "2.9.0",
18
18
  "jsnext:source": "./src/index.ts",
19
19
  "types": "./dist/index.d.ts",
20
20
  "main": "./dist/index.js",
@@ -27,8 +27,8 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@svgr/webpack": "6.5.1",
30
- "@modern-js/builder-shared": "2.7.0",
31
- "@modern-js/utils": "2.7.0"
30
+ "@modern-js/builder-shared": "2.9.0",
31
+ "@modern-js/utils": "2.9.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@babel/core": "7.18.0",
@@ -36,7 +36,7 @@
36
36
  "@types/babel__preset-env": "^7.9.2",
37
37
  "@types/node": "^14",
38
38
  "typescript": "^4",
39
- "@scripts/vitest-config": "2.7.0"
39
+ "@scripts/vitest-config": "2.9.0"
40
40
  },
41
41
  "publishConfig": {
42
42
  "registry": "https://registry.npmjs.org/",