@unpackjs/core 1.7.1 → 1.7.3

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.
@@ -4795,19 +4795,19 @@
4795
4795
  }
4796
4796
  });
4797
4797
  },
4798
- 84: (module, __unused_webpack_exports, __nccwpck_require__) => {
4798
+ 637: (module, __unused_webpack_exports, __nccwpck_require__) => {
4799
4799
  "use strict";
4800
- const loader = __nccwpck_require__(739);
4800
+ const loader = __nccwpck_require__(562);
4801
4801
  module.exports = loader.default;
4802
4802
  },
4803
- 739: (__unused_webpack_module, exports, __nccwpck_require__) => {
4803
+ 562: (__unused_webpack_module, exports, __nccwpck_require__) => {
4804
4804
  "use strict";
4805
4805
  Object.defineProperty(exports, "__esModule", { value: true });
4806
4806
  exports["default"] = void 0;
4807
4807
  var _url = _interopRequireDefault(__nccwpck_require__(310));
4808
4808
  var _path = _interopRequireDefault(__nccwpck_require__(17));
4809
- var _options = _interopRequireDefault(__nccwpck_require__(732));
4810
- var _utils = __nccwpck_require__(813);
4809
+ var _options = _interopRequireDefault(__nccwpck_require__(737));
4810
+ var _utils = __nccwpck_require__(702);
4811
4811
  function _interopRequireDefault(e) {
4812
4812
  return e && e.__esModule ? e : { default: e };
4813
4813
  }
@@ -4917,7 +4917,7 @@
4917
4917
  }
4918
4918
  var _default = (exports["default"] = loader);
4919
4919
  },
4920
- 813: (__unused_webpack_module, exports, __nccwpck_require__) => {
4920
+ 702: (__unused_webpack_module, exports, __nccwpck_require__) => {
4921
4921
  "use strict";
4922
4922
  Object.defineProperty(exports, "__esModule", { value: true });
4923
4923
  exports.errorFactory = errorFactory;
@@ -5577,7 +5577,7 @@
5577
5577
  "use strict";
5578
5578
  module.exports = require("url");
5579
5579
  },
5580
- 732: (module) => {
5580
+ 737: (module) => {
5581
5581
  "use strict";
5582
5582
  module.exports = JSON.parse(
5583
5583
  '{"title":"Sass Loader options","type":"object","properties":{"implementation":{"description":"The implementation of the sass to be used.","link":"https://github.com/webpack-contrib/sass-loader#implementation","anyOf":[{"type":"string"},{"type":"object"}]},"api":{"description":"Switch between old and modern API for `sass` (`Dart Sass`) and `Sass Embedded` implementations.","link":"https://github.com/webpack-contrib/sass-loader#sassoptions","enum":["legacy","modern","modern-compiler"]},"sassOptions":{"description":"Options for `node-sass` or `sass` (`Dart Sass`) implementation.","link":"https://github.com/webpack-contrib/sass-loader#sassoptions","anyOf":[{"type":"object","additionalProperties":true},{"instanceof":"Function"}]},"additionalData":{"description":"Prepends/Appends `Sass`/`SCSS` code before the actual entry file.","link":"https://github.com/webpack-contrib/sass-loader#additionaldata","anyOf":[{"type":"string"},{"instanceof":"Function"}]},"sourceMap":{"description":"Enables/Disables generation of source maps.","link":"https://github.com/webpack-contrib/sass-loader#sourcemap","type":"boolean"},"webpackImporter":{"description":"Enables/Disables default `webpack` importer.","link":"https://github.com/webpack-contrib/sass-loader#webpackimporter","type":"boolean"},"warnRuleAsWarning":{"description":"Treats the \'@warn\' rule as a webpack warning.","link":"https://github.com/webpack-contrib/sass-loader#warnruleaswarning","type":"boolean"}},"additionalProperties":false}',
@@ -5607,6 +5607,6 @@
5607
5607
  }
5608
5608
  if (typeof __nccwpck_require__ !== "undefined")
5609
5609
  __nccwpck_require__.ab = __dirname + "/";
5610
- var __webpack_exports__ = __nccwpck_require__(84);
5610
+ var __webpack_exports__ = __nccwpck_require__(637);
5611
5611
  module.exports = __webpack_exports__;
5612
5612
  })();
@@ -1,16 +1,16 @@
1
1
  (() => {
2
2
  "use strict";
3
3
  var __webpack_modules__ = {
4
- 151: (module, __unused_webpack_exports, __nccwpck_require__) => {
5
- const loader = __nccwpck_require__(118);
4
+ 948: (module, __unused_webpack_exports, __nccwpck_require__) => {
5
+ const loader = __nccwpck_require__(193);
6
6
  module.exports = loader.default;
7
7
  },
8
- 118: (__unused_webpack_module, exports, __nccwpck_require__) => {
8
+ 193: (__unused_webpack_module, exports, __nccwpck_require__) => {
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports["default"] = void 0;
11
11
  var _path = _interopRequireDefault(__nccwpck_require__(17));
12
- var _utils = __nccwpck_require__(171);
13
- var _options = _interopRequireDefault(__nccwpck_require__(861));
12
+ var _utils = __nccwpck_require__(394);
13
+ var _options = _interopRequireDefault(__nccwpck_require__(785));
14
14
  function _interopRequireDefault(obj) {
15
15
  return obj && obj.__esModule ? obj : { default: obj };
16
16
  }
@@ -95,7 +95,7 @@
95
95
  };
96
96
  var _default = (exports["default"] = loader);
97
97
  },
98
- 548: (module) => {
98
+ 157: (module) => {
99
99
  function isEqualLocals(a, b, isNamedExport) {
100
100
  if ((!a && b) || (a && !b)) {
101
101
  return false;
@@ -121,7 +121,7 @@
121
121
  }
122
122
  module.exports = isEqualLocals;
123
123
  },
124
- 171: (__unused_webpack_module, exports, __nccwpck_require__) => {
124
+ 394: (__unused_webpack_module, exports, __nccwpck_require__) => {
125
125
  Object.defineProperty(exports, "__esModule", { value: true });
126
126
  exports.getExportLazyStyleCode = getExportLazyStyleCode;
127
127
  exports.getExportStyleCode = getExportStyleCode;
@@ -142,7 +142,7 @@
142
142
  exports.getdomAPI = getdomAPI;
143
143
  exports.stringifyRequest = stringifyRequest;
144
144
  var _path = _interopRequireDefault(__nccwpck_require__(17));
145
- var _isEqualLocals = _interopRequireDefault(__nccwpck_require__(548));
145
+ var _isEqualLocals = _interopRequireDefault(__nccwpck_require__(157));
146
146
  function _interopRequireDefault(obj) {
147
147
  return obj && obj.__esModule ? obj : { default: obj };
148
148
  }
@@ -337,7 +337,7 @@
337
337
  17: (module) => {
338
338
  module.exports = require("path");
339
339
  },
340
- 861: (module) => {
340
+ 785: (module) => {
341
341
  module.exports = JSON.parse(
342
342
  '{"title":"Style Loader options","type":"object","properties":{"injectType":{"description":"Allows to setup how styles will be injected into DOM.","link":"https://github.com/webpack-contrib/style-loader#injecttype","enum":["styleTag","singletonStyleTag","autoStyleTag","lazyStyleTag","lazySingletonStyleTag","lazyAutoStyleTag","linkTag"]},"attributes":{"description":"Adds custom attributes to tag.","link":"https://github.com/webpack-contrib/style-loader#attributes","type":"object"},"insert":{"description":"Inserts `<style>`/`<link>` at the given position.","link":"https://github.com/webpack-contrib/style-loader#insert","type":"string"},"base":{"description":"Sets module ID base for DLLPlugin.","link":"https://github.com/webpack-contrib/style-loader#base","type":"number"},"esModule":{"description":"Use the ES modules syntax.","link":"https://github.com/webpack-contrib/css-loader#esmodule","type":"boolean"},"styleTagTransform":{"description":"Transform tag and css when insert \'style\' tag into the DOM","link":"https://github.com/webpack-contrib/style-loader#styleTagTransform","type":"string"}},"additionalProperties":false}',
343
343
  );
@@ -365,6 +365,6 @@
365
365
  }
366
366
  if (typeof __nccwpck_require__ !== "undefined")
367
367
  __nccwpck_require__.ab = __dirname + "/";
368
- var __webpack_exports__ = __nccwpck_require__(151);
368
+ var __webpack_exports__ = __nccwpck_require__(948);
369
369
  module.exports = __webpack_exports__;
370
370
  })();
@@ -35,8 +35,6 @@ var import_node_path = __toESM(require("node:path"));
35
35
  var import_core = require("@rspack/core");
36
36
  var import_html_webpack_plugin = __toESM(require("html-webpack-plugin"));
37
37
  var import_utils = require("../utils.cjs");
38
- var import_esbuild = __toESM(require("esbuild"));
39
- var import_esbuild_loader = require("esbuild-loader");
40
38
  var import_json5 = __toESM(require("json5"));
41
39
  var import_constants = require("../constants.cjs");
42
40
  var import_minimizer = require("../lightningcss/minimizer.cjs");
@@ -49,13 +47,14 @@ var import_chunkSplit = require("./chunkSplit.cjs");
49
47
  var import_css = require("./css.cjs");
50
48
  var import_experimentCss = require("./experimentCss.cjs");
51
49
  var import_helper = require("./helper.cjs");
52
- const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
50
+ var import_jsMinify = require("./jsMinify.cjs");
51
+ const { TsCheckerRspackPlugin } = require("ts-checker-rspack-plugin");
53
52
  const BundleAnalyzerPlugin = require("../../compiled/webpack-bundle-analyzer/index.js").BundleAnalyzerPlugin;
54
53
  const CopyWebpackPlugin = require("copy-webpack-plugin");
55
54
  async function getBundlerConfig(unpackConfig) {
56
55
  const isRspack = unpackConfig.bundler === "rspack";
57
56
  const HtmlPlugin = isRspack ? import_core.rspack.HtmlRspackPlugin : import_html_webpack_plugin.default;
58
- const definePlugin = (define) => isRspack ? new import_core.rspack.DefinePlugin(define) : new import_esbuild_loader.EsbuildPlugin({ define, implementation: import_esbuild.default });
57
+ const definePlugin = (define) => isRspack ? new import_core.rspack.DefinePlugin(define) : new import_webpack2.default.DefinePlugin(define);
59
58
  const JS_FILENAME = (0, import_helper.getOutputFilename)({ type: "js", hash: unpackConfig.build?.filenameHash });
60
59
  const IgnorePlugin = isRspack ? import_core.rspack.IgnorePlugin : import_webpack2.default.IgnorePlugin;
61
60
  const CopyPlugin = isRspack ? import_core.rspack.CopyRspackPlugin : CopyWebpackPlugin;
@@ -126,7 +125,7 @@ async function getBundlerConfig(unpackConfig) {
126
125
  contextRegExp: /moment$/
127
126
  }),
128
127
  unpackConfig.build?.copy && new CopyPlugin({ patterns: unpackConfig.build.copy }),
129
- unpackConfig.build?.typeCheck && (0, import_utils.isDev)() && isTs && new ForkTsCheckerWebpackPlugin({
128
+ unpackConfig.build?.typeCheck && (0, import_utils.isDev)() && isTs && new TsCheckerRspackPlugin({
130
129
  typescript: {
131
130
  // set 'readonly' to avoid emitting tsbuildinfo, as the generated tsbuildinfo will break fork-ts-checker
132
131
  mode: "readonly",
@@ -167,14 +166,14 @@ async function getBundlerConfig(unpackConfig) {
167
166
  },
168
167
  experiments: {
169
168
  lazyCompilation: unpackConfig.dev?.lazyCompilation && (0, import_utils.isDevServer)(),
170
- css: false
169
+ css: false,
170
+ ...isRspack && (0, import_utils.isDev)() && unpackConfig.experiments?.incremental ? { incremental: true } : {}
171
171
  },
172
172
  optimization: {
173
173
  moduleIds: (0, import_utils.isDev)() ? "named" : "deterministic",
174
174
  minimize: Boolean(unpackConfig.build?.minify),
175
175
  minimizer: [
176
- new import_esbuild_loader.EsbuildPlugin({
177
- implementation: import_esbuild.default,
176
+ new import_jsMinify.JsMinifyPlugin({
178
177
  target: import_constants.ESBUILD_TARGET
179
178
  }),
180
179
  new import_minimizer.LightningcssMinifyPlugin(minifyOptions.lightningcss)
@@ -182,7 +181,10 @@ async function getBundlerConfig(unpackConfig) {
182
181
  },
183
182
  cache: unpackConfig.build?.cache && unpackConfig.bundler === "webpack" ? {
184
183
  type: "filesystem"
185
- } : void 0
184
+ } : void 0,
185
+ watchOptions: {
186
+ ignored: /[\\/](?:\.git|node_modules)[\\/]/
187
+ }
186
188
  };
187
189
  if (unpackConfig.experiments?.css)
188
190
  import_logger.logger.warn("Experiments.css is not stable yet, please use with caution");
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bundler-config/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAqBzE,wBAAsB,gBAAgB,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,oBAAoB,CAAC,CA8KhG"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bundler-config/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAoBzE,wBAAsB,gBAAgB,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAiLhG"}
@@ -12,11 +12,9 @@ import path2 from "node:path";
12
12
  import { rspack } from "@rspack/core";
13
13
  import HtmlWebpackPlugin from "html-webpack-plugin";
14
14
  import { isDev, isDevServer, isFunction, isPlainObject, isProd, mergeConfig } from "../utils.js";
15
- const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
15
+ const { TsCheckerRspackPlugin } = require("ts-checker-rspack-plugin");
16
16
  const BundleAnalyzerPlugin = require("../../compiled/webpack-bundle-analyzer/index.js").BundleAnalyzerPlugin;
17
17
  const CopyWebpackPlugin = require("copy-webpack-plugin");
18
- import esbuild from "esbuild";
19
- import { EsbuildPlugin } from "esbuild-loader";
20
18
  import json5 from "json5";
21
19
  import { ESBUILD_TARGET, NODE_MODULES_REGEX, TEMPLATE_CONTENT } from "../constants.js";
22
20
  import { LightningcssMinifyPlugin } from "../lightningcss/minimizer.js";
@@ -29,10 +27,11 @@ import { applyChunkSplitConfig } from "./chunkSplit.js";
29
27
  import { applyCssConfig } from "./css.js";
30
28
  import { applyExperimentCssConfig } from "./experimentCss.js";
31
29
  import { getEntry, getOutputFilename } from "./helper.js";
30
+ import { JsMinifyPlugin } from "./jsMinify.js";
32
31
  async function getBundlerConfig(unpackConfig) {
33
32
  const isRspack = unpackConfig.bundler === "rspack";
34
33
  const HtmlPlugin = isRspack ? rspack.HtmlRspackPlugin : HtmlWebpackPlugin;
35
- const definePlugin = (define) => isRspack ? new rspack.DefinePlugin(define) : new EsbuildPlugin({ define, implementation: esbuild });
34
+ const definePlugin = (define) => isRspack ? new rspack.DefinePlugin(define) : new webpack.DefinePlugin(define);
36
35
  const JS_FILENAME = getOutputFilename({ type: "js", hash: unpackConfig.build?.filenameHash });
37
36
  const IgnorePlugin = isRspack ? rspack.IgnorePlugin : webpack.IgnorePlugin;
38
37
  const CopyPlugin = isRspack ? rspack.CopyRspackPlugin : CopyWebpackPlugin;
@@ -103,7 +102,7 @@ async function getBundlerConfig(unpackConfig) {
103
102
  contextRegExp: /moment$/
104
103
  }),
105
104
  unpackConfig.build?.copy && new CopyPlugin({ patterns: unpackConfig.build.copy }),
106
- unpackConfig.build?.typeCheck && isDev() && isTs && new ForkTsCheckerWebpackPlugin({
105
+ unpackConfig.build?.typeCheck && isDev() && isTs && new TsCheckerRspackPlugin({
107
106
  typescript: {
108
107
  // set 'readonly' to avoid emitting tsbuildinfo, as the generated tsbuildinfo will break fork-ts-checker
109
108
  mode: "readonly",
@@ -144,14 +143,14 @@ async function getBundlerConfig(unpackConfig) {
144
143
  },
145
144
  experiments: {
146
145
  lazyCompilation: unpackConfig.dev?.lazyCompilation && isDevServer(),
147
- css: false
146
+ css: false,
147
+ ...isRspack && isDev() && unpackConfig.experiments?.incremental ? { incremental: true } : {}
148
148
  },
149
149
  optimization: {
150
150
  moduleIds: isDev() ? "named" : "deterministic",
151
151
  minimize: Boolean(unpackConfig.build?.minify),
152
152
  minimizer: [
153
- new EsbuildPlugin({
154
- implementation: esbuild,
153
+ new JsMinifyPlugin({
155
154
  target: ESBUILD_TARGET
156
155
  }),
157
156
  new LightningcssMinifyPlugin(minifyOptions.lightningcss)
@@ -159,7 +158,10 @@ async function getBundlerConfig(unpackConfig) {
159
158
  },
160
159
  cache: unpackConfig.build?.cache && unpackConfig.bundler === "webpack" ? {
161
160
  type: "filesystem"
162
- } : void 0
161
+ } : void 0,
162
+ watchOptions: {
163
+ ignored: /[\\/](?:\.git|node_modules)[\\/]/
164
+ }
163
165
  };
164
166
  if (unpackConfig.experiments?.css)
165
167
  logger.warn("Experiments.css is not stable yet, please use with caution");
@@ -0,0 +1,101 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var jsMinify_exports = {};
29
+ __export(jsMinify_exports, {
30
+ JsMinifyPlugin: () => JsMinifyPlugin
31
+ });
32
+ module.exports = __toCommonJS(jsMinify_exports);
33
+ var import_esbuild = require("esbuild");
34
+ var import_webpack = __toESM(require("webpack"));
35
+ const { RawSource, SourceMapSource } = import_webpack.default.sources;
36
+ const isJsFile = /\.[cm]?js(\?.*)?$/i;
37
+ const PLUGIN_NAME = "JsMinifyPlugin";
38
+ class JsMinifyPlugin {
39
+ constructor(options = {}) {
40
+ this.options = {};
41
+ const { implementation } = options;
42
+ this.transform = implementation?.transform ?? import_esbuild.transform;
43
+ this.options = options;
44
+ }
45
+ apply(compiler) {
46
+ const { implementation, ...transformOptions } = this.options;
47
+ const meta = JSON.stringify({
48
+ name: PLUGIN_NAME,
49
+ version: "1.7.3",
50
+ options: transformOptions
51
+ });
52
+ compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
53
+ compilation.hooks.chunkHash.tap(PLUGIN_NAME, (_, hash) => hash.update(meta));
54
+ compilation.hooks.processAssets.tapPromise(
55
+ {
56
+ name: PLUGIN_NAME,
57
+ stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE,
58
+ additionalAssets: true
59
+ },
60
+ () => this.transformAssets(compilation)
61
+ );
62
+ compilation.hooks.statsPrinter.tap(PLUGIN_NAME, (stats) => {
63
+ stats.hooks.print.for("asset.info.minimized").tap(
64
+ PLUGIN_NAME,
65
+ (minimized, { green, formatFlag }) => minimized && green && formatFlag ? green(formatFlag("minimized")) : ""
66
+ );
67
+ });
68
+ });
69
+ }
70
+ async transformAssets(compilation) {
71
+ const {
72
+ options: { devtool }
73
+ } = compilation.compiler;
74
+ const sourceMap = !!devtool && devtool.includes("source-map");
75
+ const assets = compilation.getAssets().filter((asset) => !asset.info.minimized && isJsFile.test(asset.name));
76
+ const { implementation, ...transformOptions } = this.options;
77
+ await Promise.all(
78
+ assets.map(async (asset) => {
79
+ const { source, map } = asset.source.sourceAndMap();
80
+ const output = await this.transform(Buffer.isBuffer(source) ? source.toString() : source, {
81
+ ...transformOptions,
82
+ minify: true,
83
+ sourcemap: sourceMap,
84
+ sourcefile: asset.name
85
+ });
86
+ let newMap = void 0;
87
+ if (output.map) {
88
+ newMap = JSON.parse(output.map);
89
+ newMap.sources = [asset.name];
90
+ }
91
+ const newSource = sourceMap && newMap ? new SourceMapSource(output.code, asset.name, newMap, source, map, true) : new RawSource(output.code);
92
+ const newInfo = { ...asset.info, minimized: true };
93
+ compilation.updateAsset(asset.name, newSource, newInfo);
94
+ })
95
+ );
96
+ }
97
+ }
98
+ // Annotate the CommonJS export names for ESM import in node:
99
+ 0 && (module.exports = {
100
+ JsMinifyPlugin
101
+ });
@@ -0,0 +1,18 @@
1
+ import { type TransformOptions, transform } from 'esbuild';
2
+ import webpack from 'webpack';
3
+ type Implementation = {
4
+ transform: typeof transform;
5
+ };
6
+ export type EsbuildPluginOptions = Omit<TransformOptions, 'sourcemap' | 'sourcefile'> & {
7
+ /** Pass a custom esbuild implementation */
8
+ implementation?: Implementation;
9
+ };
10
+ export declare class JsMinifyPlugin {
11
+ private readonly options;
12
+ private readonly transform;
13
+ constructor(options?: EsbuildPluginOptions);
14
+ apply(compiler: webpack.Compiler): void;
15
+ private transformAssets;
16
+ }
17
+ export {};
18
+ //# sourceMappingURL=jsMinify.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsMinify.d.ts","sourceRoot":"","sources":["../../src/bundler-config/jsMinify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAC1D,OAAO,OAAO,MAAM,SAAS,CAAA;AAK7B,KAAK,cAAc,GAAG;IACpB,SAAS,EAAE,OAAO,SAAS,CAAA;CAC5B,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,gBAAgB,EAAE,WAAW,GAAG,YAAY,CAAC,GAAG;IACtF,2CAA2C;IAC3C,cAAc,CAAC,EAAE,cAAc,CAAA;CAChC,CAAA;AAGD,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA2B;IACnD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAkB;gBAEhC,OAAO,GAAE,oBAAyB;IAM9C,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ;YA2BlB,eAAe;CAkC9B"}
@@ -0,0 +1,77 @@
1
+ import { createRequire } from 'node:module';
2
+ var require = createRequire(import.meta['url']);
3
+
4
+ import path from "path";
5
+ import { fileURLToPath } from "url";
6
+ var getFilename = () => fileURLToPath(import.meta.url);
7
+ var getDirname = () => path.dirname(getFilename());
8
+ var __dirname = /* @__PURE__ */ getDirname();
9
+ var __filename = /* @__PURE__ */ getFilename();
10
+ import { transform } from "esbuild";
11
+ import webpack from "webpack";
12
+ const { RawSource, SourceMapSource } = webpack.sources;
13
+ const isJsFile = /\.[cm]?js(\?.*)?$/i;
14
+ const PLUGIN_NAME = "JsMinifyPlugin";
15
+ class JsMinifyPlugin {
16
+ constructor(options = {}) {
17
+ this.options = {};
18
+ const { implementation } = options;
19
+ this.transform = implementation?.transform ?? transform;
20
+ this.options = options;
21
+ }
22
+ apply(compiler) {
23
+ const { implementation, ...transformOptions } = this.options;
24
+ const meta = JSON.stringify({
25
+ name: PLUGIN_NAME,
26
+ version: "1.7.3",
27
+ options: transformOptions
28
+ });
29
+ compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
30
+ compilation.hooks.chunkHash.tap(PLUGIN_NAME, (_, hash) => hash.update(meta));
31
+ compilation.hooks.processAssets.tapPromise(
32
+ {
33
+ name: PLUGIN_NAME,
34
+ stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE,
35
+ additionalAssets: true
36
+ },
37
+ () => this.transformAssets(compilation)
38
+ );
39
+ compilation.hooks.statsPrinter.tap(PLUGIN_NAME, (stats) => {
40
+ stats.hooks.print.for("asset.info.minimized").tap(
41
+ PLUGIN_NAME,
42
+ (minimized, { green, formatFlag }) => minimized && green && formatFlag ? green(formatFlag("minimized")) : ""
43
+ );
44
+ });
45
+ });
46
+ }
47
+ async transformAssets(compilation) {
48
+ const {
49
+ options: { devtool }
50
+ } = compilation.compiler;
51
+ const sourceMap = !!devtool && devtool.includes("source-map");
52
+ const assets = compilation.getAssets().filter((asset) => !asset.info.minimized && isJsFile.test(asset.name));
53
+ const { implementation, ...transformOptions } = this.options;
54
+ await Promise.all(
55
+ assets.map(async (asset) => {
56
+ const { source, map } = asset.source.sourceAndMap();
57
+ const output = await this.transform(Buffer.isBuffer(source) ? source.toString() : source, {
58
+ ...transformOptions,
59
+ minify: true,
60
+ sourcemap: sourceMap,
61
+ sourcefile: asset.name
62
+ });
63
+ let newMap = void 0;
64
+ if (output.map) {
65
+ newMap = JSON.parse(output.map);
66
+ newMap.sources = [asset.name];
67
+ }
68
+ const newSource = sourceMap && newMap ? new SourceMapSource(output.code, asset.name, newMap, source, map, true) : new RawSource(output.code);
69
+ const newInfo = { ...asset.info, minimized: true };
70
+ compilation.updateAsset(asset.name, newSource, newInfo);
71
+ })
72
+ );
73
+ }
74
+ }
75
+ export {
76
+ JsMinifyPlugin
77
+ };
@@ -60,6 +60,11 @@ function createUnpack() {
60
60
  modules: true,
61
61
  transformer: "postcss",
62
62
  sourceMap: false
63
+ },
64
+ performance: {
65
+ chunkSplit: {
66
+ strategy: "split-by-experience"
67
+ }
63
68
  }
64
69
  };
65
70
  let { plugins, bundlerConfig, ...rest } = (0, import_utils.mergeConfig)(defaultConfig, unpackConfig);
@@ -76,7 +81,7 @@ function createUnpack() {
76
81
  build: async (unpackConfig) => {
77
82
  (0, import_utils.setNodeEnv)("production");
78
83
  console.log(
79
- import_colors.default.rainbow(`unpack v${"1.7.1"}`),
84
+ import_colors.default.rainbow(`unpack v${"1.7.3"}`),
80
85
  import_colors.default.green("building for production...")
81
86
  );
82
87
  const config = await resolveConfig(unpackConfig);
@@ -92,7 +97,7 @@ function createUnpack() {
92
97
  watch: async (unpackConfig) => {
93
98
  (0, import_utils.setNodeEnv)("development");
94
99
  console.log(
95
- import_colors.default.rainbow(`unpack v${"1.7.1"}`),
100
+ import_colors.default.rainbow(`unpack v${"1.7.3"}`),
96
101
  import_colors.default.green("building for development...")
97
102
  );
98
103
  const config = await resolveConfig(unpackConfig);
@@ -1 +1 @@
1
- {"version":3,"file":"createUnpack.d.ts","sourceRoot":"","sources":["../src/createUnpack.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAGjD,wBAAgB,YAAY;0BAuCI,YAAY;0BASZ,YAAY;0BAOZ,YAAY;EAU3C"}
1
+ {"version":3,"file":"createUnpack.d.ts","sourceRoot":"","sources":["../src/createUnpack.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAGjD,wBAAgB,YAAY;0BA4CI,YAAY;0BASZ,YAAY;0BAOZ,YAAY;EAU3C"}
@@ -37,6 +37,11 @@ function createUnpack() {
37
37
  modules: true,
38
38
  transformer: "postcss",
39
39
  sourceMap: false
40
+ },
41
+ performance: {
42
+ chunkSplit: {
43
+ strategy: "split-by-experience"
44
+ }
40
45
  }
41
46
  };
42
47
  let { plugins, bundlerConfig, ...rest } = mergeConfig(defaultConfig, unpackConfig);
@@ -53,7 +58,7 @@ function createUnpack() {
53
58
  build: async (unpackConfig) => {
54
59
  setNodeEnv("production");
55
60
  console.log(
56
- colors.rainbow(`unpack v${"1.7.1"}`),
61
+ colors.rainbow(`unpack v${"1.7.3"}`),
57
62
  colors.green("building for production...")
58
63
  );
59
64
  const config = await resolveConfig(unpackConfig);
@@ -69,7 +74,7 @@ function createUnpack() {
69
74
  watch: async (unpackConfig) => {
70
75
  setNodeEnv("development");
71
76
  console.log(
72
- colors.rainbow(`unpack v${"1.7.1"}`),
77
+ colors.rainbow(`unpack v${"1.7.3"}`),
73
78
  colors.green("building for development...")
74
79
  );
75
80
  const config = await resolveConfig(unpackConfig);
@@ -34,7 +34,7 @@ module.exports = __toCommonJS(minimizer_exports);
34
34
  var import_node_buffer = require("node:buffer");
35
35
  var lightningcss = __toESM(require("lightningcss"));
36
36
  var import_cache = require("./cache.cjs");
37
- const PLUGIN_NAME = "PluginLightningcssMinify";
37
+ const PLUGIN_NAME = "LightningcssMinifyPlugin";
38
38
  class LightningcssMinifyPlugin {
39
39
  constructor(opts = {}) {
40
40
  this.transform = opts.implementation?.transform ?? lightningcss.transform;
@@ -10,7 +10,7 @@ var __filename = /* @__PURE__ */ getFilename();
10
10
  import { Buffer } from "node:buffer";
11
11
  import * as lightningcss from "lightningcss";
12
12
  import { getLightningcssTargets } from "./cache.js";
13
- const PLUGIN_NAME = "PluginLightningcssMinify";
13
+ const PLUGIN_NAME = "LightningcssMinifyPlugin";
14
14
  class LightningcssMinifyPlugin {
15
15
  constructor(opts = {}) {
16
16
  this.transform = opts.implementation?.transform ?? lightningcss.transform;
@@ -188,10 +188,7 @@ const bundleDep = ({
188
188
  css: true
189
189
  },
190
190
  externals: {
191
- react: getExternalValue("react"),
192
- "react-dom": getExternalValue("react-dom"),
193
- "react-router": getExternalValue("react-router"),
194
- "react-router-dom": getExternalValue("react-router-dom")
191
+ react: getExternalValue("react")
195
192
  }
196
193
  });
197
194
  compiler.run((_, stats) => {
@@ -240,6 +237,8 @@ const getPkgEntry = (packageJson) => {
240
237
  if ((0, import_utils.isString)(defaultExport.default))
241
238
  return defaultExport.default;
242
239
  }
240
+ if ((0, import_utils.isString)(packageJson.exports.default))
241
+ return packageJson.exports.default;
243
242
  }
244
243
  if (packageJson.main)
245
244
  return packageJson.main;
@@ -251,8 +250,9 @@ const prebundleDeps = async ({
251
250
  const { root } = unpackConfig;
252
251
  const packageJson = JSON.parse(import_node_fs.default.readFileSync(import_node_path.default.resolve(root, "package.json"), "utf-8"));
253
252
  const existExternals = getExistExternals(unpackConfig.externals);
253
+ const excludeDeps = [...existExternals || [], ...userOptions.exclude || []];
254
254
  const shouldIncludeDeps = Object.keys(packageJson.dependencies).filter(
255
- (pkgName) => !existExternals.includes(pkgName) && !userOptions.exclude?.includes(pkgName)
255
+ (pkgName) => !excludeDeps.includes(pkgName)
256
256
  );
257
257
  const needBundleDeps = shouldIncludeDeps.map((pkgName) => {
258
258
  const packageJson2 = JSON.parse(
@@ -1 +1 @@
1
- {"version":3,"file":"prebundleDeps.d.ts","sourceRoot":"","sources":["../src/prebundleDeps.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AA+N3C,eAAO,MAAM,aAAa,sBAEvB;IACD,YAAY,EAAE,YAAY,CAAA;CAC3B,KAAG,OAAO,CAAC,YAAY,CA0GvB,CAAA"}
1
+ {"version":3,"file":"prebundleDeps.d.ts","sourceRoot":"","sources":["../src/prebundleDeps.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AA6N3C,eAAO,MAAM,aAAa,sBAEvB;IACD,YAAY,EAAE,YAAY,CAAA;CAC3B,KAAG,OAAO,CAAC,YAAY,CA2GvB,CAAA"}
@@ -174,10 +174,7 @@ const bundleDep = ({
174
174
  css: true
175
175
  },
176
176
  externals: {
177
- react: getExternalValue("react"),
178
- "react-dom": getExternalValue("react-dom"),
179
- "react-router": getExternalValue("react-router"),
180
- "react-router-dom": getExternalValue("react-router-dom")
177
+ react: getExternalValue("react")
181
178
  }
182
179
  });
183
180
  compiler.run((_, stats) => {
@@ -226,6 +223,8 @@ const getPkgEntry = (packageJson) => {
226
223
  if (isString(defaultExport.default))
227
224
  return defaultExport.default;
228
225
  }
226
+ if (isString(packageJson.exports.default))
227
+ return packageJson.exports.default;
229
228
  }
230
229
  if (packageJson.main)
231
230
  return packageJson.main;
@@ -237,8 +236,9 @@ const prebundleDeps = async ({
237
236
  const { root } = unpackConfig;
238
237
  const packageJson = JSON.parse(fs.readFileSync(path2.resolve(root, "package.json"), "utf-8"));
239
238
  const existExternals = getExistExternals(unpackConfig.externals);
239
+ const excludeDeps = [...existExternals || [], ...userOptions.exclude || []];
240
240
  const shouldIncludeDeps = Object.keys(packageJson.dependencies).filter(
241
- (pkgName) => !existExternals.includes(pkgName) && !userOptions.exclude?.includes(pkgName)
241
+ (pkgName) => !excludeDeps.includes(pkgName)
242
242
  );
243
243
  const needBundleDeps = shouldIncludeDeps.map((pkgName) => {
244
244
  const packageJson2 = JSON.parse(
@@ -30,7 +30,6 @@ __export(build_exports, {
30
30
  bundlerBuild: () => bundlerBuild
31
31
  });
32
32
  module.exports = __toCommonJS(build_exports);
33
- var import_node_path = __toESM(require("node:path"));
34
33
  var import_core = require("@rspack/core");
35
34
  var import_utils = require("../utils.cjs");
36
35
  var import_webpack = __toESM(require("webpack"));
@@ -61,12 +60,7 @@ async function bundlerBuild(unpackConfig) {
61
60
  }
62
61
  };
63
62
  if ((0, import_utils.isWatch)()) {
64
- compiler.watch(
65
- {
66
- ignored: [import_node_path.default.resolve(unpackConfig.root, "unpack.config.*")]
67
- },
68
- handler
69
- );
63
+ compiler.watch({}, handler);
70
64
  } else {
71
65
  compiler.run(handler);
72
66
  }
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/run/build.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAKnD,wBAAsB,YAAY,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAmC5E"}
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/run/build.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAKnD,wBAAsB,YAAY,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CA8B5E"}