@modern-js/builder 2.22.0 → 2.22.1

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,35 @@
1
1
  # @modern-js/builder
2
2
 
3
+ ## 2.22.1
4
+
5
+ ### Patch Changes
6
+
7
+ - a470c04: chore(builder): reuse rem plugin between rspack and webpack provider
8
+
9
+ chore(builder): 在 rspack 和 webpack provider 间复用 rem 插件
10
+
11
+ - bd4b150: feat(builder): add builder.serve method
12
+
13
+ feat(builder): 新增 builder.serve 方法
14
+
15
+ - d4045ed: fix(builder): print https URLs when devServer.https is true
16
+
17
+ fix(builder): 当 devServer.https 为 true 时,输出 https 的 URLs
18
+
19
+ - Updated dependencies [e2848a2]
20
+ - Updated dependencies [a470c04]
21
+ - Updated dependencies [95ffa6b]
22
+ - Updated dependencies [12d54ae]
23
+ - Updated dependencies [bd4b150]
24
+ - Updated dependencies [dd36311]
25
+ - Updated dependencies [d4045ed]
26
+ - Updated dependencies [8bd9981]
27
+ - Updated dependencies [1f02cd2]
28
+ - Updated dependencies [cfcf003]
29
+ - Updated dependencies [15181be]
30
+ - @modern-js/utils@2.22.1
31
+ - @modern-js/builder-shared@2.22.1
32
+
3
33
  ## 2.22.0
4
34
 
5
35
  ### Patch Changes
@@ -6,7 +6,7 @@ const plugins_1 = require("./plugins");
6
6
  async function createBuilder(provider, options) {
7
7
  const builderOptions = (0, builder_shared_1.applyDefaultBuilderOptions)(options);
8
8
  const pluginStore = (0, builder_shared_1.createPluginStore)();
9
- const { build, pluginAPI, publicContext, initConfigs, inspectConfig, createCompiler, startDevServer, applyDefaultPlugins, } = await provider({
9
+ const { build, serve, pluginAPI, publicContext, initConfigs, inspectConfig, createCompiler, startDevServer, applyDefaultPlugins, } = await provider({
10
10
  pluginStore,
11
11
  builderOptions,
12
12
  plugins: plugins_1.plugins,
@@ -29,6 +29,7 @@ async function createBuilder(provider, options) {
29
29
  'getBuilderConfig',
30
30
  'getNormalizedConfig',
31
31
  ]),
32
+ serve,
32
33
  build,
33
34
  createCompiler,
34
35
  initConfigs,
@@ -206,15 +206,17 @@ const builderPluginHtml = () => ({
206
206
  }
207
207
  }
208
208
  });
209
- api.onBeforeStartDevServer(async () => {
209
+ const emitRouteJson = async () => {
210
210
  const { fs, ROUTE_SPEC_FILE } = await Promise.resolve().then(() => __importStar(require('@modern-js/utils')));
211
211
  const routeFilePath = path_1.default.join(api.context.distPath, ROUTE_SPEC_FILE);
212
- // generate a basic route.json for modern.js dev server
212
+ // generate a basic route.json for modern.js server
213
213
  // if the framework has already generate a route.json, do nothing
214
214
  if (!(await (0, builder_shared_1.isFileExists)(routeFilePath)) && routesInfo.length) {
215
215
  await fs.outputFile(routeFilePath, JSON.stringify({ routes: routesInfo }, null, 2));
216
216
  }
217
- });
217
+ };
218
+ api.onBeforeBuild(emitRouteJson);
219
+ api.onBeforeStartDevServer(emitRouteJson);
218
220
  (0, exports.applyInjectTags)(api);
219
221
  },
220
222
  });
@@ -48,4 +48,5 @@ exports.plugins = {
48
48
  arco: () => Promise.resolve().then(() => __importStar(require('./arco'))).then(m => m.builderPluginArco()),
49
49
  tsChecker: () => Promise.resolve().then(() => __importStar(require('./tsChecker'))).then(m => m.builderPluginTsChecker()),
50
50
  checkSyntax: () => Promise.resolve().then(() => __importStar(require('./checkSyntax'))).then(m => m.builderPluginCheckSyntax()),
51
+ rem: () => Promise.resolve().then(() => __importStar(require('./rem'))).then(m => m.builderPluginRem()),
51
52
  };
