@modern-js/builder 2.6.0 → 2.7.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,25 @@
1
1
  # @modern-js/builder
2
2
 
3
+ ## 2.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - dfece9dc1c: fix(builder): vendor library chunks include sources
8
+ fix(builder): 用户源码被划分到第三方库所在 Chunk
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies [206c806efa]
13
+ - Updated dependencies [0f15fc597c]
14
+ - Updated dependencies [5f899af53a]
15
+ - Updated dependencies [dcad887024]
16
+ - Updated dependencies [a4672f7c16]
17
+ - Updated dependencies [ebe0d2dd6e]
18
+ - Updated dependencies [7fff9020e1]
19
+ - Updated dependencies [84bfb439b8]
20
+ - @modern-js/builder-shared@2.7.0
21
+ - @modern-js/utils@2.7.0
22
+
3
23
  ## 2.6.0
4
24
 
5
25
  ### Patch Changes
@@ -11,6 +11,7 @@ export declare const plugins: {
11
11
  toml: () => Promise<import("@modern-js/builder-shared").DefaultBuilderPlugin>;
12
12
  svg: () => Promise<import("@modern-js/builder-shared").DefaultBuilderPlugin>;
13
13
  splitChunks: () => Promise<import("@modern-js/builder-shared").DefaultBuilderPlugin>;
14
+ inlineChunk: () => Promise<import("@modern-js/builder-shared").DefaultBuilderPlugin>;
14
15
  bundleAnalyzer: () => Promise<import("@modern-js/builder-shared").DefaultBuilderPlugin>;
15
16
  font: () => Promise<import("@modern-js/builder-shared").DefaultBuilderPlugin>;
16
17
  image: () => Promise<import("@modern-js/builder-shared").DefaultBuilderPlugin>;
@@ -38,6 +38,7 @@ exports.plugins = {
38
38
  toml: () => Promise.resolve().then(() => __importStar(require('./toml'))).then(m => m.builderPluginToml()),
39
39
  svg: () => Promise.resolve().then(() => __importStar(require('./svg'))).then(m => m.builderPluginSvg()),
40
40
  splitChunks: () => Promise.resolve().then(() => __importStar(require('./splitChunks'))).then(m => m.builderPluginSplitChunks()),
41
+ inlineChunk: () => Promise.resolve().then(() => __importStar(require('./inlineChunk'))).then(m => m.builderPluginInlineChunk()),
41
42
  bundleAnalyzer: () => Promise.resolve().then(() => __importStar(require('./bundleAnalyzer'))).then(m => m.builderPluginBundleAnalyzer()),
42
43
  font: () => Promise.resolve().then(() => __importStar(require('./asset'))).then(m => m.builderAssetPlugin('font', builder_shared_1.FONT_EXTENSIONS)),
43
44
  image: () => Promise.resolve().then(() => __importStar(require('./asset'))).then(m => m.builderAssetPlugin('image', builder_shared_1.IMAGE_EXTENSIONS)),
@@ -0,0 +1,2 @@
1
+ import { DefaultBuilderPlugin } from '@modern-js/builder-shared';
2
+ export declare const builderPluginInlineChunk: () => DefaultBuilderPlugin;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.builderPluginInlineChunk = void 0;
27
+ const builder_shared_1 = require("@modern-js/builder-shared");
28
+ const builderPluginInlineChunk = () => ({
29
+ name: 'builder-plugin-inline-chunk',
30
+ setup(api) {
31
+ api.modifyBundlerChain(async (chain, { target, CHAIN_ID, isProd, HtmlPlugin }) => {
32
+ const config = api.getNormalizedConfig();
33
+ if ((0, builder_shared_1.isHtmlDisabled)(config, target) || !isProd) {
34
+ return;
35
+ }
36
+ const { InlineChunkHtmlPlugin } = await Promise.resolve().then(() => __importStar(require('@modern-js/builder-shared')));
37
+ const { disableInlineRuntimeChunk, enableInlineStyles,
38
+ // todo: not support enableInlineScripts in rspack yet, which will take unknown build error
39
+ enableInlineScripts, } = config.output;
40
+ chain.plugin(CHAIN_ID.PLUGIN.INLINE_HTML).use(InlineChunkHtmlPlugin, [
41
+ HtmlPlugin,
42
+ {
43
+ tests: [
44
+ enableInlineScripts && /\.js$/,
45
+ enableInlineStyles && /\.css$/,
46
+ !disableInlineRuntimeChunk &&
47
+ // RegExp like /builder-runtime([.].+)?\.js$/
48
+ // matches builder-runtime.js and builder-runtime.123456.js
49
+ new RegExp(`${builder_shared_1.RUNTIME_CHUNK_NAME}([.].+)?\\.js$`),
50
+ ].filter(Boolean),
51
+ distPath: (0, builder_shared_1.pick)(config.output.distPath, ['js', 'css']),
52
+ },
53
+ ]);
54
+ });
55
+ },
56
+ });
57
+ exports.builderPluginInlineChunk = builderPluginInlineChunk;
@@ -1,2 +1,4 @@
1
1
  import { DefaultBuilderPlugin } from '@modern-js/builder-shared';
2
+ /** Expect to match path just like "./node_modules/react-router/" */
3
+ export declare const createDependenciesRegExp: (...dependencies: string[]) => RegExp;
2
4
  export declare function builderPluginSplitChunks(): DefaultBuilderPlugin;
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.builderPluginSplitChunks = void 0;
29
+ exports.builderPluginSplitChunks = exports.createDependenciesRegExp = void 0;
30
30
  const assert_1 = __importDefault(require("assert"));
31
31
  const builder_shared_1 = require("@modern-js/builder-shared");
32
32
  function getUserDefinedCacheGroups(forceSplitting) {
@@ -43,28 +43,31 @@ function getUserDefinedCacheGroups(forceSplitting) {
43
43
  });
44
44
  return cacheGroups;
45
45
  }
46
+ /** Expect to match path just like "./node_modules/react-router/" */
47
+ const createDependenciesRegExp = (...dependencies) => new RegExp(`[\\\\/]node_modules[\\\\/](${dependencies.join('|')})[\\\\/]`);
48
+ exports.createDependenciesRegExp = createDependenciesRegExp;
46
49
  async function splitByExperience(ctx) {
47
50
  const { isPackageInstalled } = await Promise.resolve().then(() => __importStar(require('@modern-js/utils')));
48
51
  const { override, polyfill, rootPath, defaultConfig, userDefinedCacheGroups, } = ctx;
49
52
  const experienceCacheGroup = {};
50
53
  const packageRegExps = {
51
- react: /[\\/]react|react-dom[\\/]/,
52
- router: /[\\/]react-router|react-router-dom|history[\\/]/,
53
- lodash: /[\\/]lodash|lodash-es[\\/]/,
54
+ react: (0, exports.createDependenciesRegExp)('react', 'react-dom'),
55
+ router: (0, exports.createDependenciesRegExp)('react-router', 'react-router-dom', 'history'),
56
+ lodash: (0, exports.createDependenciesRegExp)('lodash', 'lodash-es'),
54
57
  };
55
58
  // Detect if the package is installed in current project
56
59
  // If installed, add the package to cache group
57
60
  if (isPackageInstalled('antd', rootPath)) {
58
- packageRegExps.antd = /[\\/]antd[\\/]/;
61
+ packageRegExps.antd = (0, exports.createDependenciesRegExp)('antd');
59
62
  }
60
63
  if (isPackageInstalled('@arco-design/web-react', rootPath)) {
61
- packageRegExps.arco = /[\\/]arco-design[\\/]/;
64
+ packageRegExps.arco = (0, exports.createDependenciesRegExp)('arco-design');
62
65
  }
63
66
  if (isPackageInstalled('@douyinfe/semi-ui', rootPath)) {
64
- packageRegExps.semi = /[\\/]semi-ui[\\/]/;
67
+ packageRegExps.semi = (0, exports.createDependenciesRegExp)('semi-ui');
65
68
  }
66
69
  if (polyfill === 'entry' || polyfill === 'usage') {
67
- packageRegExps.polyfill = /[\\/]core-js|@babel\/runtime[\\/]/;
70
+ packageRegExps.polyfill = (0, exports.createDependenciesRegExp)('core-js', '@babel/runtime');
68
71
  }
69
72
  Object.entries(packageRegExps).forEach(([name, test]) => {
70
73
  const key = `lib-${name}`;
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "engines": {
15
15
  "node": ">=14.0.0"
16
16
  },
17
- "version": "2.6.0",
17
+ "version": "2.7.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.6.0",
31
- "@modern-js/utils": "2.6.0"
30
+ "@modern-js/builder-shared": "2.7.0",
31
+ "@modern-js/utils": "2.7.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.6.0"
39
+ "@scripts/vitest-config": "2.7.0"
40
40
  },
41
41
  "publishConfig": {
42
42
  "registry": "https://registry.npmjs.org/",