@modern-js/rsbuild-plugin-esbuild 2.54.6 → 2.55.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 (2) hide show
  1. package/dist/index.js +45 -3
  2. package/package.json +2 -3
package/dist/index.js CHANGED
@@ -32,8 +32,50 @@ __export(src_exports, {
32
32
  });
33
33
  module.exports = __toCommonJS(src_exports);
34
34
  var import_path = __toESM(require("path"));
35
- var import_shared = require("@rsbuild/shared");
35
+ const JS_REGEX = /\.(?:js|mjs|cjs|jsx)$/;
36
36
  const TS_REGEX = /\.(?:ts|mts|cts|tsx)$/;
37
+ const NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/;
38
+ const castArray = (arr) => {
39
+ if (arr === void 0) {
40
+ return [];
41
+ }
42
+ return Array.isArray(arr) ? arr : [
43
+ arr
44
+ ];
45
+ };
46
+ function applyScriptCondition({ rule, chain, config, context, includes, excludes }) {
47
+ rule.include.add({
48
+ and: [
49
+ context.rootPath,
50
+ {
51
+ not: NODE_MODULES_REGEX
52
+ }
53
+ ]
54
+ });
55
+ rule.include.add(/\.(?:ts|tsx|jsx|mts|cts)$/);
56
+ const target = castArray(chain.get("target"));
57
+ const legacyTarget = [
58
+ "es5",
59
+ "es6",
60
+ "es2015",
61
+ "es2016"
62
+ ];
63
+ if (legacyTarget.some((item) => target.includes(item))) {
64
+ rule.include.add(/[\\/]@rsbuild[\\/]core[\\/]dist[\\/]/);
65
+ }
66
+ for (const condition of [
67
+ ...includes,
68
+ ...config.source.include || []
69
+ ]) {
70
+ rule.include.add(condition);
71
+ }
72
+ for (const condition of [
73
+ ...excludes,
74
+ ...config.source.exclude || []
75
+ ]) {
76
+ rule.exclude.add(condition);
77
+ }
78
+ }
37
79
  function pluginEsbuild(userOptions = {}) {
38
80
  return {
39
81
  name: "modernjs:esbuild",
@@ -56,7 +98,7 @@ function pluginEsbuild(userOptions = {}) {
56
98
  if (options.loader !== false) {
57
99
  chain.module.rule(CHAIN_ID.RULE.JS).uses.delete(CHAIN_ID.USE.BABEL);
58
100
  chain.module.rule(CHAIN_ID.RULE.TS).uses.delete(CHAIN_ID.USE.BABEL).delete(CHAIN_ID.USE.TS);
59
- chain.module.rule(CHAIN_ID.RULE.JS).test(import_shared.JS_REGEX).use("esbuild").loader(esbuildLoaderPath).options({
101
+ chain.module.rule(CHAIN_ID.RULE.JS).test(JS_REGEX).use("esbuild").loader(esbuildLoaderPath).options({
60
102
  loader: "jsx",
61
103
  ...options === null || options === void 0 ? void 0 : options.loader
62
104
  });
@@ -65,7 +107,7 @@ function pluginEsbuild(userOptions = {}) {
65
107
  loader: "tsx",
66
108
  ...options === null || options === void 0 ? void 0 : options.loader
67
109
  });
68
- (0, import_shared.applyScriptCondition)({
110
+ applyScriptCondition({
69
111
  chain,
70
112
  rule,
71
113
  config: rsbuildConfig,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modern-js/rsbuild-plugin-esbuild",
3
- "version": "2.54.6",
3
+ "version": "2.55.0",
4
4
  "description": "Esbuild Rsbuild plugin and Modern.js",
5
5
  "homepage": "https://modernjs.dev",
6
6
  "repository": {
@@ -23,7 +23,6 @@
23
23
  ],
24
24
  "dependencies": {
25
25
  "@swc/helpers": "0.5.3",
26
- "@rsbuild/shared": "0.7.10",
27
26
  "esbuild": "0.17.19",
28
27
  "webpack": "^5.92.0"
29
28
  },
@@ -31,7 +30,7 @@
31
30
  "@rsbuild/core": "0.7.10",
32
31
  "@rsbuild/webpack": "0.7.10",
33
32
  "typescript": "^5.4.2",
34
- "@scripts/build": "2.54.6"
33
+ "@scripts/build": "2.55.0"
35
34
  },
36
35
  "publishConfig": {
37
36
  "access": "public",