@@ -0,0 +1,2 @@
1
+ import { type DefaultBuilderPlugin } from '@modern-js/builder-shared';
2
+ export declare const builderPluginRem: () => DefaultBuilderPlugin;
@@ -0,0 +1,106 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.builderPluginRem = void 0;
30
+ const lodash_1 = __importDefault(require("@modern-js/utils/lodash"));
31
+ const builder_shared_1 = require("@modern-js/builder-shared");
32
+ const defaultOptions = {
33
+ enableRuntime: true,
34
+ rootFontSize: 50,
35
+ };
36
+ const builderPluginRem = () => ({
37
+ name: 'builder-plugin-rem',
38
+ pre: [
39
+ 'builder-plugin-css',
40
+ 'builder-plugin-less',
41
+ 'builder-plugin-sass',
42
+ 'builder-plugin-stylus',
43
+ ],
44
+ setup(api) {
45
+ api.modifyBundlerChain(async (chain, { CHAIN_ID, isServer, isWebWorker, HtmlPlugin }) => {
46
+ const config = api.getNormalizedConfig();
47
+ const { output: { convertToRem }, } = config;
48
+ if (!convertToRem || isServer || isWebWorker) {
49
+ return;
50
+ }
51
+ const userOptions = {
52
+ ...defaultOptions,
53
+ ...(typeof convertToRem === 'boolean' ? {} : convertToRem),
54
+ };
55
+ // handle css
56
+ const { default: PxToRemPlugin } = (await Promise.resolve(`${(0, builder_shared_1.getSharedPkgCompiledPath)('postcss-pxtorem')}`).then(s => __importStar(require(s))));
57
+ const applyRules = [
58
+ CHAIN_ID.RULE.CSS,
59
+ CHAIN_ID.RULE.LESS,
60
+ CHAIN_ID.RULE.SASS,
61
+ CHAIN_ID.RULE.STYLUS,
62
+ ];
63
+ const getPxToRemPlugin = () => PxToRemPlugin({
64
+ rootValue: userOptions.rootFontSize,
65
+ unitPrecision: 5,
66
+ propList: ['*'],
67
+ ...lodash_1.default.cloneDeep(userOptions.pxtorem || {}),
68
+ });
69
+ // Deep copy options to prevent unexpected behavior.
70
+ applyRules.forEach(name => {
71
+ chain.module.rules.has(name) &&
72
+ chain.module
73
+ .rule(name)
74
+ .use(CHAIN_ID.USE.POSTCSS)
75
+ .tap((options = {}) => {
76
+ var _a;
77
+ return ({
78
+ ...options,
79
+ postcssOptions: {
80
+ ...(options.postcssOptions || {}),
81
+ plugins: [
82
+ ...(((_a = options.postcssOptions) === null || _a === void 0 ? void 0 : _a.plugins) || []),
83
+ getPxToRemPlugin(),
84
+ ],
85
+ },
86
+ });
87
+ });
88
+ });
89
+ // handle runtime (html)
90
+ if (!userOptions.enableRuntime) {
91
+ return;
92
+ }
93
+ const entries = Object.keys(chain.entryPoints.entries() || {});
94
+ const distDir = (0, builder_shared_1.getDistPath)(config.output, 'js');
95
+ chain
96
+ .plugin(CHAIN_ID.PLUGIN.AUTO_SET_ROOT_SIZE)
97
+ .use(builder_shared_1.AutoSetRootFontSizePlugin, [
98
+ userOptions,
99
+ entries,
100
+ HtmlPlugin,
101
+ distDir,
102
+ ]);
103
+ });
104
+ },
105
+ });
106
+ exports.builderPluginRem = builderPluginRem;
@@ -44,7 +44,8 @@ function builderPluginStartUrl() {
44
44
  return;
45
45
  }
46
46
  const config = api.getNormalizedConfig();
47
- const { https, startUrl, beforeStartUrl } = config.dev;
47
+ const { startUrl, beforeStartUrl } = config.dev;
48
+ const { https } = api.context.devServer || {};
48
49
  if (!startUrl) {
49
50
  return;
50
51
  }
package/package.json CHANGED
@@ -18,7 +18,7 @@
18
18
  "engines": {
19
19
  "node": ">=14.0.0"
20
20
  },
21
- "version": "2.22.0",
21
+ "version": "2.22.1",
22
22
  "jsnext:source": "./src/index.ts",
23
23
  "types": "./dist/index.d.ts",
24
24
  "main": "./dist/index.js",
@@ -31,14 +31,14 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@svgr/webpack": "8.0.1",
34
- "@modern-js/builder-shared": "2.22.0",
35
- "@modern-js/utils": "2.22.0"
34
+ "@modern-js/builder-shared": "2.22.1",
35
+ "@modern-js/utils": "2.22.1"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/babel__core": "^7.20.0",
39
39
  "@types/node": "^14",
40
40
  "typescript": "^5",
41
- "@scripts/vitest-config": "2.22.0"
41
+ "@scripts/vitest-config": "2.22.1"
42
42
  },
43
43
  "publishConfig": {
44
44
  "registry": "https://registry.npmjs.org/",