@modern-js/builder 2.1.0 → 2.2.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,22 @@
1
1
  # @modern-js/builder
2
2
 
3
+ ## 2.2.0
4
+
5
+ ### Patch Changes
6
+
7
+ - d82b621: feat(builder): support port placeholder in dev.startUrl config
8
+
9
+ feat(builder): 支持在 dev.startUrl 配置项中使用端口号占位符
10
+
11
+ - 16bdc0a: chore: adjust builder plugin name
12
+
13
+ chore: 调整 builder 插件命名格式
14
+
15
+ - Updated dependencies [f2f8a83]
16
+ - Updated dependencies [49eff0c]
17
+ - @modern-js/builder-shared@2.2.0
18
+ - @modern-js/utils@2.2.0
19
+
3
20
  ## 2.1.0
4
21
 
5
22
  ### Patch Changes
@@ -1,2 +1,2 @@
1
1
  import { DefaultBuilderPlugin } from '@modern-js/builder-shared';
2
- export declare const PluginCache: () => DefaultBuilderPlugin;
2
+ export declare const builderPluginCache: () => DefaultBuilderPlugin;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.PluginCache = void 0;
26
+ exports.builderPluginCache = void 0;
27
27
  const path_1 = require("path");
28
28
  const builder_shared_1 = require("@modern-js/builder-shared");
29
29
  async function validateCache(cacheDirectory, buildDependencies) {
@@ -51,7 +51,7 @@ function getCacheDirectory({ cacheDirectory }, context) {
51
51
  }
52
52
  return (0, path_1.join)(context.cachePath, context.bundlerType);
53
53
  }
