@docusaurus/bundler 0.0.0-6098 → 0.0.0-6101
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/lib/currentBundler.d.ts +4 -0
- package/lib/currentBundler.d.ts.map +1 -1
- package/lib/currentBundler.js +16 -6
- package/lib/currentBundler.js.map +1 -1
- package/lib/importFaster.d.ts +3 -2
- package/lib/importFaster.d.ts.map +1 -1
- package/lib/importFaster.js +10 -0
- package/lib/importFaster.js.map +1 -1
- package/lib/loaders/jsLoader.d.ts +1 -1
- package/lib/loaders/jsLoader.d.ts.map +1 -1
- package/lib/loaders/jsLoader.js +27 -0
- package/lib/loaders/jsLoader.js.map +1 -1
- package/lib/minification.d.ts.map +1 -1
- package/lib/minification.js +26 -2
- package/lib/minification.js.map +1 -1
- package/package.json +15 -8
- package/src/currentBundler.ts +23 -8
- package/src/importFaster.ts +11 -1
- package/src/loaders/jsLoader.ts +32 -1
- package/src/minification.ts +27 -2
package/lib/currentBundler.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import WebpackBar from 'webpackbar';
|
|
8
8
|
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
9
9
|
import CopyWebpackPlugin from 'copy-webpack-plugin';
|
|
10
|
+
import type { FasterModule } from './importFaster';
|
|
10
11
|
import type { CurrentBundler, DocusaurusConfig } from '@docusaurus/types';
|
|
11
12
|
type SiteConfigSlice = {
|
|
12
13
|
future: {
|
|
@@ -16,6 +17,9 @@ type SiteConfigSlice = {
|
|
|
16
17
|
export declare function getCurrentBundler({ siteConfig, }: {
|
|
17
18
|
siteConfig: SiteConfigSlice;
|
|
18
19
|
}): Promise<CurrentBundler>;
|
|
20
|
+
export declare function getCurrentBundlerAsRspack({ currentBundler, }: {
|
|
21
|
+
currentBundler: CurrentBundler;
|
|
22
|
+
}): FasterModule['rspack'];
|
|
19
23
|
export declare function getCSSExtractPlugin({ currentBundler, }: {
|
|
20
24
|
currentBundler: CurrentBundler;
|
|
21
25
|
}): Promise<typeof MiniCssExtractPlugin>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currentBundler.d.ts","sourceRoot":"","sources":["../src/currentBundler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,oBAAoB,MAAM,yBAAyB,CAAC;AAC3D,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AAEpD,OAAO,KAAK,EAAC,cAAc,EAAE,gBAAgB,EAAC,MAAM,mBAAmB,CAAC;AAGxE,KAAK,eAAe,GAAG;IACrB,MAAM,EAAE;QACN,mBAAmB,EAAE,IAAI,CACvB,gBAAgB,CAAC,QAAQ,CAAC,CAAC,qBAAqB,CAAC,EACjD,eAAe,CAChB,CAAC;KACH,CAAC;CACH,CAAC;AAMF,wBAAsB,iBAAiB,CAAC,EACtC,UAAU,GACX,EAAE;IACD,UAAU,EAAE,eAAe,CAAC;CAC7B,GAAG,OAAO,CAAC,cAAc,CAAC,CAW1B;AAED,wBAAsB,mBAAmB,CAAC,EACxC,cAAc,GACf,EAAE;IACD,cAAc,EAAE,cAAc,CAAC;CAChC,GAAG,OAAO,CAAC,OAAO,oBAAoB,CAAC,
|
|
1
|
+
{"version":3,"file":"currentBundler.d.ts","sourceRoot":"","sources":["../src/currentBundler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,oBAAoB,MAAM,yBAAyB,CAAC;AAC3D,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AAEpD,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAC,cAAc,EAAE,gBAAgB,EAAC,MAAM,mBAAmB,CAAC;AAGxE,KAAK,eAAe,GAAG;IACrB,MAAM,EAAE;QACN,mBAAmB,EAAE,IAAI,CACvB,gBAAgB,CAAC,QAAQ,CAAC,CAAC,qBAAqB,CAAC,EACjD,eAAe,CAChB,CAAC;KACH,CAAC;CACH,CAAC;AAMF,wBAAsB,iBAAiB,CAAC,EACtC,UAAU,GACX,EAAE;IACD,UAAU,EAAE,eAAe,CAAC;CAC7B,GAAG,OAAO,CAAC,cAAc,CAAC,CAW1B;AAED,wBAAgB,yBAAyB,CAAC,EACxC,cAAc,GACf,EAAE;IACD,cAAc,EAAE,cAAc,CAAC;CAChC,GAAG,YAAY,CAAC,QAAQ,CAAC,CAOzB;AAED,wBAAsB,mBAAmB,CAAC,EACxC,cAAc,GACf,EAAE;IACD,cAAc,EAAE,cAAc,CAAC;CAChC,GAAG,OAAO,CAAC,OAAO,oBAAoB,CAAC,CAMvC;AAED,wBAAsB,aAAa,CAAC,EAClC,cAAc,GACf,EAAE;IACD,cAAc,EAAE,cAAc,CAAC;CAChC,GAAG,OAAO,CAAC,OAAO,iBAAiB,CAAC,CAMpC;AAED,wBAAsB,oBAAoB,CAAC,EACzC,cAAc,GACf,EAAE;IACD,cAAc,EAAE,cAAc,CAAC;CAChC,GAAG,OAAO,CAAC,OAAO,UAAU,CAAC,CAgB7B"}
|
package/lib/currentBundler.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.getCurrentBundler = getCurrentBundler;
|
|
10
|
+
exports.getCurrentBundlerAsRspack = getCurrentBundlerAsRspack;
|
|
10
11
|
exports.getCSSExtractPlugin = getCSSExtractPlugin;
|
|
11
12
|
exports.getCopyPlugin = getCopyPlugin;
|
|
12
13
|
exports.getProgressBarPlugin = getProgressBarPlugin;
|
|
@@ -15,31 +16,40 @@ const webpack_1 = tslib_1.__importDefault(require("webpack"));
|
|
|
15
16
|
const webpackbar_1 = tslib_1.__importDefault(require("webpackbar"));
|
|
16
17
|
const mini_css_extract_plugin_1 = tslib_1.__importDefault(require("mini-css-extract-plugin"));
|
|
17
18
|
const copy_webpack_plugin_1 = tslib_1.__importDefault(require("copy-webpack-plugin"));
|
|
18
|
-
const
|
|
19
|
+
const importFaster_1 = require("./importFaster");
|
|
19
20
|
function isRspack(siteConfig) {
|
|
20
21
|
return siteConfig.future.experimental_faster.rspackBundler;
|
|
21
22
|
}
|
|
22
23
|
async function getCurrentBundler({ siteConfig, }) {
|
|
23
24
|
if (isRspack(siteConfig)) {
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
return {
|
|
26
|
+
name: 'rspack',
|
|
27
|
+
instance: (await (0, importFaster_1.importRspack)()),
|
|
28
|
+
};
|
|
26
29
|
}
|
|
27
30
|
return {
|
|
28
31
|
name: 'webpack',
|
|
29
32
|
instance: webpack_1.default,
|
|
30
33
|
};
|
|
31
34
|
}
|
|
35
|
+
function getCurrentBundlerAsRspack({ currentBundler, }) {
|
|
36
|
+
if (currentBundler.name !== 'rspack') {
|
|
37
|
+
throw new Error(`Can't getCurrentBundlerAsRspack() because current bundler is ${currentBundler.name}`);
|
|
38
|
+
}
|
|
39
|
+
return currentBundler.instance;
|
|
40
|
+
}
|
|
32
41
|
async function getCSSExtractPlugin({ currentBundler, }) {
|
|
33
42
|
if (currentBundler.name === 'rspack') {
|
|
34
|
-
|
|
43
|
+
// @ts-expect-error: this exists only in Rspack
|
|
44
|
+
return currentBundler.instance.CssExtractRspackPlugin;
|
|
35
45
|
}
|
|
36
46
|
return mini_css_extract_plugin_1.default;
|
|
37
47
|
}
|
|
38
48
|
async function getCopyPlugin({ currentBundler, }) {
|
|
39
49
|
if (currentBundler.name === 'rspack') {
|
|
40
|
-
|
|
50
|
+
// @ts-expect-error: this exists only in Rspack
|
|
51
|
+
return currentBundler.instance.CopyRspackPlugin;
|
|
41
52
|
}
|
|
42
|
-
// https://github.com/webpack-contrib/copy-webpack-plugin
|
|
43
53
|
return copy_webpack_plugin_1.default;
|
|
44
54
|
}
|
|
45
55
|
async function getProgressBarPlugin({ currentBundler, }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currentBundler.js","sourceRoot":"","sources":["../src/currentBundler.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;
|
|
1
|
+
{"version":3,"file":"currentBundler.js","sourceRoot":"","sources":["../src/currentBundler.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAwBH,8CAeC;AAED,8DAWC;AAED,kDAUC;AAED,sCAUC;AAED,oDAoBC;;AAhGD,8DAA8B;AAC9B,oEAAoC;AACpC,8FAA2D;AAC3D,sFAAoD;AACpD,iDAA4C;AAc5C,SAAS,QAAQ,CAAC,UAA2B;IAC3C,OAAO,UAAU,CAAC,MAAM,CAAC,mBAAmB,CAAC,aAAa,CAAC;AAC7D,CAAC;AAEM,KAAK,UAAU,iBAAiB,CAAC,EACtC,UAAU,GAGX;IACC,IAAI,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;QACzB,OAAO;YACL,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,CAAC,MAAM,IAAA,2BAAY,GAAE,CAA8B;SAC9D,CAAC;IACJ,CAAC;IACD,OAAO;QACL,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,iBAAO;KAClB,CAAC;AACJ,CAAC;AAED,SAAgB,yBAAyB,CAAC,EACxC,cAAc,GAGf;IACC,IAAI,cAAc,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CACb,gEAAgE,cAAc,CAAC,IAAI,EAAE,CACtF,CAAC;IACJ,CAAC;IACD,OAAO,cAAc,CAAC,QAA6C,CAAC;AACtE,CAAC;AAEM,KAAK,UAAU,mBAAmB,CAAC,EACxC,cAAc,GAGf;IACC,IAAI,cAAc,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACrC,+CAA+C;QAC/C,OAAO,cAAc,CAAC,QAAQ,CAAC,sBAAsB,CAAC;IACxD,CAAC;IACD,OAAO,iCAAoB,CAAC;AAC9B,CAAC;AAEM,KAAK,UAAU,aAAa,CAAC,EAClC,cAAc,GAGf;IACC,IAAI,cAAc,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACrC,+CAA+C;QAC/C,OAAO,cAAc,CAAC,QAAQ,CAAC,gBAAgB,CAAC;IAClD,CAAC;IACD,OAAO,6BAAiB,CAAC;AAC3B,CAAC;AAEM,KAAK,UAAU,oBAAoB,CAAC,EACzC,cAAc,GAGf;IACC,IAAI,cAAc,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACrC,MAAM,0BAA2B,SAAQ,cAAc,CAAC,QAAQ;aAC7D,cAAc;YACf,YAAY,EAAC,IAAI,EAAiB;gBAChC,6BAA6B;gBAC7B,sEAAsE;gBACtE,yDAAyD;gBACzD,4DAA4D;gBAC5D,KAAK,CAAC,EAAC,MAAM,EAAE,IAAI,EAAC,CAAC,CAAC;YACxB,CAAC;SACF;QACD,OAAO,0BAA+C,CAAC;IACzD,CAAC;IAED,OAAO,oBAAU,CAAC;AACpB,CAAC"}
|
package/lib/importFaster.d.ts
CHANGED
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
import type { ConfigureWebpackUtils } from '@docusaurus/types';
|
|
8
8
|
import type { MinimizerOptions as JsMinimizerOptions, CustomOptions } from 'terser-webpack-plugin';
|
|
9
9
|
import type { MinimizerOptions as CssMinimizerOptions } from 'css-minimizer-webpack-plugin';
|
|
10
|
-
type FasterModule = Awaited<typeof import('@docusaurus/faster')>;
|
|
10
|
+
export type FasterModule = Awaited<typeof import('@docusaurus/faster')>;
|
|
11
|
+
export declare function importRspack(): Promise<FasterModule['rspack']>;
|
|
11
12
|
export declare function importSwcJsLoaderFactory(): Promise<ConfigureWebpackUtils['getJSLoader']>;
|
|
12
13
|
export declare function importSwcJsMinimizerOptions(): Promise<JsMinimizerOptions<CustomOptions>>;
|
|
13
14
|
export declare function importSwcHtmlMinifier(): Promise<ReturnType<FasterModule['getSwcHtmlMinifier']>>;
|
|
15
|
+
export declare function importBrowserslistQueries(): Promise<string[]>;
|
|
14
16
|
export declare function importLightningCssMinimizerOptions(): Promise<CssMinimizerOptions<CustomOptions>>;
|
|
15
|
-
export {};
|
|
16
17
|
//# sourceMappingURL=importFaster.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"importFaster.d.ts","sourceRoot":"","sources":["../src/importFaster.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,mBAAmB,CAAC;AAC7D,OAAO,KAAK,EACV,gBAAgB,IAAI,kBAAkB,EACtC,aAAa,EACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAC,gBAAgB,IAAI,mBAAmB,EAAC,MAAM,8BAA8B,CAAC;AAE1F,
|
|
1
|
+
{"version":3,"file":"importFaster.d.ts","sourceRoot":"","sources":["../src/importFaster.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,mBAAmB,CAAC;AAC7D,OAAO,KAAK,EACV,gBAAgB,IAAI,kBAAkB,EACtC,aAAa,EACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAC,gBAAgB,IAAI,mBAAmB,EAAC,MAAM,8BAA8B,CAAC;AAE1F,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC,cAAc,oBAAoB,CAAC,CAAC,CAAC;AAiBxE,wBAAsB,YAAY,IAAI,OAAO,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAGpE;AAED,wBAAsB,wBAAwB,IAAI,OAAO,CACvD,qBAAqB,CAAC,aAAa,CAAC,CACrC,CAGA;AAED,wBAAsB,2BAA2B,IAAI,OAAO,CAC1D,kBAAkB,CAAC,aAAa,CAAC,CAClC,CAGA;AAED,wBAAsB,qBAAqB,IAAI,OAAO,CACpD,UAAU,CAAC,YAAY,CAAC,oBAAoB,CAAC,CAAC,CAC/C,CAGA;AAED,wBAAsB,yBAAyB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAGnE;AAED,wBAAsB,kCAAkC,IAAI,OAAO,CACjE,mBAAmB,CAAC,aAAa,CAAC,CACnC,CAGA"}
|
package/lib/importFaster.js
CHANGED
|
@@ -6,9 +6,11 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.importRspack = importRspack;
|
|
9
10
|
exports.importSwcJsLoaderFactory = importSwcJsLoaderFactory;
|
|
10
11
|
exports.importSwcJsMinimizerOptions = importSwcJsMinimizerOptions;
|
|
11
12
|
exports.importSwcHtmlMinifier = importSwcHtmlMinifier;
|
|
13
|
+
exports.importBrowserslistQueries = importBrowserslistQueries;
|
|
12
14
|
exports.importLightningCssMinimizerOptions = importLightningCssMinimizerOptions;
|
|
13
15
|
async function importFaster() {
|
|
14
16
|
return import('@docusaurus/faster');
|
|
@@ -21,6 +23,10 @@ async function ensureFaster() {
|
|
|
21
23
|
throw new Error('Your Docusaurus site need to add the @docusaurus/faster package as a dependency.', { cause: error });
|
|
22
24
|
}
|
|
23
25
|
}
|
|
26
|
+
async function importRspack() {
|
|
27
|
+
const faster = await ensureFaster();
|
|
28
|
+
return faster.rspack;
|
|
29
|
+
}
|
|
24
30
|
async function importSwcJsLoaderFactory() {
|
|
25
31
|
const faster = await ensureFaster();
|
|
26
32
|
return faster.getSwcJsLoaderFactory;
|
|
@@ -33,6 +39,10 @@ async function importSwcHtmlMinifier() {
|
|
|
33
39
|
const faster = await ensureFaster();
|
|
34
40
|
return faster.getSwcHtmlMinifier();
|
|
35
41
|
}
|
|
42
|
+
async function importBrowserslistQueries() {
|
|
43
|
+
const faster = await ensureFaster();
|
|
44
|
+
return faster.getBrowserslistQueries();
|
|
45
|
+
}
|
|
36
46
|
async function importLightningCssMinimizerOptions() {
|
|
37
47
|
const faster = await ensureFaster();
|
|
38
48
|
return faster.getLightningCssMinimizerOptions();
|
package/lib/importFaster.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"importFaster.js","sourceRoot":"","sources":["../src/importFaster.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AA0BH,4DAKC;AAED,kEAKC;AAED,sDAKC;AAED,gFAKC;
|
|
1
|
+
{"version":3,"file":"importFaster.js","sourceRoot":"","sources":["../src/importFaster.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AA0BH,oCAGC;AAED,4DAKC;AAED,kEAKC;AAED,sDAKC;AAED,8DAGC;AAED,gFAKC;AAnDD,KAAK,UAAU,YAAY;IACzB,OAAO,MAAM,CAAC,oBAAoB,CAAC,CAAC;AACtC,CAAC;AAED,KAAK,UAAU,YAAY;IACzB,IAAI,CAAC;QACH,OAAO,MAAM,YAAY,EAAE,CAAC;IAC9B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,kFAAkF,EAClF,EAAC,KAAK,EAAE,KAAK,EAAC,CACf,CAAC;IACJ,CAAC;AACH,CAAC;AAEM,KAAK,UAAU,YAAY;IAChC,MAAM,MAAM,GAAG,MAAM,YAAY,EAAE,CAAC;IACpC,OAAO,MAAM,CAAC,MAAM,CAAC;AACvB,CAAC;AAEM,KAAK,UAAU,wBAAwB;IAG5C,MAAM,MAAM,GAAG,MAAM,YAAY,EAAE,CAAC;IACpC,OAAO,MAAM,CAAC,qBAAqB,CAAC;AACtC,CAAC;AAEM,KAAK,UAAU,2BAA2B;IAG/C,MAAM,MAAM,GAAG,MAAM,YAAY,EAAE,CAAC;IACpC,OAAO,MAAM,CAAC,wBAAwB,EAAuC,CAAC;AAChF,CAAC;AAEM,KAAK,UAAU,qBAAqB;IAGzC,MAAM,MAAM,GAAG,MAAM,YAAY,EAAE,CAAC;IACpC,OAAO,MAAM,CAAC,kBAAkB,EAAE,CAAC;AACrC,CAAC;AAEM,KAAK,UAAU,yBAAyB;IAC7C,MAAM,MAAM,GAAG,MAAM,YAAY,EAAE,CAAC;IACpC,OAAO,MAAM,CAAC,sBAAsB,EAAE,CAAC;AACzC,CAAC;AAEM,KAAK,UAAU,kCAAkC;IAGtD,MAAM,MAAM,GAAG,MAAM,YAAY,EAAE,CAAC;IACpC,OAAO,MAAM,CAAC,+BAA+B,EAAwC,CAAC;AACxF,CAAC"}
|
|
@@ -8,7 +8,7 @@ import type { ConfigureWebpackUtils, DocusaurusConfig } from '@docusaurus/types'
|
|
|
8
8
|
export declare function createJsLoaderFactory({ siteConfig, }: {
|
|
9
9
|
siteConfig: {
|
|
10
10
|
webpack?: DocusaurusConfig['webpack'];
|
|
11
|
-
future
|
|
11
|
+
future: {
|
|
12
12
|
experimental_faster: DocusaurusConfig['future']['experimental_faster'];
|
|
13
13
|
};
|
|
14
14
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsLoader.d.ts","sourceRoot":"","sources":["../../src/loaders/jsLoader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"jsLoader.d.ts","sourceRoot":"","sources":["../../src/loaders/jsLoader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAC,qBAAqB,EAAE,gBAAgB,EAAC,MAAM,mBAAmB,CAAC;AAkC/E,wBAAsB,qBAAqB,CAAC,EAC1C,UAAU,GACX,EAAE;IACD,UAAU,EAAE;QACV,OAAO,CAAC,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC;QACtC,MAAM,EAAE;YACN,mBAAmB,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAC,qBAAqB,CAAC,CAAC;SACxE,CAAC;KACH,CAAC;CACH,GAAG,OAAO,CAAC,qBAAqB,CAAC,aAAa,CAAC,CAAC,CA+BhD"}
|
package/lib/loaders/jsLoader.js
CHANGED
|
@@ -9,16 +9,43 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.createJsLoaderFactory = createJsLoaderFactory;
|
|
10
10
|
const babel_1 = require("@docusaurus/babel");
|
|
11
11
|
const importFaster_1 = require("../importFaster");
|
|
12
|
+
const currentBundler_1 = require("../currentBundler");
|
|
12
13
|
const BabelJsLoaderFactory = ({ isServer, babelOptions, }) => {
|
|
13
14
|
return {
|
|
14
15
|
loader: require.resolve('babel-loader'),
|
|
15
16
|
options: (0, babel_1.getBabelOptions)({ isServer, babelOptions }),
|
|
16
17
|
};
|
|
17
18
|
};
|
|
19
|
+
const RspackJsLoaderFactory = () => {
|
|
20
|
+
return {
|
|
21
|
+
loader: 'builtin:swc-loader',
|
|
22
|
+
options: {
|
|
23
|
+
jsc: {
|
|
24
|
+
parser: {
|
|
25
|
+
syntax: 'typescript',
|
|
26
|
+
tsx: true,
|
|
27
|
+
},
|
|
28
|
+
transform: {
|
|
29
|
+
react: {
|
|
30
|
+
runtime: 'automatic',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
};
|
|
18
37
|
// Confusing: function that creates a function that creates actual js loaders
|
|
19
38
|
// This is done on purpose because the js loader factory is a public API
|
|
20
39
|
// It is injected in configureWebpack plugin lifecycle for plugin authors
|
|
21
40
|
async function createJsLoaderFactory({ siteConfig, }) {
|
|
41
|
+
const currentBundler = await (0, currentBundler_1.getCurrentBundler)({ siteConfig });
|
|
42
|
+
const isSWCLoader = siteConfig.future.experimental_faster.swcJsLoader;
|
|
43
|
+
if (currentBundler.name === 'rspack') {
|
|
44
|
+
if (!isSWCLoader) {
|
|
45
|
+
throw new Error('When using Rspack bundler, it is required to enable swcJsLoader too');
|
|
46
|
+
}
|
|
47
|
+
return RspackJsLoaderFactory;
|
|
48
|
+
}
|
|
22
49
|
const jsLoader = siteConfig.webpack?.jsLoader ?? 'babel';
|
|
23
50
|
if (jsLoader instanceof Function &&
|
|
24
51
|
siteConfig.future?.experimental_faster.swcJsLoader) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsLoader.js","sourceRoot":"","sources":["../../src/loaders/jsLoader.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;
|
|
1
|
+
{"version":3,"file":"jsLoader.js","sourceRoot":"","sources":["../../src/loaders/jsLoader.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAuCH,sDAwCC;AA7ED,6CAAkD;AAClD,kDAAyD;AACzD,sDAAoD;AAGpD,MAAM,oBAAoB,GAAyC,CAAC,EAClE,QAAQ,EACR,YAAY,GACb,EAAE,EAAE;IACH,OAAO;QACL,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC;QACvC,OAAO,EAAE,IAAA,uBAAe,EAAC,EAAC,QAAQ,EAAE,YAAY,EAAC,CAAC;KACnD,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,qBAAqB,GAAyC,GAAG,EAAE;IACvE,OAAO;QACL,MAAM,EAAE,oBAAoB;QAC5B,OAAO,EAAE;YACP,GAAG,EAAE;gBACH,MAAM,EAAE;oBACN,MAAM,EAAE,YAAY;oBACpB,GAAG,EAAE,IAAI;iBACV;gBACD,SAAS,EAAE;oBACT,KAAK,EAAE;wBACL,OAAO,EAAE,WAAW;qBACrB;iBACF;aACF;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,6EAA6E;AAC7E,wEAAwE;AACxE,yEAAyE;AAClE,KAAK,UAAU,qBAAqB,CAAC,EAC1C,UAAU,GAQX;IACC,MAAM,cAAc,GAAG,MAAM,IAAA,kCAAiB,EAAC,EAAC,UAAU,EAAC,CAAC,CAAC;IAC7D,MAAM,WAAW,GAAG,UAAU,CAAC,MAAM,CAAC,mBAAmB,CAAC,WAAW,CAAC;IAEtE,IAAI,cAAc,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACrC,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CACb,qEAAqE,CACtE,CAAC;QACJ,CAAC;QACD,OAAO,qBAAqB,CAAC;IAC/B,CAAC;IACD,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,EAAE,QAAQ,IAAI,OAAO,CAAC;IACzD,IACE,QAAQ,YAAY,QAAQ;QAC5B,UAAU,CAAC,MAAM,EAAE,mBAAmB,CAAC,WAAW,EAClD,CAAC;QACD,MAAM,IAAI,KAAK,CACb,8FAA8F,CAC/F,CAAC;IACJ,CAAC;IACD,IAAI,QAAQ,YAAY,QAAQ,EAAE,CAAC;QACjC,OAAO,CAAC,EAAC,QAAQ,EAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC5C,CAAC;IACD,IAAI,UAAU,CAAC,MAAM,EAAE,mBAAmB,CAAC,WAAW,EAAE,CAAC;QACvD,OAAO,IAAA,uCAAwB,GAAE,CAAC;IACpC,CAAC;IACD,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;QACzB,OAAO,oBAAoB,CAAC;IAC9B,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,4CAA4C,QAAQ,EAAE,CAAC,CAAC;AAC1E,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"minification.d.ts","sourceRoot":"","sources":["../src/minification.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"minification.d.ts","sourceRoot":"","sources":["../src/minification.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAWH,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,SAAS,CAAC;AACnD,OAAO,KAAK,EAAC,cAAc,EAAE,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAEpE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,gBAAgB,GAAG,uBAAuB,CAAC,CAAC;IACvE,cAAc,EAAE,cAAc,CAAC;CAChC,CAAC;AAkJF,wBAAsB,aAAa,CACjC,MAAM,EAAE,gBAAgB,GACvB,OAAO,CAAC,qBAAqB,EAAE,CAAC,CAIlC"}
|
package/lib/minification.js
CHANGED
|
@@ -11,6 +11,7 @@ const tslib_1 = require("tslib");
|
|
|
11
11
|
const terser_webpack_plugin_1 = tslib_1.__importDefault(require("terser-webpack-plugin"));
|
|
12
12
|
const css_minimizer_webpack_plugin_1 = tslib_1.__importDefault(require("css-minimizer-webpack-plugin"));
|
|
13
13
|
const importFaster_1 = require("./importFaster");
|
|
14
|
+
const currentBundler_1 = require("./currentBundler");
|
|
14
15
|
// See https://github.com/webpack-contrib/terser-webpack-plugin#parallel
|
|
15
16
|
function getTerserParallel() {
|
|
16
17
|
let terserParallel = true;
|
|
@@ -34,6 +35,7 @@ async function getJsMinimizer({ faster, }) {
|
|
|
34
35
|
}
|
|
35
36
|
return new terser_webpack_plugin_1.default({
|
|
36
37
|
parallel: getTerserParallel(),
|
|
38
|
+
// See https://terser.org/docs/options/
|
|
37
39
|
terserOptions: {
|
|
38
40
|
parse: {
|
|
39
41
|
// We want uglify-js to parse ecma 8 code. However, we don't want it
|
|
@@ -111,8 +113,30 @@ async function getWebpackMinimizers(params) {
|
|
|
111
113
|
return Promise.all([getJsMinimizer(params), getCssMinimizer(params)]);
|
|
112
114
|
}
|
|
113
115
|
async function getRspackMinimizers({ currentBundler, }) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
+
const rspack = (0, currentBundler_1.getCurrentBundlerAsRspack)({ currentBundler });
|
|
117
|
+
const browserslistQueries = await (0, importFaster_1.importBrowserslistQueries)();
|
|
118
|
+
const swcJsMinimizerOptions = await (0, importFaster_1.importSwcJsMinimizerOptions)();
|
|
119
|
+
return [
|
|
120
|
+
// See https://rspack.dev/plugins/rspack/swc-js-minimizer-rspack-plugin
|
|
121
|
+
// See https://swc.rs/docs/configuration/minification
|
|
122
|
+
new rspack.SwcJsMinimizerRspackPlugin({
|
|
123
|
+
minimizerOptions: {
|
|
124
|
+
minify: true,
|
|
125
|
+
...swcJsMinimizerOptions,
|
|
126
|
+
},
|
|
127
|
+
}),
|
|
128
|
+
new rspack.LightningCssMinimizerRspackPlugin({
|
|
129
|
+
minimizerOptions: {
|
|
130
|
+
...(await (0, importFaster_1.importLightningCssMinimizerOptions)()),
|
|
131
|
+
// Not sure why but Rspack takes browserslist queries directly
|
|
132
|
+
// While LightningCSS targets are normally not browserslist queries
|
|
133
|
+
// We have to override the option to avoid errors
|
|
134
|
+
// See https://rspack.dev/plugins/rspack/lightning-css-minimizer-rspack-plugin#minimizeroptions
|
|
135
|
+
// See https://lightningcss.dev/transpilation.html
|
|
136
|
+
targets: browserslistQueries,
|
|
137
|
+
},
|
|
138
|
+
}),
|
|
139
|
+
];
|
|
116
140
|
}
|
|
117
141
|
async function getMinimizers(params) {
|
|
118
142
|
return params.currentBundler.name === 'rspack'
|
package/lib/minification.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"minification.js","sourceRoot":"","sources":["../src/minification.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;
|
|
1
|
+
{"version":3,"file":"minification.js","sourceRoot":"","sources":["../src/minification.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/bundler",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-6101",
|
|
4
4
|
"description": "Docusaurus util package to abstract the current bundler.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -19,12 +19,11 @@
|
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@babel/core": "^7.23.3",
|
|
22
|
-
"@docusaurus/babel": "0.0.0-
|
|
23
|
-
"@docusaurus/cssnano-preset": "0.0.0-
|
|
24
|
-
"@docusaurus/
|
|
25
|
-
"@docusaurus/
|
|
26
|
-
"@docusaurus/
|
|
27
|
-
"@docusaurus/utils": "0.0.0-6098",
|
|
22
|
+
"@docusaurus/babel": "0.0.0-6101",
|
|
23
|
+
"@docusaurus/cssnano-preset": "0.0.0-6101",
|
|
24
|
+
"@docusaurus/logger": "0.0.0-6101",
|
|
25
|
+
"@docusaurus/types": "0.0.0-6101",
|
|
26
|
+
"@docusaurus/utils": "0.0.0-6101",
|
|
28
27
|
"autoprefixer": "^10.4.14",
|
|
29
28
|
"babel-loader": "^9.1.3",
|
|
30
29
|
"clean-css": "^5.3.2",
|
|
@@ -45,11 +44,19 @@
|
|
|
45
44
|
"webpack": "^5.95.0",
|
|
46
45
|
"webpackbar": "^6.0.1"
|
|
47
46
|
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"@docusaurus/faster": "3.5.2"
|
|
49
|
+
},
|
|
50
|
+
"peerDependenciesMeta": {
|
|
51
|
+
"@docusaurus/faster": {
|
|
52
|
+
"optional": true
|
|
53
|
+
}
|
|
54
|
+
},
|
|
48
55
|
"devDependencies": {
|
|
49
56
|
"@total-typescript/shoehorn": "^0.1.2"
|
|
50
57
|
},
|
|
51
58
|
"engines": {
|
|
52
59
|
"node": ">=18.0"
|
|
53
60
|
},
|
|
54
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "16bade8e806ebfd77603c2e52d06a0208843122e"
|
|
55
62
|
}
|
package/src/currentBundler.ts
CHANGED
|
@@ -9,7 +9,8 @@ import webpack from 'webpack';
|
|
|
9
9
|
import WebpackBar from 'webpackbar';
|
|
10
10
|
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
11
11
|
import CopyWebpackPlugin from 'copy-webpack-plugin';
|
|
12
|
-
import
|
|
12
|
+
import {importRspack} from './importFaster';
|
|
13
|
+
import type {FasterModule} from './importFaster';
|
|
13
14
|
import type {CurrentBundler, DocusaurusConfig} from '@docusaurus/types';
|
|
14
15
|
|
|
15
16
|
// We inject a site config slice because the Rspack flag might change place
|
|
@@ -32,10 +33,10 @@ export async function getCurrentBundler({
|
|
|
32
33
|
siteConfig: SiteConfigSlice;
|
|
33
34
|
}): Promise<CurrentBundler> {
|
|
34
35
|
if (isRspack(siteConfig)) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
return {
|
|
37
|
+
name: 'rspack',
|
|
38
|
+
instance: (await importRspack()) as unknown as typeof webpack,
|
|
39
|
+
};
|
|
39
40
|
}
|
|
40
41
|
return {
|
|
41
42
|
name: 'webpack',
|
|
@@ -43,13 +44,27 @@ export async function getCurrentBundler({
|
|
|
43
44
|
};
|
|
44
45
|
}
|
|
45
46
|
|
|
47
|
+
export function getCurrentBundlerAsRspack({
|
|
48
|
+
currentBundler,
|
|
49
|
+
}: {
|
|
50
|
+
currentBundler: CurrentBundler;
|
|
51
|
+
}): FasterModule['rspack'] {
|
|
52
|
+
if (currentBundler.name !== 'rspack') {
|
|
53
|
+
throw new Error(
|
|
54
|
+
`Can't getCurrentBundlerAsRspack() because current bundler is ${currentBundler.name}`,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
return currentBundler.instance as unknown as FasterModule['rspack'];
|
|
58
|
+
}
|
|
59
|
+
|
|
46
60
|
export async function getCSSExtractPlugin({
|
|
47
61
|
currentBundler,
|
|
48
62
|
}: {
|
|
49
63
|
currentBundler: CurrentBundler;
|
|
50
64
|
}): Promise<typeof MiniCssExtractPlugin> {
|
|
51
65
|
if (currentBundler.name === 'rspack') {
|
|
52
|
-
|
|
66
|
+
// @ts-expect-error: this exists only in Rspack
|
|
67
|
+
return currentBundler.instance.CssExtractRspackPlugin;
|
|
53
68
|
}
|
|
54
69
|
return MiniCssExtractPlugin;
|
|
55
70
|
}
|
|
@@ -60,9 +75,9 @@ export async function getCopyPlugin({
|
|
|
60
75
|
currentBundler: CurrentBundler;
|
|
61
76
|
}): Promise<typeof CopyWebpackPlugin> {
|
|
62
77
|
if (currentBundler.name === 'rspack') {
|
|
63
|
-
|
|
78
|
+
// @ts-expect-error: this exists only in Rspack
|
|
79
|
+
return currentBundler.instance.CopyRspackPlugin;
|
|
64
80
|
}
|
|
65
|
-
// https://github.com/webpack-contrib/copy-webpack-plugin
|
|
66
81
|
return CopyWebpackPlugin;
|
|
67
82
|
}
|
|
68
83
|
|
package/src/importFaster.ts
CHANGED
|
@@ -12,7 +12,7 @@ import type {
|
|
|
12
12
|
} from 'terser-webpack-plugin';
|
|
13
13
|
import type {MinimizerOptions as CssMinimizerOptions} from 'css-minimizer-webpack-plugin';
|
|
14
14
|
|
|
15
|
-
type FasterModule = Awaited<typeof import('@docusaurus/faster')>;
|
|
15
|
+
export type FasterModule = Awaited<typeof import('@docusaurus/faster')>;
|
|
16
16
|
|
|
17
17
|
async function importFaster(): Promise<FasterModule> {
|
|
18
18
|
return import('@docusaurus/faster');
|
|
@@ -29,6 +29,11 @@ async function ensureFaster(): Promise<FasterModule> {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
export async function importRspack(): Promise<FasterModule['rspack']> {
|
|
33
|
+
const faster = await ensureFaster();
|
|
34
|
+
return faster.rspack;
|
|
35
|
+
}
|
|
36
|
+
|
|
32
37
|
export async function importSwcJsLoaderFactory(): Promise<
|
|
33
38
|
ConfigureWebpackUtils['getJSLoader']
|
|
34
39
|
> {
|
|
@@ -50,6 +55,11 @@ export async function importSwcHtmlMinifier(): Promise<
|
|
|
50
55
|
return faster.getSwcHtmlMinifier();
|
|
51
56
|
}
|
|
52
57
|
|
|
58
|
+
export async function importBrowserslistQueries(): Promise<string[]> {
|
|
59
|
+
const faster = await ensureFaster();
|
|
60
|
+
return faster.getBrowserslistQueries();
|
|
61
|
+
}
|
|
62
|
+
|
|
53
63
|
export async function importLightningCssMinimizerOptions(): Promise<
|
|
54
64
|
CssMinimizerOptions<CustomOptions>
|
|
55
65
|
> {
|
package/src/loaders/jsLoader.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import {getBabelOptions} from '@docusaurus/babel';
|
|
9
9
|
import {importSwcJsLoaderFactory} from '../importFaster';
|
|
10
|
+
import {getCurrentBundler} from '../currentBundler';
|
|
10
11
|
import type {ConfigureWebpackUtils, DocusaurusConfig} from '@docusaurus/types';
|
|
11
12
|
|
|
12
13
|
const BabelJsLoaderFactory: ConfigureWebpackUtils['getJSLoader'] = ({
|
|
@@ -19,6 +20,25 @@ const BabelJsLoaderFactory: ConfigureWebpackUtils['getJSLoader'] = ({
|
|
|
19
20
|
};
|
|
20
21
|
};
|
|
21
22
|
|
|
23
|
+
const RspackJsLoaderFactory: ConfigureWebpackUtils['getJSLoader'] = () => {
|
|
24
|
+
return {
|
|
25
|
+
loader: 'builtin:swc-loader',
|
|
26
|
+
options: {
|
|
27
|
+
jsc: {
|
|
28
|
+
parser: {
|
|
29
|
+
syntax: 'typescript',
|
|
30
|
+
tsx: true,
|
|
31
|
+
},
|
|
32
|
+
transform: {
|
|
33
|
+
react: {
|
|
34
|
+
runtime: 'automatic',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
22
42
|
// Confusing: function that creates a function that creates actual js loaders
|
|
23
43
|
// This is done on purpose because the js loader factory is a public API
|
|
24
44
|
// It is injected in configureWebpack plugin lifecycle for plugin authors
|
|
@@ -27,11 +47,22 @@ export async function createJsLoaderFactory({
|
|
|
27
47
|
}: {
|
|
28
48
|
siteConfig: {
|
|
29
49
|
webpack?: DocusaurusConfig['webpack'];
|
|
30
|
-
future
|
|
50
|
+
future: {
|
|
31
51
|
experimental_faster: DocusaurusConfig['future']['experimental_faster'];
|
|
32
52
|
};
|
|
33
53
|
};
|
|
34
54
|
}): Promise<ConfigureWebpackUtils['getJSLoader']> {
|
|
55
|
+
const currentBundler = await getCurrentBundler({siteConfig});
|
|
56
|
+
const isSWCLoader = siteConfig.future.experimental_faster.swcJsLoader;
|
|
57
|
+
|
|
58
|
+
if (currentBundler.name === 'rspack') {
|
|
59
|
+
if (!isSWCLoader) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
'When using Rspack bundler, it is required to enable swcJsLoader too',
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
return RspackJsLoaderFactory;
|
|
65
|
+
}
|
|
35
66
|
const jsLoader = siteConfig.webpack?.jsLoader ?? 'babel';
|
|
36
67
|
if (
|
|
37
68
|
jsLoader instanceof Function &&
|
package/src/minification.ts
CHANGED
|
@@ -10,7 +10,9 @@ import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
|
|
|
10
10
|
import {
|
|
11
11
|
importSwcJsMinimizerOptions,
|
|
12
12
|
importLightningCssMinimizerOptions,
|
|
13
|
+
importBrowserslistQueries,
|
|
13
14
|
} from './importFaster';
|
|
15
|
+
import {getCurrentBundlerAsRspack} from './currentBundler';
|
|
14
16
|
import type {CustomOptions, CssNanoOptions} from 'css-minimizer-webpack-plugin';
|
|
15
17
|
import type {WebpackPluginInstance} from 'webpack';
|
|
16
18
|
import type {CurrentBundler, FasterConfig} from '@docusaurus/types';
|
|
@@ -48,6 +50,7 @@ async function getJsMinimizer({
|
|
|
48
50
|
|
|
49
51
|
return new TerserPlugin({
|
|
50
52
|
parallel: getTerserParallel(),
|
|
53
|
+
// See https://terser.org/docs/options/
|
|
51
54
|
terserOptions: {
|
|
52
55
|
parse: {
|
|
53
56
|
// We want uglify-js to parse ecma 8 code. However, we don't want it
|
|
@@ -137,8 +140,30 @@ async function getWebpackMinimizers(
|
|
|
137
140
|
async function getRspackMinimizers({
|
|
138
141
|
currentBundler,
|
|
139
142
|
}: MinimizersConfig): Promise<WebpackPluginInstance[]> {
|
|
140
|
-
|
|
141
|
-
|
|
143
|
+
const rspack = getCurrentBundlerAsRspack({currentBundler});
|
|
144
|
+
const browserslistQueries = await importBrowserslistQueries();
|
|
145
|
+
const swcJsMinimizerOptions = await importSwcJsMinimizerOptions();
|
|
146
|
+
return [
|
|
147
|
+
// See https://rspack.dev/plugins/rspack/swc-js-minimizer-rspack-plugin
|
|
148
|
+
// See https://swc.rs/docs/configuration/minification
|
|
149
|
+
new rspack.SwcJsMinimizerRspackPlugin({
|
|
150
|
+
minimizerOptions: {
|
|
151
|
+
minify: true,
|
|
152
|
+
...swcJsMinimizerOptions,
|
|
153
|
+
},
|
|
154
|
+
}),
|
|
155
|
+
new rspack.LightningCssMinimizerRspackPlugin({
|
|
156
|
+
minimizerOptions: {
|
|
157
|
+
...(await importLightningCssMinimizerOptions()),
|
|
158
|
+
// Not sure why but Rspack takes browserslist queries directly
|
|
159
|
+
// While LightningCSS targets are normally not browserslist queries
|
|
160
|
+
// We have to override the option to avoid errors
|
|
161
|
+
// See https://rspack.dev/plugins/rspack/lightning-css-minimizer-rspack-plugin#minimizeroptions
|
|
162
|
+
// See https://lightningcss.dev/transpilation.html
|
|
163
|
+
targets: browserslistQueries,
|
|
164
|
+
},
|
|
165
|
+
}),
|
|
166
|
+
] as unknown as WebpackPluginInstance[];
|
|
142
167
|
}
|
|
143
168
|
|
|
144
169
|
export async function getMinimizers(
|