@docusaurus/core 0.0.0-6052 → 0.0.0-6055

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.
@@ -195,6 +195,7 @@ async function getBuildClientConfig({ props, cliOptions, }) {
195
195
  const result = await (0, client_1.createBuildClientConfig)({
196
196
  props,
197
197
  minify: cliOptions.minify ?? true,
198
+ faster: props.siteConfig.future.experimental_faster,
198
199
  bundleAnalyzer: cliOptions.bundleAnalyzer ?? false,
199
200
  });
200
201
  let { config } = result;
@@ -102,6 +102,7 @@ async function getStartClientConfig({ props, minify, poll, }) {
102
102
  let { clientConfig: config } = await (0, client_1.createStartClientConfig)({
103
103
  props,
104
104
  minify,
105
+ faster: props.siteConfig.future.experimental_faster,
105
106
  poll,
106
107
  });
107
108
  config = (0, configure_1.executePluginsConfigureWebpack)({
package/lib/faster.d.ts CHANGED
@@ -5,4 +5,6 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { ConfigureWebpackUtils } from '@docusaurus/types';
8
- export declare function getSwcJsLoaderFactory(): Promise<ConfigureWebpackUtils['getJSLoader']>;
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>>;
package/lib/faster.js CHANGED
@@ -6,7 +6,8 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.getSwcJsLoaderFactory = getSwcJsLoaderFactory;
9
+ exports.importSwcJsLoaderFactory = importSwcJsLoaderFactory;
10
+ exports.importSwcJsMinifierOptions = importSwcJsMinifierOptions;
10
11
  async function importFaster() {
11
12
  return import('@docusaurus/faster');
12
13
  }
@@ -18,7 +19,11 @@ async function ensureFaster() {
18
19
  throw new Error('Your Docusaurus site need to add the @docusaurus/faster package as a dependency.', { cause: error });
19
20
  }
20
21
  }
21
- async function getSwcJsLoaderFactory() {
22
+ async function importSwcJsLoaderFactory() {
22
23
  const faster = await ensureFaster();
23
24
  return faster.getSwcJsLoaderFactory;
24
25
  }
26
+ async function importSwcJsMinifierOptions() {
27
+ const faster = await ensureFaster();
28
+ return faster.getSwcJsMinifierOptions();
29
+ }
@@ -24,10 +24,12 @@ exports.DEFAULT_STORAGE_CONFIG = {
24
24
  };
25
25
  exports.DEFAULT_FASTER_CONFIG = {
26
26
  swcJsLoader: false,
27
+ swcJsMinimizer: false,
27
28
  };
28
29
  // When using the "faster: true" shortcut
29
30
  exports.DEFAULT_FASTER_CONFIG_TRUE = {
30
31
  swcJsLoader: true,
32
+ swcJsMinimizer: true,
31
33
  };
32
34
  exports.DEFAULT_FUTURE_CONFIG = {
33
35
  experimental_faster: exports.DEFAULT_FASTER_CONFIG,
@@ -141,6 +143,7 @@ const I18N_CONFIG_SCHEMA = utils_validation_1.Joi.object({
141
143
  const FASTER_CONFIG_SCHEMA = utils_validation_1.Joi.alternatives()
142
144
  .try(utils_validation_1.Joi.object({
143
145
  swcJsLoader: utils_validation_1.Joi.boolean().default(exports.DEFAULT_FASTER_CONFIG.swcJsLoader),
146
+ swcJsMinimizer: utils_validation_1.Joi.boolean().default(exports.DEFAULT_FASTER_CONFIG.swcJsMinimizer),
144
147
  }), utils_validation_1.Joi.boolean()
145
148
  .required()
146
149
  .custom((bool) => bool ? exports.DEFAULT_FASTER_CONFIG_TRUE : exports.DEFAULT_FASTER_CONFIG))
@@ -5,11 +5,12 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { Configuration } from 'webpack';
8
- import type { Props } from '@docusaurus/types';
8
+ import type { FasterConfig, Props } from '@docusaurus/types';
9
9
  export declare const clientDir: string;
10
10
  export declare function excludeJS(modulePath: string): boolean;
11
- export declare function createBaseConfig({ props, isServer, minify, }: {
11
+ export declare function createBaseConfig({ props, isServer, minify, faster, }: {
12
12
  props: Props;
13
13
  isServer: boolean;
14
14
  minify: boolean;
15
+ faster: FasterConfig;
15
16
  }): Promise<Configuration>;
@@ -42,7 +42,7 @@ function excludeJS(modulePath) {
42
42
  !/docusaurus(?:(?!node_modules).)*\.jsx?$/.test(modulePath) &&
43
43
  !LibrariesToTranspileRegex.test(modulePath));
44
44
  }
45
- async function createBaseConfig({ props, isServer, minify, }) {
45
+ async function createBaseConfig({ props, isServer, minify, faster, }) {
46
46
  const { outDir, siteDir, siteConfig, siteConfigPath, baseUrl, generatedFilesDir, routesPaths, siteMetadata, plugins, } = props;
47
47
  const totalPages = routesPaths.length;
48
48
  const isProd = process.env.NODE_ENV === 'production';
@@ -135,7 +135,7 @@ async function createBaseConfig({ props, isServer, minify, }) {
135
135
  // Only minimize client bundle in production because server bundle is only
136
136
  // used for static site generation
137
137
  minimize: minimizeEnabled,
138
- minimizer: minimizeEnabled ? (0, minification_1.getMinimizer)() : undefined,
138
+ minimizer: minimizeEnabled ? await (0, minification_1.getMinimizers)({ faster }) : undefined,
139
139
  splitChunks: isServer
140
140
  ? false
141
141
  : {
@@ -4,18 +4,20 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import type { Props } from '@docusaurus/types';
7
+ import type { FasterConfig, Props } from '@docusaurus/types';
8
8
  import type { Configuration } from 'webpack';
9
- export declare function createStartClientConfig({ props, minify, poll, }: {
9
+ export declare function createStartClientConfig({ props, minify, poll, faster, }: {
10
10
  props: Props;
11
11
  minify: boolean;
12
12
  poll: number | boolean | undefined;
13
+ faster: FasterConfig;
13
14
  }): Promise<{
14
15
  clientConfig: Configuration;
15
16
  }>;
16
- export declare function createBuildClientConfig({ props, minify, bundleAnalyzer, }: {
17
+ export declare function createBuildClientConfig({ props, minify, faster, bundleAnalyzer, }: {
17
18
  props: Props;
18
19
  minify: boolean;
20
+ faster: FasterConfig;
19
21
  bundleAnalyzer: boolean;
20
22
  }): Promise<{
21
23
  config: Configuration;
@@ -21,8 +21,13 @@ const ChunkAssetPlugin_1 = tslib_1.__importDefault(require("./plugins/ChunkAsset
21
21
  const CleanWebpackPlugin_1 = tslib_1.__importDefault(require("./plugins/CleanWebpackPlugin"));
22
22
  const ForceTerminatePlugin_1 = tslib_1.__importDefault(require("./plugins/ForceTerminatePlugin"));
23
23
  const StaticDirectoriesCopyPlugin_1 = require("./plugins/StaticDirectoriesCopyPlugin");
24
- async function createBaseClientConfig({ props, hydrate, minify, }) {
25
- const baseConfig = await (0, base_1.createBaseConfig)({ props, isServer: false, minify });
24
+ async function createBaseClientConfig({ props, hydrate, minify, faster, }) {
25
+ const baseConfig = await (0, base_1.createBaseConfig)({
26
+ props,
27
+ isServer: false,
28
+ minify,
29
+ faster,
30
+ });
26
31
  return (0, webpack_merge_1.default)(baseConfig, {
27
32
  // Useless, disabled on purpose (errors on existing sites with no
28
33
  // browserslist config)
@@ -47,12 +52,13 @@ async function createBaseClientConfig({ props, hydrate, minify, }) {
47
52
  });
48
53
  }
49
54
  // client config when running "docusaurus start"
50
- async function createStartClientConfig({ props, minify, poll, }) {
55
+ async function createStartClientConfig({ props, minify, poll, faster, }) {
51
56
  const { siteConfig, headTags, preBodyTags, postBodyTags } = props;
52
57
  const clientConfig = (0, webpack_merge_1.default)(await createBaseClientConfig({
53
58
  props,
54
59
  minify,
55
60
  hydrate: false,
61
+ faster,
56
62
  }), {
57
63
  watchOptions: {
58
64
  ignored: /node_modules\/(?!@docusaurus)/,
@@ -79,7 +85,7 @@ async function createStartClientConfig({ props, minify, poll, }) {
79
85
  return { clientConfig };
80
86
  }
81
87
  // client config when running "docusaurus build"
82
- async function createBuildClientConfig({ props, minify, bundleAnalyzer, }) {
88
+ async function createBuildClientConfig({ props, minify, faster, bundleAnalyzer, }) {
83
89
  // Apply user webpack config.
84
90
  const { generatedFilesDir, siteConfig } = props;
85
91
  const router = siteConfig.future.experimental_router;
@@ -87,7 +93,7 @@ async function createBuildClientConfig({ props, minify, bundleAnalyzer, }) {
87
93
  // This is because it will always be a client-rendered React app
88
94
  const hydrate = router !== 'hash';
89
95
  const clientManifestPath = path_1.default.join(generatedFilesDir, 'client-manifest.json');
90
- const config = (0, webpack_merge_1.default)(await createBaseClientConfig({ props, minify, hydrate }), {
96
+ const config = (0, webpack_merge_1.default)(await createBaseClientConfig({ props, minify, faster, hydrate }), {
91
97
  plugins: [
92
98
  new ForceTerminatePlugin_1.default(),
93
99
  // Remove/clean build folders before building bundles.
@@ -5,4 +5,8 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { WebpackPluginInstance } from 'webpack';
8
- export declare function getMinimizer(): WebpackPluginInstance[];
8
+ import type { FasterConfig } from '@docusaurus/types';
9
+ export type MinimizersConfig = {
10
+ faster: Pick<FasterConfig, 'swcJsMinimizer'>;
11
+ };
12
+ export declare function getMinimizers(params: MinimizersConfig): Promise<WebpackPluginInstance[]>;
@@ -6,10 +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.getMinimizer = getMinimizer;
9
+ exports.getMinimizers = getMinimizers;
10
10
  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
+ const faster_1 = require("../faster");
13
14
  // See https://github.com/webpack-contrib/terser-webpack-plugin#parallel
14
15
  function getTerserParallel() {
15
16
  let terserParallel = true;
@@ -22,7 +23,15 @@ function getTerserParallel() {
22
23
  }
23
24
  return terserParallel;
24
25
  }
25
- function getJsMinifierPlugin() {
26
+ async function getJsMinimizer({ faster }) {
27
+ if (faster.swcJsMinimizer) {
28
+ const terserOptions = await (0, faster_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
+ }
26
35
  return new terser_webpack_plugin_1.default({
27
36
  parallel: getTerserParallel(),
28
37
  terserOptions: {
@@ -81,16 +90,17 @@ function getAdvancedCssMinifier() {
81
90
  ],
82
91
  });
83
92
  }
84
- function getMinimizer() {
93
+ function getCssMinimizer() {
85
94
  // This is an historical env variable to opt-out of the advanced minifier
86
95
  // Sometimes there's a bug in it and people are happy to disable it
87
96
  const useSimpleCssMinifier = process.env.USE_SIMPLE_CSS_MINIFIER === 'true';
88
- const minimizer = [getJsMinifierPlugin()];
89
97
  if (useSimpleCssMinifier) {
90
- minimizer.push(new css_minimizer_webpack_plugin_1.default());
98
+ return new css_minimizer_webpack_plugin_1.default();
91
99
  }
92
100
  else {
93
- minimizer.push(getAdvancedCssMinifier());
101
+ return getAdvancedCssMinifier();
94
102
  }
95
- return minimizer;
103
+ }
104
+ async function getMinimizers(params) {
105
+ return Promise.all([getJsMinimizer(params), getCssMinimizer()]);
96
106
  }
@@ -18,8 +18,8 @@ async function createServerConfig(params) {
18
18
  const baseConfig = await (0, base_1.createBaseConfig)({
19
19
  props,
20
20
  isServer: true,
21
- // Minification of server bundle reduces size but doubles bundle time :/
22
21
  minify: false,
22
+ faster: props.siteConfig.future.experimental_faster,
23
23
  });
24
24
  const outputFilename = 'server.bundle.js';
25
25
  const outputDir = path_1.default.join(props.outDir, '__server');
@@ -143,7 +143,7 @@ async function createJsLoaderFactory({ siteConfig, }) {
143
143
  return ({ isServer }) => jsLoader(isServer);
144
144
  }
145
145
  if (siteConfig.future?.experimental_faster.swcJsLoader) {
146
- return (0, faster_1.getSwcJsLoaderFactory)();
146
+ return (0, faster_1.importSwcJsLoaderFactory)();
147
147
  }
148
148
  if (jsLoader === 'babel') {
149
149
  return BabelJsLoaderFactory;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@docusaurus/core",
3
3
  "description": "Easy to Maintain Open Source Documentation Websites",
4
- "version": "0.0.0-6052",
4
+ "version": "0.0.0-6055",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -43,12 +43,12 @@
43
43
  "@babel/runtime": "^7.22.6",
44
44
  "@babel/runtime-corejs3": "^7.22.6",
45
45
  "@babel/traverse": "^7.22.8",
46
- "@docusaurus/cssnano-preset": "0.0.0-6052",
47
- "@docusaurus/logger": "0.0.0-6052",
48
- "@docusaurus/mdx-loader": "0.0.0-6052",
49
- "@docusaurus/utils": "0.0.0-6052",
50
- "@docusaurus/utils-common": "0.0.0-6052",
51
- "@docusaurus/utils-validation": "0.0.0-6052",
46
+ "@docusaurus/cssnano-preset": "0.0.0-6055",
47
+ "@docusaurus/logger": "0.0.0-6055",
48
+ "@docusaurus/mdx-loader": "0.0.0-6055",
49
+ "@docusaurus/utils": "0.0.0-6055",
50
+ "@docusaurus/utils-common": "0.0.0-6055",
51
+ "@docusaurus/utils-validation": "0.0.0-6055",
52
52
  "autoprefixer": "^10.4.14",
53
53
  "babel-loader": "^9.1.3",
54
54
  "babel-plugin-dynamic-import-node": "^2.3.3",
@@ -92,7 +92,7 @@
92
92
  "semver": "^7.5.4",
93
93
  "serve-handler": "^6.1.5",
94
94
  "shelljs": "^0.8.5",
95
- "terser-webpack-plugin": "^5.3.9",
95
+ "terser-webpack-plugin": "^5.3.10",
96
96
  "tslib": "^2.6.0",
97
97
  "update-notifier": "^6.0.2",
98
98
  "url-loader": "^4.1.1",
@@ -103,8 +103,8 @@
103
103
  "webpackbar": "^5.0.2"
104
104
  },
105
105
  "devDependencies": {
106
- "@docusaurus/module-type-aliases": "0.0.0-6052",
107
- "@docusaurus/types": "0.0.0-6052",
106
+ "@docusaurus/module-type-aliases": "0.0.0-6055",
107
+ "@docusaurus/types": "0.0.0-6055",
108
108
  "@total-typescript/shoehorn": "^0.1.2",
109
109
  "@types/detect-port": "^1.3.3",
110
110
  "@types/react-dom": "^18.2.7",
@@ -131,5 +131,5 @@
131
131
  "engines": {
132
132
  "node": ">=18.0"
133
133
  },
134
- "gitHead": "ff41451cf14cc627f2c0e002edc580ae91732eaf"
134
+ "gitHead": "b57b82e42ebabf1864ac745b95199ff62fb289af"
135
135
  }