@docusaurus/bundler 0.0.0-6082

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Facebook, Inc. and its affiliates.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # `@docusaurus/bundler`
2
+
3
+ Docusaurus util package to abstract the current bundler.
@@ -0,0 +1,22 @@
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 { type Configuration } from 'webpack';
8
+ import type webpack from 'webpack';
9
+ import type { CurrentBundler } from '@docusaurus/types';
10
+ export declare function formatStatsErrorMessage(statsJson: ReturnType<webpack.Stats['toJson']> | undefined): string | undefined;
11
+ export declare function printStatsWarnings(statsJson: ReturnType<webpack.Stats['toJson']> | undefined): void;
12
+ declare global {
13
+ interface Error {
14
+ /** @see https://webpack.js.org/api/node/#error-handling */
15
+ details?: unknown;
16
+ }
17
+ }
18
+ export declare function compile({ configs, currentBundler, }: {
19
+ configs: Configuration[];
20
+ currentBundler: CurrentBundler;
21
+ }): Promise<webpack.MultiStats>;
22
+ //# sourceMappingURL=compiler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,KAAK,aAAa,EAAC,MAAM,SAAS,CAAC;AAG3C,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AAEtD,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,GAAG,SAAS,GACzD,MAAM,GAAG,SAAS,CAWpB;AAED,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,GAAG,SAAS,GACzD,IAAI,CAMN;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK;QACb,2DAA2D;QAC3D,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB;CACF;AAED,wBAAgB,OAAO,CAAC,EACtB,OAAO,EACP,cAAc,GACf,EAAE;IACD,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,cAAc,EAAE,cAAc,CAAC;CAChC,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAmC9B"}
@@ -0,0 +1,66 @@
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.formatStatsErrorMessage = formatStatsErrorMessage;
10
+ exports.printStatsWarnings = printStatsWarnings;
11
+ exports.compile = compile;
12
+ const tslib_1 = require("tslib");
13
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
14
+ const formatWebpackMessages_1 = tslib_1.__importDefault(require("react-dev-utils/formatWebpackMessages"));
15
+ function formatStatsErrorMessage(statsJson) {
16
+ if (statsJson?.errors?.length) {
17
+ // TODO formatWebpackMessages does not print stack-traces
18
+ // Also the error causal chain is lost here
19
+ // We log the stacktrace inside serverEntry.tsx for now (not ideal)
20
+ const { errors } = (0, formatWebpackMessages_1.default)(statsJson);
21
+ return errors
22
+ .map((str) => logger_1.default.red(str))
23
+ .join(`\n\n${logger_1.default.yellow('--------------------------')}\n\n`);
24
+ }
25
+ return undefined;
26
+ }
27
+ function printStatsWarnings(statsJson) {
28
+ if (statsJson?.warnings?.length) {
29
+ statsJson.warnings?.forEach((warning) => {
30
+ logger_1.default.warn(warning);
31
+ });
32
+ }
33
+ }
34
+ function compile({ configs, currentBundler, }) {
35
+ return new Promise((resolve, reject) => {
36
+ const compiler = currentBundler.instance(configs);
37
+ compiler.run((err, stats) => {
38
+ if (err) {
39
+ logger_1.default.error(err.stack ?? err);
40
+ if (err.details) {
41
+ logger_1.default.error(err.details);
42
+ }
43
+ reject(err);
44
+ }
45
+ // Let plugins consume all the stats
46
+ const errorsWarnings = stats?.toJson('errors-warnings');
47
+ if (stats?.hasErrors()) {
48
+ const statsErrorMessage = formatStatsErrorMessage(errorsWarnings);
49
+ reject(new Error(`Failed to compile due to Webpack errors.\n${statsErrorMessage}`));
50
+ }
51
+ printStatsWarnings(errorsWarnings);
52
+ // Webpack 5 requires calling close() so that persistent caching works
53
+ // See https://github.com/webpack/webpack.js.org/pull/4775
54
+ compiler.close((errClose) => {
55
+ if (errClose) {
56
+ logger_1.default.error(`Error while closing Webpack compiler: ${errClose}`);
57
+ reject(errClose);
58
+ }
59
+ else {
60
+ resolve(stats);
61
+ }
62
+ });
63
+ });
64
+ });
65
+ }
66
+ //# sourceMappingURL=compiler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiler.js","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAQH,0DAaC;AAED,gDAQC;AASD,0BAyCC;;AA9ED,wEAAwC;AACxC,0GAA0E;AAI1E,SAAgB,uBAAuB,CACrC,SAA0D;IAE1D,IAAI,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;QAC9B,yDAAyD;QACzD,2CAA2C;QAC3C,mEAAmE;QACnE,MAAM,EAAC,MAAM,EAAC,GAAG,IAAA,+BAAqB,EAAC,SAAS,CAAC,CAAC;QAClD,OAAO,MAAM;aACV,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,gBAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;aAC7B,IAAI,CAAC,OAAO,gBAAM,CAAC,MAAM,CAAC,4BAA4B,CAAC,MAAM,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAgB,kBAAkB,CAChC,SAA0D;IAE1D,IAAI,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;QAChC,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YACtC,gBAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AASD,SAAgB,OAAO,CAAC,EACtB,OAAO,EACP,cAAc,GAIf;IACC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,QAAQ,GAAG,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAClD,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;YAC1B,IAAI,GAAG,EAAE,CAAC;gBACR,gBAAM,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,CAAC;gBAC/B,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;oBAChB,gBAAM,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;gBAC5B,CAAC;gBACD,MAAM,CAAC,GAAG,CAAC,CAAC;YACd,CAAC;YACD,oCAAoC;YACpC,MAAM,cAAc,GAAG,KAAK,EAAE,MAAM,CAAC,iBAAiB,CAAC,CAAC;YACxD,IAAI,KAAK,EAAE,SAAS,EAAE,EAAE,CAAC;gBACvB,MAAM,iBAAiB,GAAG,uBAAuB,CAAC,cAAc,CAAC,CAAC;gBAClE,MAAM,CACJ,IAAI,KAAK,CACP,6CAA6C,iBAAiB,EAAE,CACjE,CACF,CAAC;YACJ,CAAC;YACD,kBAAkB,CAAC,cAAc,CAAC,CAAC;YAEnC,sEAAsE;YACtE,0DAA0D;YAC1D,QAAQ,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,EAAE;gBAC1B,IAAI,QAAQ,EAAE,CAAC;oBACb,gBAAM,CAAC,KAAK,CAAC,yCAAyC,QAAQ,EAAE,CAAC,CAAC;oBAClE,MAAM,CAAC,QAAQ,CAAC,CAAC;gBACnB,CAAC;qBAAM,CAAC;oBACN,OAAO,CAAC,KAAM,CAAC,CAAC;gBAClB,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -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=currentBundler.d.ts.map
@@ -0,0 +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,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"}
@@ -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=currentBundler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"currentBundler.js","sourceRoot":"","sources":["../src/currentBundler.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAuBH,8CAeC;AAED,kDASC;AAED,sCAUC;AAED,oDAoBC;;AAjFD,8DAA8B;AAC9B,oEAAoC;AACpC,8FAA2D;AAC3D,sFAAoD;AACpD,wEAAwC;AAaxC,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,8BAA8B;QAC9B,gBAAM,CAAC,KAAK,CACV,+DAA+D,CAChE,CAAC;IACJ,CAAC;IACD,OAAO;QACL,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,iBAAO;KAClB,CAAC;AACJ,CAAC;AAEM,KAAK,UAAU,mBAAmB,CAAC,EACxC,cAAc,GAGf;IACC,IAAI,cAAc,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACzD,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,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACzD,CAAC;IACD,yDAAyD;IACzD,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"}
@@ -0,0 +1,11 @@
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 type { ConfigureWebpackUtils } from '@docusaurus/types';
8
+ import type { MinimizerOptions, CustomOptions } from 'terser-webpack-plugin';
9
+ export declare function importSwcJsLoaderFactory(): Promise<ConfigureWebpackUtils['getJSLoader']>;
10
+ export declare function importSwcJsMinifierOptions(): Promise<MinimizerOptions<CustomOptions>>;
11
+ //# sourceMappingURL=importFaster.d.ts.map
@@ -0,0 +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,EAAC,gBAAgB,EAAE,aAAa,EAAC,MAAM,uBAAuB,CAAC;AAiB3E,wBAAsB,wBAAwB,IAAI,OAAO,CACvD,qBAAqB,CAAC,aAAa,CAAC,CACrC,CAGA;AAED,wBAAsB,0BAA0B,IAAI,OAAO,CACzD,gBAAgB,CAAC,aAAa,CAAC,CAChC,CAGA"}
@@ -0,0 +1,30 @@
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.importSwcJsLoaderFactory = importSwcJsLoaderFactory;
10
+ exports.importSwcJsMinifierOptions = importSwcJsMinifierOptions;
11
+ async function importFaster() {
12
+ return import('@docusaurus/faster');
13
+ }
14
+ async function ensureFaster() {
15
+ try {
16
+ return await importFaster();
17
+ }
18
+ catch (error) {
19
+ throw new Error('Your Docusaurus site need to add the @docusaurus/faster package as a dependency.', { cause: error });
20
+ }
21
+ }
22
+ async function importSwcJsLoaderFactory() {
23
+ const faster = await ensureFaster();
24
+ return faster.getSwcJsLoaderFactory;
25
+ }
26
+ async function importSwcJsMinifierOptions() {
27
+ const faster = await ensureFaster();
28
+ return faster.getSwcJsMinifierOptions();
29
+ }
30
+ //# sourceMappingURL=importFaster.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"importFaster.js","sourceRoot":"","sources":["../src/importFaster.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAoBH,4DAKC;AAED,gEAKC;AA3BD,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,wBAAwB;IAG5C,MAAM,MAAM,GAAG,MAAM,YAAY,EAAE,CAAC;IACpC,OAAO,MAAM,CAAC,qBAAqB,CAAC;AACtC,CAAC;AAEM,KAAK,UAAU,0BAA0B;IAG9C,MAAM,MAAM,GAAG,MAAM,YAAY,EAAE,CAAC;IACpC,OAAO,MAAM,CAAC,uBAAuB,EAAqC,CAAC;AAC7E,CAAC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,12 @@
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
+ export { printStatsWarnings, formatStatsErrorMessage, compile } from './compiler';
8
+ export { getCurrentBundler, getCSSExtractPlugin, getCopyPlugin, getProgressBarPlugin, } from './currentBundler';
9
+ export { getMinimizers } from './minification';
10
+ export { createJsLoaderFactory } from './loaders/jsLoader';
11
+ export { createStyleLoadersFactory } from './loaders/styleLoader';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,kBAAkB,EAAE,uBAAuB,EAAE,OAAO,EAAC,MAAM,YAAY,CAAC;AAEhF,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,EACb,oBAAoB,GACrB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAC,aAAa,EAAC,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAC,qBAAqB,EAAC,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAC,yBAAyB,EAAC,MAAM,uBAAuB,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,25 @@
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.createStyleLoadersFactory = exports.createJsLoaderFactory = exports.getMinimizers = exports.getProgressBarPlugin = exports.getCopyPlugin = exports.getCSSExtractPlugin = exports.getCurrentBundler = exports.compile = exports.formatStatsErrorMessage = exports.printStatsWarnings = void 0;
10
+ var compiler_1 = require("./compiler");
11
+ Object.defineProperty(exports, "printStatsWarnings", { enumerable: true, get: function () { return compiler_1.printStatsWarnings; } });
12
+ Object.defineProperty(exports, "formatStatsErrorMessage", { enumerable: true, get: function () { return compiler_1.formatStatsErrorMessage; } });
13
+ Object.defineProperty(exports, "compile", { enumerable: true, get: function () { return compiler_1.compile; } });
14
+ var currentBundler_1 = require("./currentBundler");
15
+ Object.defineProperty(exports, "getCurrentBundler", { enumerable: true, get: function () { return currentBundler_1.getCurrentBundler; } });
16
+ Object.defineProperty(exports, "getCSSExtractPlugin", { enumerable: true, get: function () { return currentBundler_1.getCSSExtractPlugin; } });
17
+ Object.defineProperty(exports, "getCopyPlugin", { enumerable: true, get: function () { return currentBundler_1.getCopyPlugin; } });
18
+ Object.defineProperty(exports, "getProgressBarPlugin", { enumerable: true, get: function () { return currentBundler_1.getProgressBarPlugin; } });
19
+ var minification_1 = require("./minification");
20
+ Object.defineProperty(exports, "getMinimizers", { enumerable: true, get: function () { return minification_1.getMinimizers; } });
21
+ var jsLoader_1 = require("./loaders/jsLoader");
22
+ Object.defineProperty(exports, "createJsLoaderFactory", { enumerable: true, get: function () { return jsLoader_1.createJsLoaderFactory; } });
23
+ var styleLoader_1 = require("./loaders/styleLoader");
24
+ Object.defineProperty(exports, "createStyleLoadersFactory", { enumerable: true, get: function () { return styleLoader_1.createStyleLoadersFactory; } });
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,uCAAgF;AAAxE,8GAAA,kBAAkB,OAAA;AAAE,mHAAA,uBAAuB,OAAA;AAAE,mGAAA,OAAO,OAAA;AAE5D,mDAK0B;AAJxB,mHAAA,iBAAiB,OAAA;AACjB,qHAAA,mBAAmB,OAAA;AACnB,+GAAA,aAAa,OAAA;AACb,sHAAA,oBAAoB,OAAA;AAGtB,+CAA6C;AAArC,6GAAA,aAAa,OAAA;AACrB,+CAAyD;AAAjD,iHAAA,qBAAqB,OAAA;AAC7B,qDAAgE;AAAxD,wHAAA,yBAAyB,OAAA"}
@@ -0,0 +1,16 @@
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 type { ConfigureWebpackUtils, DocusaurusConfig } from '@docusaurus/types';
8
+ export declare function createJsLoaderFactory({ siteConfig, }: {
9
+ siteConfig: {
10
+ webpack?: DocusaurusConfig['webpack'];
11
+ future?: {
12
+ experimental_faster: DocusaurusConfig['future']['experimental_faster'];
13
+ };
14
+ };
15
+ }): Promise<ConfigureWebpackUtils['getJSLoader']>;
16
+ //# sourceMappingURL=jsLoader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsLoader.d.ts","sourceRoot":"","sources":["../../src/loaders/jsLoader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAC,qBAAqB,EAAE,gBAAgB,EAAC,MAAM,mBAAmB,CAAC;AAe/E,wBAAsB,qBAAqB,CAAC,EAC1C,UAAU,GACX,EAAE;IACD,UAAU,EAAE;QACV,OAAO,CAAC,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC;QACtC,MAAM,CAAC,EAAE;YACP,mBAAmB,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAC,qBAAqB,CAAC,CAAC;SACxE,CAAC;KACH,CAAC;CACH,GAAG,OAAO,CAAC,qBAAqB,CAAC,aAAa,CAAC,CAAC,CAoBhD"}
@@ -0,0 +1,38 @@
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.createJsLoaderFactory = createJsLoaderFactory;
10
+ const babel_1 = require("@docusaurus/babel");
11
+ const importFaster_1 = require("../importFaster");
12
+ const BabelJsLoaderFactory = ({ isServer, babelOptions, }) => {
13
+ return {
14
+ loader: require.resolve('babel-loader'),
15
+ options: (0, babel_1.getBabelOptions)({ isServer, babelOptions }),
16
+ };
17
+ };
18
+ // Confusing: function that creates a function that creates actual js loaders
19
+ // This is done on purpose because the js loader factory is a public API
20
+ // It is injected in configureWebpack plugin lifecycle for plugin authors
21
+ async function createJsLoaderFactory({ siteConfig, }) {
22
+ const jsLoader = siteConfig.webpack?.jsLoader ?? 'babel';
23
+ if (jsLoader instanceof Function &&
24
+ siteConfig.future?.experimental_faster.swcJsLoader) {
25
+ throw new Error("You can't use a custom webpack.jsLoader and experimental_faster.swcJsLoader at the same time");
26
+ }
27
+ if (jsLoader instanceof Function) {
28
+ return ({ isServer }) => jsLoader(isServer);
29
+ }
30
+ if (siteConfig.future?.experimental_faster.swcJsLoader) {
31
+ return (0, importFaster_1.importSwcJsLoaderFactory)();
32
+ }
33
+ if (jsLoader === 'babel') {
34
+ return BabelJsLoaderFactory;
35
+ }
36
+ throw new Error(`Docusaurus bug: unexpected jsLoader value${jsLoader}`);
37
+ }
38
+ //# sourceMappingURL=jsLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsLoader.js","sourceRoot":"","sources":["../../src/loaders/jsLoader.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAmBH,sDA6BC;AA9CD,6CAAkD;AAClD,kDAAyD;AAGzD,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,6EAA6E;AAC7E,wEAAwE;AACxE,yEAAyE;AAClE,KAAK,UAAU,qBAAqB,CAAC,EAC1C,UAAU,GAQX;IACC,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"}
@@ -0,0 +1,11 @@
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 type { ConfigureWebpackUtils, CurrentBundler } from '@docusaurus/types';
8
+ export declare function createStyleLoadersFactory({ currentBundler, }: {
9
+ currentBundler: CurrentBundler;
10
+ }): Promise<ConfigureWebpackUtils['getStyleLoaders']>;
11
+ //# sourceMappingURL=styleLoader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styleLoader.d.ts","sourceRoot":"","sources":["../../src/loaders/styleLoader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,qBAAqB,EAAE,cAAc,EAAC,MAAM,mBAAmB,CAAC;AAE7E,wBAAsB,yBAAyB,CAAC,EAC9C,cAAc,GACf,EAAE;IACD,cAAc,EAAE,cAAc,CAAC;CAChC,GAAG,OAAO,CAAC,qBAAqB,CAAC,iBAAiB,CAAC,CAAC,CAiEpD"}
@@ -0,0 +1,68 @@
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.createStyleLoadersFactory = createStyleLoadersFactory;
10
+ const currentBundler_1 = require("../currentBundler");
11
+ async function createStyleLoadersFactory({ currentBundler, }) {
12
+ const CssExtractPlugin = await (0, currentBundler_1.getCSSExtractPlugin)({ currentBundler });
13
+ return function getStyleLoaders(isServer, cssOptionsArg = {}) {
14
+ const cssOptions = {
15
+ // TODO turn esModule on later, see https://github.com/facebook/docusaurus/pull/6424
16
+ esModule: false,
17
+ ...cssOptionsArg,
18
+ };
19
+ // On the server we don't really need to extract/emit CSS
20
+ // We only need to transform CSS module imports to a styles object
21
+ if (isServer) {
22
+ return cssOptions.modules
23
+ ? [
24
+ {
25
+ loader: require.resolve('css-loader'),
26
+ options: cssOptions,
27
+ },
28
+ ]
29
+ : // Ignore regular CSS files
30
+ [{ loader: require.resolve('null-loader') }];
31
+ }
32
+ return [
33
+ {
34
+ loader: CssExtractPlugin.loader,
35
+ options: {
36
+ esModule: true,
37
+ },
38
+ },
39
+ {
40
+ loader: require.resolve('css-loader'),
41
+ options: cssOptions,
42
+ },
43
+ // TODO apart for configurePostCss(), do we really need this loader?
44
+ // Note: using postcss here looks inefficient/duplicate
45
+ // But in practice, it's not a big deal because css-loader also uses postcss
46
+ // and is able to reuse the parsed AST from postcss-loader
47
+ // See https://github.com/webpack-contrib/css-loader/blob/master/src/index.js#L159
48
+ {
49
+ // Options for PostCSS as we reference these options twice
50
+ // Adds vendor prefixing based on your specified browser support in
51
+ // package.json
52
+ loader: require.resolve('postcss-loader'),
53
+ options: {
54
+ postcssOptions: {
55
+ // Necessary for external CSS imports to work
56
+ // https://github.com/facebook/create-react-app/issues/2677
57
+ ident: 'postcss',
58
+ plugins: [
59
+ // eslint-disable-next-line global-require
60
+ require('autoprefixer'),
61
+ ],
62
+ },
63
+ },
64
+ },
65
+ ];
66
+ };
67
+ }
68
+ //# sourceMappingURL=styleLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styleLoader.js","sourceRoot":"","sources":["../../src/loaders/styleLoader.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAKH,8DAqEC;AAxED,sDAAsD;AAG/C,KAAK,UAAU,yBAAyB,CAAC,EAC9C,cAAc,GAGf;IACC,MAAM,gBAAgB,GAAG,MAAM,IAAA,oCAAmB,EAAC,EAAC,cAAc,EAAC,CAAC,CAAC;IAErE,OAAO,SAAS,eAAe,CAC7B,QAAiB,EACjB,gBAEI,EAAE;QAEN,MAAM,UAAU,GAA6B;YAC3C,oFAAoF;YACpF,QAAQ,EAAE,KAAK;YACf,GAAG,aAAa;SACjB,CAAC;QAEF,yDAAyD;QACzD,kEAAkE;QAClE,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,UAAU,CAAC,OAAO;gBACvB,CAAC,CAAC;oBACE;wBACE,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC;wBACrC,OAAO,EAAE,UAAU;qBACpB;iBACF;gBACH,CAAC,CAAC,2BAA2B;oBAC3B,CAAC,EAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,EAAC,CAAC,CAAC;QACjD,CAAC;QAED,OAAO;YACL;gBACE,MAAM,EAAE,gBAAgB,CAAC,MAAM;gBAC/B,OAAO,EAAE;oBACP,QAAQ,EAAE,IAAI;iBACf;aACF;YACD;gBACE,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC;gBACrC,OAAO,EAAE,UAAU;aACpB;YAED,oEAAoE;YACpE,uDAAuD;YACvD,4EAA4E;YAC5E,0DAA0D;YAC1D,kFAAkF;YAClF;gBACE,0DAA0D;gBAC1D,mEAAmE;gBACnE,eAAe;gBACf,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC;gBACzC,OAAO,EAAE;oBACP,cAAc,EAAE;wBACd,6CAA6C;wBAC7C,2DAA2D;wBAC3D,KAAK,EAAE,SAAS;wBAChB,OAAO,EAAE;4BACP,0CAA0C;4BAC1C,OAAO,CAAC,cAAc,CAAC;yBACxB;qBACF;iBACF;aACF;SACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,14 @@
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 type { WebpackPluginInstance } from 'webpack';
8
+ import type { CurrentBundler, FasterConfig } from '@docusaurus/types';
9
+ export type MinimizersConfig = {
10
+ faster: Pick<FasterConfig, 'swcJsMinimizer'>;
11
+ currentBundler: CurrentBundler;
12
+ };
13
+ export declare function getMinimizers(params: MinimizersConfig): Promise<WebpackPluginInstance[]>;
14
+ //# sourceMappingURL=minification.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"minification.d.ts","sourceRoot":"","sources":["../src/minification.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,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,CAAC,CAAC;IAC7C,cAAc,EAAE,cAAc,CAAC;CAChC,CAAC;AA8GF,wBAAsB,aAAa,CACjC,MAAM,EAAE,gBAAgB,GACvB,OAAO,CAAC,qBAAqB,EAAE,CAAC,CAIlC"}
@@ -0,0 +1,116 @@
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.getMinimizers = getMinimizers;
10
+ const tslib_1 = require("tslib");
11
+ const terser_webpack_plugin_1 = tslib_1.__importDefault(require("terser-webpack-plugin"));
12
+ const css_minimizer_webpack_plugin_1 = tslib_1.__importDefault(require("css-minimizer-webpack-plugin"));
13
+ const importFaster_1 = require("./importFaster");
14
+ // See https://github.com/webpack-contrib/terser-webpack-plugin#parallel
15
+ function getTerserParallel() {
16
+ let terserParallel = true;
17
+ if (process.env.TERSER_PARALLEL === 'false') {
18
+ terserParallel = false;
19
+ }
20
+ else if (process.env.TERSER_PARALLEL &&
21
+ parseInt(process.env.TERSER_PARALLEL, 10) > 0) {
22
+ terserParallel = parseInt(process.env.TERSER_PARALLEL, 10);
23
+ }
24
+ return terserParallel;
25
+ }
26
+ async function getJsMinimizer({ faster }) {
27
+ if (faster.swcJsMinimizer) {
28
+ const terserOptions = await (0, importFaster_1.importSwcJsMinifierOptions)();
29
+ return new terser_webpack_plugin_1.default({
30
+ parallel: getTerserParallel(),
31
+ minify: terser_webpack_plugin_1.default.swcMinify,
32
+ terserOptions,
33
+ });
34
+ }
35
+ return new terser_webpack_plugin_1.default({
36
+ parallel: getTerserParallel(),
37
+ terserOptions: {
38
+ parse: {
39
+ // We want uglify-js to parse ecma 8 code. However, we don't want it
40
+ // to apply any minification steps that turns valid ecma 5 code
41
+ // into invalid ecma 5 code. This is why the 'compress' and 'output'
42
+ // sections only apply transformations that are ecma 5 safe
43
+ // https://github.com/facebook/create-react-app/pull/4234
44
+ ecma: 2020,
45
+ },
46
+ compress: {
47
+ ecma: 5,
48
+ },
49
+ mangle: {
50
+ safari10: true,
51
+ },
52
+ output: {
53
+ ecma: 5,
54
+ comments: false,
55
+ // Turned on because emoji and regex is not minified properly using
56
+ // default. See https://github.com/facebook/create-react-app/issues/2488
57
+ ascii_only: true,
58
+ },
59
+ },
60
+ });
61
+ }
62
+ function getAdvancedCssMinifier() {
63
+ // Using the array syntax to add 2 minimizers
64
+ // see https://github.com/webpack-contrib/css-minimizer-webpack-plugin#array
65
+ return new css_minimizer_webpack_plugin_1.default({
66
+ minimizerOptions: [
67
+ // CssNano options
68
+ {
69
+ preset: require.resolve('@docusaurus/cssnano-preset'),
70
+ },
71
+ // CleanCss options
72
+ {
73
+ inline: false,
74
+ level: {
75
+ 1: {
76
+ all: false,
77
+ removeWhitespace: true,
78
+ },
79
+ 2: {
80
+ all: true,
81
+ restructureRules: true,
82
+ removeUnusedAtRules: false,
83
+ },
84
+ },
85
+ },
86
+ ],
87
+ minify: [
88
+ css_minimizer_webpack_plugin_1.default.cssnanoMinify,
89
+ css_minimizer_webpack_plugin_1.default.cleanCssMinify,
90
+ ],
91
+ });
92
+ }
93
+ function getCssMinimizer() {
94
+ // This is an historical env variable to opt-out of the advanced minifier
95
+ // Sometimes there's a bug in it and people are happy to disable it
96
+ const useSimpleCssMinifier = process.env.USE_SIMPLE_CSS_MINIFIER === 'true';
97
+ if (useSimpleCssMinifier) {
98
+ return new css_minimizer_webpack_plugin_1.default();
99
+ }
100
+ else {
101
+ return getAdvancedCssMinifier();
102
+ }
103
+ }
104
+ async function getWebpackMinimizers(params) {
105
+ return Promise.all([getJsMinimizer(params), getCssMinimizer()]);
106
+ }
107
+ async function getRspackMinimizers({ currentBundler, }) {
108
+ console.log('currentBundler', currentBundler.name);
109
+ throw new Error('TODO Rspack minimizers not implemented yet');
110
+ }
111
+ async function getMinimizers(params) {
112
+ return params.currentBundler.name === 'rspack'
113
+ ? getRspackMinimizers(params)
114
+ : getWebpackMinimizers(params);
115
+ }
116
+ //# sourceMappingURL=minification.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"minification.js","sourceRoot":"","sources":["../src/minification.ts"],"names":[],"mappings":"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"}
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@docusaurus/bundler",
3
+ "version": "0.0.0-6082",
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
+ "@babel/core": "^7.23.3",
22
+ "@docusaurus/babel": "0.0.0-6082",
23
+ "@docusaurus/cssnano-preset": "0.0.0-6082",
24
+ "@docusaurus/faster": "0.0.0-6082",
25
+ "@docusaurus/logger": "0.0.0-6082",
26
+ "@docusaurus/types": "0.0.0-6082",
27
+ "@docusaurus/utils": "0.0.0-6082",
28
+ "autoprefixer": "^10.4.14",
29
+ "babel-loader": "^9.1.3",
30
+ "clean-css": "^5.3.2",
31
+ "copy-webpack-plugin": "^11.0.0",
32
+ "css-loader": "^6.8.1",
33
+ "css-minimizer-webpack-plugin": "^5.0.1",
34
+ "cssnano": "^6.1.2",
35
+ "file-loader": "^6.2.0",
36
+ "mini-css-extract-plugin": "^2.9.1",
37
+ "null-loader": "^4.0.1",
38
+ "postcss": "^8.4.26",
39
+ "postcss-loader": "^7.3.3",
40
+ "react-dev-utils": "^12.0.1",
41
+ "terser-webpack-plugin": "^5.3.9",
42
+ "tslib": "^2.6.0",
43
+ "url-loader": "^4.1.1",
44
+ "webpack": "^5.88.1",
45
+ "webpackbar": "^6.0.1"
46
+ },
47
+ "devDependencies": {
48
+ "@total-typescript/shoehorn": "^0.1.2"
49
+ },
50
+ "engines": {
51
+ "node": ">=18.0"
52
+ },
53
+ "gitHead": "bbf50dffd0ec70f522b74e73406e4d18037d77f2"
54
+ }
@@ -0,0 +1,87 @@
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 {type Configuration} from 'webpack';
9
+ import logger from '@docusaurus/logger';
10
+ import formatWebpackMessages from 'react-dev-utils/formatWebpackMessages';
11
+ import type webpack from 'webpack';
12
+ import type {CurrentBundler} from '@docusaurus/types';
13
+
14
+ export function formatStatsErrorMessage(
15
+ statsJson: ReturnType<webpack.Stats['toJson']> | undefined,
16
+ ): string | undefined {
17
+ if (statsJson?.errors?.length) {
18
+ // TODO formatWebpackMessages does not print stack-traces
19
+ // Also the error causal chain is lost here
20
+ // We log the stacktrace inside serverEntry.tsx for now (not ideal)
21
+ const {errors} = formatWebpackMessages(statsJson);
22
+ return errors
23
+ .map((str) => logger.red(str))
24
+ .join(`\n\n${logger.yellow('--------------------------')}\n\n`);
25
+ }
26
+ return undefined;
27
+ }
28
+
29
+ export function printStatsWarnings(
30
+ statsJson: ReturnType<webpack.Stats['toJson']> | undefined,
31
+ ): void {
32
+ if (statsJson?.warnings?.length) {
33
+ statsJson.warnings?.forEach((warning) => {
34
+ logger.warn(warning);
35
+ });
36
+ }
37
+ }
38
+
39
+ declare global {
40
+ interface Error {
41
+ /** @see https://webpack.js.org/api/node/#error-handling */
42
+ details?: unknown;
43
+ }
44
+ }
45
+
46
+ export function compile({
47
+ configs,
48
+ currentBundler,
49
+ }: {
50
+ configs: Configuration[];
51
+ currentBundler: CurrentBundler;
52
+ }): Promise<webpack.MultiStats> {
53
+ return new Promise((resolve, reject) => {
54
+ const compiler = currentBundler.instance(configs);
55
+ compiler.run((err, stats) => {
56
+ if (err) {
57
+ logger.error(err.stack ?? err);
58
+ if (err.details) {
59
+ logger.error(err.details);
60
+ }
61
+ reject(err);
62
+ }
63
+ // Let plugins consume all the stats
64
+ const errorsWarnings = stats?.toJson('errors-warnings');
65
+ if (stats?.hasErrors()) {
66
+ const statsErrorMessage = formatStatsErrorMessage(errorsWarnings);
67
+ reject(
68
+ new Error(
69
+ `Failed to compile due to Webpack errors.\n${statsErrorMessage}`,
70
+ ),
71
+ );
72
+ }
73
+ printStatsWarnings(errorsWarnings);
74
+
75
+ // Webpack 5 requires calling close() so that persistent caching works
76
+ // See https://github.com/webpack/webpack.js.org/pull/4775
77
+ compiler.close((errClose) => {
78
+ if (errClose) {
79
+ logger.error(`Error while closing Webpack compiler: ${errClose}`);
80
+ reject(errClose);
81
+ } else {
82
+ resolve(stats!);
83
+ }
84
+ });
85
+ });
86
+ });
87
+ }
@@ -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
+ }
@@ -0,0 +1,38 @@
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 type {ConfigureWebpackUtils} from '@docusaurus/types';
9
+ import type {MinimizerOptions, CustomOptions} from 'terser-webpack-plugin';
10
+
11
+ async function importFaster() {
12
+ return import('@docusaurus/faster');
13
+ }
14
+
15
+ async function ensureFaster() {
16
+ try {
17
+ return await importFaster();
18
+ } catch (error) {
19
+ throw new Error(
20
+ 'Your Docusaurus site need to add the @docusaurus/faster package as a dependency.',
21
+ {cause: error},
22
+ );
23
+ }
24
+ }
25
+
26
+ export async function importSwcJsLoaderFactory(): Promise<
27
+ ConfigureWebpackUtils['getJSLoader']
28
+ > {
29
+ const faster = await ensureFaster();
30
+ return faster.getSwcJsLoaderFactory;
31
+ }
32
+
33
+ export async function importSwcJsMinifierOptions(): Promise<
34
+ MinimizerOptions<CustomOptions>
35
+ > {
36
+ const faster = await ensureFaster();
37
+ return faster.getSwcJsMinifierOptions() as MinimizerOptions<CustomOptions>;
38
+ }
package/src/index.ts ADDED
@@ -0,0 +1,19 @@
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
+ export {printStatsWarnings, formatStatsErrorMessage, compile} from './compiler';
9
+
10
+ export {
11
+ getCurrentBundler,
12
+ getCSSExtractPlugin,
13
+ getCopyPlugin,
14
+ getProgressBarPlugin,
15
+ } from './currentBundler';
16
+
17
+ export {getMinimizers} from './minification';
18
+ export {createJsLoaderFactory} from './loaders/jsLoader';
19
+ export {createStyleLoadersFactory} from './loaders/styleLoader';
@@ -0,0 +1,54 @@
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 {getBabelOptions} from '@docusaurus/babel';
9
+ import {importSwcJsLoaderFactory} from '../importFaster';
10
+ import type {ConfigureWebpackUtils, DocusaurusConfig} from '@docusaurus/types';
11
+
12
+ const BabelJsLoaderFactory: ConfigureWebpackUtils['getJSLoader'] = ({
13
+ isServer,
14
+ babelOptions,
15
+ }) => {
16
+ return {
17
+ loader: require.resolve('babel-loader'),
18
+ options: getBabelOptions({isServer, babelOptions}),
19
+ };
20
+ };
21
+
22
+ // Confusing: function that creates a function that creates actual js loaders
23
+ // This is done on purpose because the js loader factory is a public API
24
+ // It is injected in configureWebpack plugin lifecycle for plugin authors
25
+ export async function createJsLoaderFactory({
26
+ siteConfig,
27
+ }: {
28
+ siteConfig: {
29
+ webpack?: DocusaurusConfig['webpack'];
30
+ future?: {
31
+ experimental_faster: DocusaurusConfig['future']['experimental_faster'];
32
+ };
33
+ };
34
+ }): Promise<ConfigureWebpackUtils['getJSLoader']> {
35
+ const jsLoader = siteConfig.webpack?.jsLoader ?? 'babel';
36
+ if (
37
+ jsLoader instanceof Function &&
38
+ siteConfig.future?.experimental_faster.swcJsLoader
39
+ ) {
40
+ throw new Error(
41
+ "You can't use a custom webpack.jsLoader and experimental_faster.swcJsLoader at the same time",
42
+ );
43
+ }
44
+ if (jsLoader instanceof Function) {
45
+ return ({isServer}) => jsLoader(isServer);
46
+ }
47
+ if (siteConfig.future?.experimental_faster.swcJsLoader) {
48
+ return importSwcJsLoaderFactory();
49
+ }
50
+ if (jsLoader === 'babel') {
51
+ return BabelJsLoaderFactory;
52
+ }
53
+ throw new Error(`Docusaurus bug: unexpected jsLoader value${jsLoader}`);
54
+ }
@@ -0,0 +1,80 @@
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 {getCSSExtractPlugin} from '../currentBundler';
9
+ import type {ConfigureWebpackUtils, CurrentBundler} from '@docusaurus/types';
10
+
11
+ export async function createStyleLoadersFactory({
12
+ currentBundler,
13
+ }: {
14
+ currentBundler: CurrentBundler;
15
+ }): Promise<ConfigureWebpackUtils['getStyleLoaders']> {
16
+ const CssExtractPlugin = await getCSSExtractPlugin({currentBundler});
17
+
18
+ return function getStyleLoaders(
19
+ isServer: boolean,
20
+ cssOptionsArg: {
21
+ [key: string]: unknown;
22
+ } = {},
23
+ ) {
24
+ const cssOptions: {[key: string]: unknown} = {
25
+ // TODO turn esModule on later, see https://github.com/facebook/docusaurus/pull/6424
26
+ esModule: false,
27
+ ...cssOptionsArg,
28
+ };
29
+
30
+ // On the server we don't really need to extract/emit CSS
31
+ // We only need to transform CSS module imports to a styles object
32
+ if (isServer) {
33
+ return cssOptions.modules
34
+ ? [
35
+ {
36
+ loader: require.resolve('css-loader'),
37
+ options: cssOptions,
38
+ },
39
+ ]
40
+ : // Ignore regular CSS files
41
+ [{loader: require.resolve('null-loader')}];
42
+ }
43
+
44
+ return [
45
+ {
46
+ loader: CssExtractPlugin.loader,
47
+ options: {
48
+ esModule: true,
49
+ },
50
+ },
51
+ {
52
+ loader: require.resolve('css-loader'),
53
+ options: cssOptions,
54
+ },
55
+
56
+ // TODO apart for configurePostCss(), do we really need this loader?
57
+ // Note: using postcss here looks inefficient/duplicate
58
+ // But in practice, it's not a big deal because css-loader also uses postcss
59
+ // and is able to reuse the parsed AST from postcss-loader
60
+ // See https://github.com/webpack-contrib/css-loader/blob/master/src/index.js#L159
61
+ {
62
+ // Options for PostCSS as we reference these options twice
63
+ // Adds vendor prefixing based on your specified browser support in
64
+ // package.json
65
+ loader: require.resolve('postcss-loader'),
66
+ options: {
67
+ postcssOptions: {
68
+ // Necessary for external CSS imports to work
69
+ // https://github.com/facebook/create-react-app/issues/2677
70
+ ident: 'postcss',
71
+ plugins: [
72
+ // eslint-disable-next-line global-require
73
+ require('autoprefixer'),
74
+ ],
75
+ },
76
+ },
77
+ },
78
+ ];
79
+ };
80
+ }
@@ -0,0 +1,134 @@
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 TerserPlugin from 'terser-webpack-plugin';
9
+ import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
10
+ import {importSwcJsMinifierOptions} from './importFaster';
11
+ import type {CustomOptions, CssNanoOptions} from 'css-minimizer-webpack-plugin';
12
+ import type {WebpackPluginInstance} from 'webpack';
13
+ import type {CurrentBundler, FasterConfig} from '@docusaurus/types';
14
+
15
+ export type MinimizersConfig = {
16
+ faster: Pick<FasterConfig, 'swcJsMinimizer'>;
17
+ currentBundler: CurrentBundler;
18
+ };
19
+
20
+ // See https://github.com/webpack-contrib/terser-webpack-plugin#parallel
21
+ function getTerserParallel() {
22
+ let terserParallel: boolean | number = true;
23
+ if (process.env.TERSER_PARALLEL === 'false') {
24
+ terserParallel = false;
25
+ } else if (
26
+ process.env.TERSER_PARALLEL &&
27
+ parseInt(process.env.TERSER_PARALLEL, 10) > 0
28
+ ) {
29
+ terserParallel = parseInt(process.env.TERSER_PARALLEL, 10);
30
+ }
31
+ return terserParallel;
32
+ }
33
+
34
+ async function getJsMinimizer({faster}: MinimizersConfig) {
35
+ if (faster.swcJsMinimizer) {
36
+ const terserOptions = await importSwcJsMinifierOptions();
37
+ return new TerserPlugin({
38
+ parallel: getTerserParallel(),
39
+ minify: TerserPlugin.swcMinify,
40
+ terserOptions,
41
+ });
42
+ }
43
+
44
+ return new TerserPlugin({
45
+ parallel: getTerserParallel(),
46
+ terserOptions: {
47
+ parse: {
48
+ // We want uglify-js to parse ecma 8 code. However, we don't want it
49
+ // to apply any minification steps that turns valid ecma 5 code
50
+ // into invalid ecma 5 code. This is why the 'compress' and 'output'
51
+ // sections only apply transformations that are ecma 5 safe
52
+ // https://github.com/facebook/create-react-app/pull/4234
53
+ ecma: 2020,
54
+ },
55
+ compress: {
56
+ ecma: 5,
57
+ },
58
+ mangle: {
59
+ safari10: true,
60
+ },
61
+ output: {
62
+ ecma: 5,
63
+ comments: false,
64
+ // Turned on because emoji and regex is not minified properly using
65
+ // default. See https://github.com/facebook/create-react-app/issues/2488
66
+ ascii_only: true,
67
+ },
68
+ },
69
+ });
70
+ }
71
+
72
+ function getAdvancedCssMinifier() {
73
+ // Using the array syntax to add 2 minimizers
74
+ // see https://github.com/webpack-contrib/css-minimizer-webpack-plugin#array
75
+ return new CssMinimizerPlugin<[CssNanoOptions, CustomOptions]>({
76
+ minimizerOptions: [
77
+ // CssNano options
78
+ {
79
+ preset: require.resolve('@docusaurus/cssnano-preset'),
80
+ },
81
+ // CleanCss options
82
+ {
83
+ inline: false,
84
+ level: {
85
+ 1: {
86
+ all: false,
87
+ removeWhitespace: true,
88
+ },
89
+ 2: {
90
+ all: true,
91
+ restructureRules: true,
92
+ removeUnusedAtRules: false,
93
+ },
94
+ },
95
+ },
96
+ ],
97
+ minify: [
98
+ CssMinimizerPlugin.cssnanoMinify,
99
+ CssMinimizerPlugin.cleanCssMinify,
100
+ ],
101
+ });
102
+ }
103
+
104
+ function getCssMinimizer(): WebpackPluginInstance {
105
+ // This is an historical env variable to opt-out of the advanced minifier
106
+ // Sometimes there's a bug in it and people are happy to disable it
107
+ const useSimpleCssMinifier = process.env.USE_SIMPLE_CSS_MINIFIER === 'true';
108
+ if (useSimpleCssMinifier) {
109
+ return new CssMinimizerPlugin();
110
+ } else {
111
+ return getAdvancedCssMinifier();
112
+ }
113
+ }
114
+
115
+ async function getWebpackMinimizers(
116
+ params: MinimizersConfig,
117
+ ): Promise<WebpackPluginInstance[]> {
118
+ return Promise.all([getJsMinimizer(params), getCssMinimizer()]);
119
+ }
120
+
121
+ async function getRspackMinimizers({
122
+ currentBundler,
123
+ }: MinimizersConfig): Promise<WebpackPluginInstance[]> {
124
+ console.log('currentBundler', currentBundler.name);
125
+ throw new Error('TODO Rspack minimizers not implemented yet');
126
+ }
127
+
128
+ export async function getMinimizers(
129
+ params: MinimizersConfig,
130
+ ): Promise<WebpackPluginInstance[]> {
131
+ return params.currentBundler.name === 'rspack'
132
+ ? getRspackMinimizers(params)
133
+ : getWebpackMinimizers(params);
134
+ }