Skip to content

Commit

Permalink
fix(core): make generated files have unambiguous module types
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed May 9, 2022
1 parent c3880cc commit 55c6af6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ exports[`loadRoutes loads flat route config 1`] = `
],
},
},
"routesConfig": "import React from 'react';
import ComponentCreator from '@docusaurus/ComponentCreator';
"routesConfig": "import ComponentCreator from '@docusaurus/ComponentCreator';
export default [
{
Expand Down Expand Up @@ -90,8 +89,7 @@ exports[`loadRoutes loads nested route config 1`] = `
"metadata": "metadata---docs-foo-baz-2-cf-fa7",
},
},
"routesConfig": "import React from 'react';
import ComponentCreator from '@docusaurus/ComponentCreator';
"routesConfig": "import ComponentCreator from '@docusaurus/ComponentCreator';
export default [
{
Expand Down Expand Up @@ -140,8 +138,7 @@ exports[`loadRoutes loads route config with empty (but valid) path string 1`] =
"__comp": "__comp---hello-world-jse-0-f-b6c",
},
},
"routesConfig": "import React from 'react';
import ComponentCreator from '@docusaurus/ComponentCreator';
"routesConfig": "import ComponentCreator from '@docusaurus/ComponentCreator';
export default [
{
Expand Down
8 changes: 4 additions & 4 deletions packages/docusaurus/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ export default ${JSON.stringify(siteConfig, null, 2)};

const genClientModules = generate(
generatedFilesDir,
'client-modules.js',
`export default [
'client-modules.cjs',
`module.exports = [
${clientModules
// Use `require()` because `import()` is async but client modules can have CSS
// and the order matters for loading CSS.
Expand All @@ -181,8 +181,8 @@ ${clientModules

const genRegistry = generate(
generatedFilesDir,
'registry.js',
`export default {
'registry.cjs',
`module.exports = {
${Object.entries(registry)
.sort((a, b) => a[0].localeCompare(b[0]))
.map(
Expand Down
3 changes: 1 addition & 2 deletions packages/docusaurus/src/server/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,7 @@ export function loadRoutes(
.map((r) => genRouteCode(r, res))
.join(',\n');

res.routesConfig = `import React from 'react';
import ComponentCreator from '@docusaurus/ComponentCreator';
res.routesConfig = `import ComponentCreator from '@docusaurus/ComponentCreator';
export default [
${indent(routeConfigSerialized)},
Expand Down
11 changes: 10 additions & 1 deletion packages/docusaurus/src/webpack/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,16 @@ export async function createBaseConfig(
devtool: isProd ? undefined : 'eval-cheap-module-source-map',
resolve: {
unsafeCache: false, // Not enabled, does not seem to improve perf much
extensions: ['.wasm', '.mjs', '.js', '.jsx', '.ts', '.tsx', '.json'],
extensions: [
'.wasm',
'.mjs',
'.cjs',
'.js',
'.jsx',
'.ts',
'.tsx',
'.json',
],
symlinks: true, // See https://github.com/facebook/docusaurus/issues/3272
roots: [
// Allow resolution of url("/fonts/xyz.ttf") by webpack
Expand Down

0 comments on commit 55c6af6

Please sign in to comment.