54
- const PluginCache = () => ({
54
+ const builderPluginCache = () => ({
55
55
  name: 'builder-plugin-cache',
56
56
  setup(api) {
57
57
  api.modifyBundlerChain(async (chain, { target, env }) => {
@@ -93,4 +93,4 @@ const PluginCache = () => ({
93
93
  });
94
94
  },
95
95
  });
96
- exports.PluginCache = PluginCache;
96
+ exports.builderPluginCache = builderPluginCache;
@@ -1,2 +1,2 @@
1
1
  import type { DefaultBuilderPlugin } from '@modern-js/builder-shared';
2
- export declare const PluginCleanOutput: () => DefaultBuilderPlugin;
2
+ export declare const builderPluginCleanOutput: () => DefaultBuilderPlugin;
@@ -23,8 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.PluginCleanOutput = void 0;
27
- const PluginCleanOutput = () => ({
26
+ exports.builderPluginCleanOutput = void 0;
27
+ const builderPluginCleanOutput = () => ({
28
28
  name: 'builder-plugin-clean-output',
29
29
  setup(api) {
30
30
  const clean = async () => {
@@ -39,4 +39,4 @@ const PluginCleanOutput = () => ({
39
39
  api.onBeforeStartDevServer(clean);
40
40
  },
41
41
  });
42
- exports.PluginCleanOutput = PluginCleanOutput;
42
+ exports.builderPluginCleanOutput = builderPluginCleanOutput;
@@ -1,2 +1,2 @@
1
1
  import { DefaultBuilderPlugin } from '@modern-js/builder-shared';
2
- export declare const PluginDevtool: () => DefaultBuilderPlugin;
2
+ export declare const builderPluginDevtool: () => DefaultBuilderPlugin;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PluginDevtool = void 0;
3
+ exports.builderPluginDevtool = void 0;
4
4
  const builder_shared_1 = require("@modern-js/builder-shared");
5
- const PluginDevtool = () => ({
5
+ const builderPluginDevtool = () => ({
6
6
  name: 'builder-plugin-devtool',
7
7
  setup(api) {
8
8
  api.modifyBundlerChain((chain, { isProd }) => {
@@ -20,4 +20,4 @@ const PluginDevtool = () => ({
20
20
  });
21
21
  },
22
22
  });
23
- exports.PluginDevtool = PluginDevtool;
23
+ exports.builderPluginDevtool = builderPluginDevtool;
@@ -1,2 +1,2 @@
1
1
  import { DefaultBuilderPlugin } from '@modern-js/builder-shared';
2
- export declare const PluginEntry: () => DefaultBuilderPlugin;
2
+ export declare const builderPluginEntry: () => DefaultBuilderPlugin;
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.PluginEntry = void 0;
6
+ exports.builderPluginEntry = void 0;
7
7
  const lodash_1 = __importDefault(require("@modern-js/utils/lodash"));
8
- const PluginEntry = () => ({
8
+ const builderPluginEntry = () => ({
9
9
  name: 'builder-plugin-entry',
10
10
  setup(api) {
11
11
  api.modifyBundlerChain(async (chain) => {
@@ -19,4 +19,4 @@ const PluginEntry = () => ({
19
19
  });
20
20
  },
21
21
  });
22
- exports.PluginEntry = PluginEntry;
22
+ exports.builderPluginEntry = builderPluginEntry;
@@ -1,4 +1,4 @@
1
1
  import type { DefaultBuilderPlugin } from '@modern-js/builder-shared';
2
2
  /** Filter source map files */
3
3
  export declare const filterAsset: (asset: string) => boolean;
4
- export declare const PluginFileSize: () => DefaultBuilderPlugin;
4
+ export declare const builderPluginFileSize: () => 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.PluginFileSize = exports.filterAsset = void 0;
29
+ exports.builderPluginFileSize = exports.filterAsset = void 0;
30
30
  /**
31
31
  * modified from https://github.com/facebook/create-react-app
32
32
  * license at https://github.com/facebook/create-react-app/blob/master/LICENSE
@@ -116,7 +116,7 @@ async function printFileSizes(stats, distPath) {
116
116
  });
117
117
  builder_shared_1.logger.log('');
118
118
  }
119
- const PluginFileSize = () => ({
119
+ const builderPluginFileSize = () => ({
120
120
  name: 'builder-plugin-file-size',
121
121
  setup(api) {
122
122
  api.onAfterBuild(async ({ stats }) => {
@@ -127,4 +127,4 @@ const PluginFileSize = () => ({
127
127
  });
128
128
  },
129
129
  });
130
- exports.PluginFileSize = PluginFileSize;
130
+ exports.builderPluginFileSize = builderPluginFileSize;
@@ -25,13 +25,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.plugins = void 0;
27
27
  exports.plugins = {
28
- cleanOutput: () => Promise.resolve().then(() => __importStar(require('./cleanOutput'))).then(m => m.PluginCleanOutput()),
29
- startUrl: () => Promise.resolve().then(() => __importStar(require('./startUrl'))).then(m => m.PluginStartUrl()),
30
- fileSize: () => Promise.resolve().then(() => __importStar(require('./fileSize'))).then(m => m.PluginFileSize()),
31
- devtool: () => Promise.resolve().then(() => __importStar(require('./devtool'))).then(m => m.PluginDevtool()),
32
- target: () => Promise.resolve().then(() => __importStar(require('./target'))).then(m => m.PluginTarget()),
33
- entry: () => Promise.resolve().then(() => __importStar(require('./entry'))).then(m => m.PluginEntry()),
34
- cache: () => Promise.resolve().then(() => __importStar(require('./cache'))).then(m => m.PluginCache()),
35
- yaml: () => Promise.resolve().then(() => __importStar(require('./yaml'))).then(m => m.PluginYaml()),
36
- toml: () => Promise.resolve().then(() => __importStar(require('./toml'))).then(m => m.PluginToml()),
28
+ cleanOutput: () => Promise.resolve().then(() => __importStar(require('./cleanOutput'))).then(m => m.builderPluginCleanOutput()),
29
+ startUrl: () => Promise.resolve().then(() => __importStar(require('./startUrl'))).then(m => m.builderPluginStartUrl()),
30
+ fileSize: () => Promise.resolve().then(() => __importStar(require('./fileSize'))).then(m => m.builderPluginFileSize()),
31
+ devtool: () => Promise.resolve().then(() => __importStar(require('./devtool'))).then(m => m.builderPluginDevtool()),
32
+ target: () => Promise.resolve().then(() => __importStar(require('./target'))).then(m => m.builderPluginTarget()),
33
+ entry: () => Promise.resolve().then(() => __importStar(require('./entry'))).then(m => m.builderPluginEntry()),
34
+ cache: () => Promise.resolve().then(() => __importStar(require('./cache'))).then(m => m.builderPluginCache()),
35
+ yaml: () => Promise.resolve().then(() => __importStar(require('./yaml'))).then(m => m.builderPluginYaml()),
36
+ toml: () => Promise.resolve().then(() => __importStar(require('./toml'))).then(m => m.builderPluginToml()),
37
37
  };
@@ -1,2 +1,3 @@
1
1
  import type { DefaultBuilderPlugin } from '@modern-js/builder-shared';
2
- export declare function PluginStartUrl(): DefaultBuilderPlugin;
2
+ export declare const replacePlaceholder: (url: string, port: number) => string;
3
+ export declare function builderPluginStartUrl(): DefaultBuilderPlugin;
@@ -26,9 +26,11 @@ 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.PluginStartUrl = void 0;
29
+ exports.builderPluginStartUrl = exports.replacePlaceholder = void 0;
30
30
  const lodash_1 = __importDefault(require("@modern-js/utils/lodash"));
31
- function PluginStartUrl() {
31
+ const replacePlaceholder = (url, port) => url.replace(/<port>/g, String(port));
32
+ exports.replacePlaceholder = replacePlaceholder;
33
+ function builderPluginStartUrl() {
32
34
  return {
33
35
  name: 'builder-plugin-start-url',
34
36
  async setup(api) {
@@ -41,24 +43,24 @@ function PluginStartUrl() {
41
43
  return;
42
44
  }
43
45
  const config = api.getNormalizedConfig();
44
- const { startUrl } = config.dev;
46
+ const { https, startUrl } = config.dev;
45
47
  if (!startUrl) {
46
48
  return;
47
49
  }
48
- const { default: open } = await Promise.resolve().then(() => __importStar(require('@modern-js/builder-shared/open')));
49
50
  const urls = [];
50
51
  if (startUrl === true) {
51
- const protocol = config.dev.https ? 'https' : 'http';
52
+ const protocol = https ? 'https' : 'http';
52
53
  urls.push(`${protocol}://localhost:${port}`);
53
54
  }
54
55
  else {
55
- urls.push(...lodash_1.default.castArray(startUrl));
56
+ urls.push(...lodash_1.default.castArray(startUrl).map(item => (0, exports.replacePlaceholder)(item, port)));
56
57
  }
58
+ const { openBrowser } = await Promise.resolve().then(() => __importStar(require('@modern-js/builder-shared')));
57
59
  for (const url of urls) {
58
- await open(url);
60
+ await openBrowser(url);
59
61
  }
60
62
  });
61
63
  },
62
64
  };
63
65
  }
64
- exports.PluginStartUrl = PluginStartUrl;
66
+ exports.builderPluginStartUrl = builderPluginStartUrl;
@@ -1,2 +1,2 @@
1
1
  import type { DefaultBuilderPlugin } from '@modern-js/builder-shared';
2
- export declare const PluginTarget: () => DefaultBuilderPlugin;
2
+ export declare const builderPluginTarget: () => DefaultBuilderPlugin;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PluginTarget = void 0;
3
+ exports.builderPluginTarget = void 0;
4
4
  const builder_shared_1 = require("@modern-js/builder-shared");
5
- const PluginTarget = () => ({
5
+ const builderPluginTarget = () => ({
6
6
  name: 'builder-plugin-target',
7
7
  setup(api) {
8
8
  api.modifyBundlerChain(async (chain, { target }) => {
@@ -24,4 +24,4 @@ const PluginTarget = () => ({
24
24
  });
25
25
  },
26
26
  });
27
- exports.PluginTarget = PluginTarget;
27
+ exports.builderPluginTarget = builderPluginTarget;
@@ -1,2 +1,2 @@
1
1
  import type { DefaultBuilderPlugin } from '@modern-js/builder-shared';
2
- export declare const PluginToml: () => DefaultBuilderPlugin;
2
+ export declare const builderPluginToml: () => DefaultBuilderPlugin;
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.PluginToml = void 0;
6
+ exports.builderPluginToml = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
- const PluginToml = () => ({
8
+ const builderPluginToml = () => ({
9
9
  name: 'builder-plugin-toml',
10
10
  setup(api) {
11
11
  api.modifyBundlerChain((chain, { CHAIN_ID }) => {
@@ -18,4 +18,4 @@ const PluginToml = () => ({
18
18
  });
19
19
  },
20
20
  });
21
- exports.PluginToml = PluginToml;
21
+ exports.builderPluginToml = builderPluginToml;
@@ -1,2 +1,2 @@
1
1
  import type { DefaultBuilderPlugin } from '@modern-js/builder-shared';
2
- export declare const PluginYaml: () => DefaultBuilderPlugin;
2
+ export declare const builderPluginYaml: () => DefaultBuilderPlugin;
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.PluginYaml = void 0;
6
+ exports.builderPluginYaml = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
- const PluginYaml = () => ({
8
+ const builderPluginYaml = () => ({
9
9
  name: 'builder-plugin-yaml',
10
10
  setup(api) {
11
11
  api.modifyBundlerChain((chain, { CHAIN_ID }) => {
@@ -18,4 +18,4 @@ const PluginYaml = () => ({
18
18
  });
19
19
  },
20
20
  });
21
- exports.PluginYaml = PluginYaml;
21
+ exports.builderPluginYaml = builderPluginYaml;
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "engines": {
15
15
  "node": ">=14.0.0"
16
16
  },
17
- "version": "2.1.0",
17
+ "version": "2.2.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
  },
29
29
  "dependencies": {
30
- "@modern-js/builder-shared": "2.1.0",
31
- "@modern-js/utils": "2.1.0"
30
+ "@modern-js/builder-shared": "2.2.0",
31
+ "@modern-js/utils": "2.2.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.1.0"
39
+ "@scripts/vitest-config": "2.2.0"
40
40
  },
41
41
  "publishConfig": {
42
42
  "registry": "https://registry.npmjs.org/",