@docusaurus/bundler 3.5.2

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/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # `@docusaurus/bundler`
2
+
3
+ Docusaurus util package to abstract the current bundler.
package/lib/index.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import WebpackBar from 'webpackbar';
8
+ import MiniCssExtractPlugin from 'mini-css-extract-plugin';
9
+ import CopyWebpackPlugin from 'copy-webpack-plugin';
10
+ import type { CurrentBundler, DocusaurusConfig } from '@docusaurus/types';
11
+ type SiteConfigSlice = {
12
+ future: {
13
+ experimental_faster: Pick<DocusaurusConfig['future']['experimental_faster'], 'rspackBundler'>;
14
+ };
15
+ };
16
+ export declare function getCurrentBundler({ siteConfig, }: {
17
+ siteConfig: SiteConfigSlice;
18
+ }): Promise<CurrentBundler>;
19
+ export declare function getCSSExtractPlugin({ currentBundler, }: {
20
+ currentBundler: CurrentBundler;
21
+ }): Promise<typeof MiniCssExtractPlugin>;
22
+ export declare function getCopyPlugin({ currentBundler, }: {
23
+ currentBundler: CurrentBundler;
24
+ }): Promise<typeof CopyWebpackPlugin>;
25
+ export declare function getProgressBarPlugin({ currentBundler, }: {
26
+ currentBundler: CurrentBundler;
27
+ }): Promise<typeof WebpackBar>;
28
+ export {};
29
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.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,CAKvC;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/index.js ADDED
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.getCurrentBundler = getCurrentBundler;
10
+ exports.getCSSExtractPlugin = getCSSExtractPlugin;
11
+ exports.getCopyPlugin = getCopyPlugin;
12
+ exports.getProgressBarPlugin = getProgressBarPlugin;
13
+ const tslib_1 = require("tslib");
14
+ const webpack_1 = tslib_1.__importDefault(require("webpack"));
15
+ const webpackbar_1 = tslib_1.__importDefault(require("webpackbar"));
16
+ const mini_css_extract_plugin_1 = tslib_1.__importDefault(require("mini-css-extract-plugin"));
17
+ const copy_webpack_plugin_1 = tslib_1.__importDefault(require("copy-webpack-plugin"));
18
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
19
+ function isRspack(siteConfig) {
20
+ return siteConfig.future.experimental_faster.rspackBundler;
21
+ }
22
+ async function getCurrentBundler({ siteConfig, }) {
23
+ if (isRspack(siteConfig)) {
24
+ // TODO add support for Rspack
25
+ logger_1.default.error('Rspack bundler is not supported yet, will use Webpack instead');
26
+ }
27
+ return {
28
+ name: 'webpack',
29
+ instance: webpack_1.default,
30
+ };
31
+ }
32
+ async function getCSSExtractPlugin({ currentBundler, }) {
33
+ if (currentBundler.name === 'rspack') {
34
+ throw new Error('Rspack bundler is not supported yet');
35
+ }
36
+ return mini_css_extract_plugin_1.default;
37
+ }
38
+ async function getCopyPlugin({ currentBundler, }) {
39
+ if (currentBundler.name === 'rspack') {
40
+ throw new Error('Rspack bundler is not supported yet');
41
+ }
42
+ // https://github.com/webpack-contrib/copy-webpack-plugin
43
+ return copy_webpack_plugin_1.default;
44
+ }
45
+ async function getProgressBarPlugin({ currentBundler, }) {
46
+ if (currentBundler.name === 'rspack') {
47
+ class CustomRspackProgressPlugin extends currentBundler.instance
48
+ .ProgressPlugin {
49
+ constructor({ name }) {
50
+ // TODO add support for color
51
+ // Unfortunately the rspack.ProgressPlugin does not have a name option
52
+ // See https://rspack.dev/plugins/webpack/progress-plugin
53
+ // @ts-expect-error: adapt Rspack ProgressPlugin constructor
54
+ super({ prefix: name });
55
+ }
56
+ }
57
+ return CustomRspackProgressPlugin;
58
+ }
59
+ return webpackbar_1.default;
60
+ }
61
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAuBH,8CAeC;AAED,kDASC;AAED,sCAUC;AAED,oDAoBC;;AAjFD,8DAA8B;AAC9B,oEAAoC;AACpC,8FAA2D;AAC3D,sFAAoD;AACpD,wEAAwC;AAaxC,SAA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 {
2
+ "name": "@docusaurus/bundler",
3
+ "version": "3.5.2",
4
+ "description": "Docusaurus util package to abstract the current bundler.",
5
+ "main": "./lib/index.js",
6
+ "types": "./lib/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "watch": "tsc --watch"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/facebook/docusaurus.git",
17
+ "directory": "packages/docusaurus-bundler"
18
+ },
19
+ "license": "MIT",
20
+ "dependencies": {
21
+ "@docusaurus/logger": "3.5.2",
22
+ "@docusaurus/types": "3.5.2",
23
+ "copy-webpack-plugin": "^11.0.0",
24
+ "mini-css-extract-plugin": "^2.9.1",
25
+ "tslib": "^2.6.0",
26
+ "webpack": "^5.88.1",
27
+ "webpackbar": "^6.0.1"
28
+ },
29
+ "engines": {
30
+ "node": ">=18.0"
31
+ }
32
+ }
package/src/index.ts ADDED
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import webpack from 'webpack';
9
+ import WebpackBar from 'webpackbar';
10
+ import MiniCssExtractPlugin from 'mini-css-extract-plugin';
11
+ import CopyWebpackPlugin from 'copy-webpack-plugin';
12
+ import logger from '@docusaurus/logger';
13
+ import type {CurrentBundler, DocusaurusConfig} from '@docusaurus/types';
14
+
15
+ // We inject a site config slice because the Rspack flag might change place
16
+ type SiteConfigSlice = {
17
+ future: {
18
+ experimental_faster: Pick<
19
+ DocusaurusConfig['future']['experimental_faster'],
20
+ 'rspackBundler'
21
+ >;
22
+ };
23
+ };
24
+
25
+ function isRspack(siteConfig: SiteConfigSlice): boolean {
26
+ return siteConfig.future.experimental_faster.rspackBundler;
27
+ }
28
+
29
+ export async function getCurrentBundler({
30
+ siteConfig,
31
+ }: {
32
+ siteConfig: SiteConfigSlice;
33
+ }): Promise<CurrentBundler> {
34
+ if (isRspack(siteConfig)) {
35
+ // TODO add support for Rspack
36
+ logger.error(
37
+ 'Rspack bundler is not supported yet, will use Webpack instead',
38
+ );
39
+ }
40
+ return {
41
+ name: 'webpack',
42
+ instance: webpack,
43
+ };
44
+ }
45
+
46
+ export async function getCSSExtractPlugin({
47
+ currentBundler,
48
+ }: {
49
+ currentBundler: CurrentBundler;
50
+ }): Promise<typeof MiniCssExtractPlugin> {
51
+ if (currentBundler.name === 'rspack') {
52
+ throw new Error('Rspack bundler is not supported yet');
53
+ }
54
+ return MiniCssExtractPlugin;
55
+ }
56
+
57
+ export async function getCopyPlugin({
58
+ currentBundler,
59
+ }: {
60
+ currentBundler: CurrentBundler;
61
+ }): Promise<typeof CopyWebpackPlugin> {
62
+ if (currentBundler.name === 'rspack') {
63
+ throw new Error('Rspack bundler is not supported yet');
64
+ }
65
+ // https://github.com/webpack-contrib/copy-webpack-plugin
66
+ return CopyWebpackPlugin;
67
+ }
68
+
69
+ export async function getProgressBarPlugin({
70
+ currentBundler,
71
+ }: {
72
+ currentBundler: CurrentBundler;
73
+ }): Promise<typeof WebpackBar> {
74
+ if (currentBundler.name === 'rspack') {
75
+ class CustomRspackProgressPlugin extends currentBundler.instance
76
+ .ProgressPlugin {
77
+ constructor({name}: {name: string}) {
78
+ // TODO add support for color
79
+ // Unfortunately the rspack.ProgressPlugin does not have a name option
80
+ // See https://rspack.dev/plugins/webpack/progress-plugin
81
+ // @ts-expect-error: adapt Rspack ProgressPlugin constructor
82
+ super({prefix: name});
83
+ }
84
+ }
85
+ return CustomRspackProgressPlugin as typeof WebpackBar;
86
+ }
87
+
88
+ return WebpackBar;
89
+ }