@strapi/strapi 5.0.0-beta.0 → 5.0.0-beta.10
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 +4 -4
- package/dist/admin.d.ts.map +1 -1
- package/dist/admin.js +12 -4
- package/dist/admin.js.map +1 -1
- package/dist/admin.mjs +10 -4
- package/dist/admin.mjs.map +1 -1
- package/dist/cli/commands/admin/create-user.js +2 -2
- package/dist/cli/commands/admin/create-user.js.map +1 -1
- package/dist/cli/commands/admin/create-user.mjs +88 -0
- package/dist/cli/commands/admin/create-user.mjs.map +1 -0
- package/dist/cli/commands/admin/reset-user-password.js +2 -2
- package/dist/cli/commands/admin/reset-user-password.js.map +1 -1
- package/dist/cli/commands/admin/reset-user-password.mjs +44 -0
- package/dist/cli/commands/admin/reset-user-password.mjs.map +1 -0
- package/dist/cli/commands/build.js.map +1 -1
- package/dist/cli/commands/build.mjs +30 -0
- package/dist/cli/commands/build.mjs.map +1 -0
- package/dist/cli/commands/components/list.js +2 -2
- package/dist/cli/commands/components/list.js.map +1 -1
- package/dist/cli/commands/components/list.mjs +24 -0
- package/dist/cli/commands/components/list.mjs.map +1 -0
- package/dist/cli/commands/configuration/dump.js +2 -2
- package/dist/cli/commands/configuration/dump.js.map +1 -1
- package/dist/cli/commands/configuration/dump.mjs +41 -0
- package/dist/cli/commands/configuration/dump.mjs.map +1 -0
- package/dist/cli/commands/configuration/restore.js +2 -2
- package/dist/cli/commands/configuration/restore.js.map +1 -1
- package/dist/cli/commands/configuration/restore.mjs +140 -0
- package/dist/cli/commands/configuration/restore.mjs.map +1 -0
- package/dist/cli/commands/console.js +2 -2
- package/dist/cli/commands/console.js.map +1 -1
- package/dist/cli/commands/console.mjs +27 -0
- package/dist/cli/commands/console.mjs.map +1 -0
- package/dist/cli/commands/content-types/list.js +2 -2
- package/dist/cli/commands/content-types/list.js.map +1 -1
- package/dist/cli/commands/content-types/list.mjs +24 -0
- package/dist/cli/commands/content-types/list.mjs.map +1 -0
- package/dist/cli/commands/controllers/list.js +2 -2
- package/dist/cli/commands/controllers/list.js.map +1 -1
- package/dist/cli/commands/controllers/list.mjs +24 -0
- package/dist/cli/commands/controllers/list.mjs.map +1 -0
- package/dist/cli/commands/develop.js.map +1 -1
- package/dist/cli/commands/develop.mjs +27 -0
- package/dist/cli/commands/develop.mjs.map +1 -0
- package/dist/cli/commands/export/action.js.map +1 -1
- package/dist/cli/commands/export/action.mjs +116 -0
- package/dist/cli/commands/export/action.mjs.map +1 -0
- package/dist/cli/commands/export/command.mjs +24 -0
- package/dist/cli/commands/export/command.mjs.map +1 -0
- package/dist/cli/commands/generate.mjs +13 -0
- package/dist/cli/commands/generate.mjs.map +1 -0
- package/dist/cli/commands/hooks/list.js +2 -2
- package/dist/cli/commands/hooks/list.js.map +1 -1
- package/dist/cli/commands/hooks/list.mjs +24 -0
- package/dist/cli/commands/hooks/list.mjs.map +1 -0
- package/dist/cli/commands/import/action.js.map +1 -1
- package/dist/cli/commands/import/action.mjs +105 -0
- package/dist/cli/commands/import/action.mjs.map +1 -0
- package/dist/cli/commands/import/command.mjs +68 -0
- package/dist/cli/commands/import/command.mjs.map +1 -0
- package/dist/cli/commands/index.d.ts.map +1 -1
- package/dist/cli/commands/index.js +1 -14
- package/dist/cli/commands/index.js.map +1 -1
- package/dist/cli/commands/index.mjs +58 -0
- package/dist/cli/commands/index.mjs.map +1 -0
- package/dist/cli/commands/middlewares/list.js +2 -2
- package/dist/cli/commands/middlewares/list.js.map +1 -1
- package/dist/cli/commands/middlewares/list.mjs +24 -0
- package/dist/cli/commands/middlewares/list.mjs.map +1 -0
- package/dist/cli/commands/plugin/init/files/typescript.d.ts.map +1 -1
- package/dist/cli/commands/policies/list.js +2 -2
- package/dist/cli/commands/policies/list.js.map +1 -1
- package/dist/cli/commands/policies/list.mjs +24 -0
- package/dist/cli/commands/policies/list.mjs.map +1 -0
- package/dist/cli/commands/report.js +2 -2
- package/dist/cli/commands/report.js.map +1 -1
- package/dist/cli/commands/report.mjs +35 -0
- package/dist/cli/commands/report.mjs.map +1 -0
- package/dist/cli/commands/routes/list.js +2 -2
- package/dist/cli/commands/routes/list.js.map +1 -1
- package/dist/cli/commands/routes/list.mjs +28 -0
- package/dist/cli/commands/routes/list.mjs.map +1 -0
- package/dist/cli/commands/services/list.js +2 -2
- package/dist/cli/commands/services/list.js.map +1 -1
- package/dist/cli/commands/services/list.mjs +24 -0
- package/dist/cli/commands/services/list.mjs.map +1 -0
- package/dist/cli/commands/start.js +1 -1
- package/dist/cli/commands/start.js.map +1 -1
- package/dist/cli/commands/start.mjs +24 -0
- package/dist/cli/commands/start.mjs.map +1 -0
- package/dist/cli/commands/telemetry/disable.mjs +67 -0
- package/dist/cli/commands/telemetry/disable.mjs.map +1 -0
- package/dist/cli/commands/telemetry/enable.mjs +86 -0
- package/dist/cli/commands/telemetry/enable.mjs.map +1 -0
- package/dist/cli/commands/templates/generate.mjs +74 -0
- package/dist/cli/commands/templates/generate.mjs.map +1 -0
- package/dist/cli/commands/transfer/action.mjs +131 -0
- package/dist/cli/commands/transfer/action.mjs.map +1 -0
- package/dist/cli/commands/transfer/command.mjs +84 -0
- package/dist/cli/commands/transfer/command.mjs.map +1 -0
- package/dist/cli/commands/ts/generate-types.d.ts.map +1 -1
- package/dist/cli/commands/ts/generate-types.js +4 -5
- package/dist/cli/commands/ts/generate-types.js.map +1 -1
- package/dist/cli/commands/ts/generate-types.mjs +34 -0
- package/dist/cli/commands/ts/generate-types.mjs.map +1 -0
- package/dist/cli/commands/version.mjs +13 -0
- package/dist/cli/commands/version.mjs.map +1 -0
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +30 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/index.mjs +79 -0
- package/dist/cli/index.mjs.map +1 -0
- package/dist/cli/utils/commander.d.ts +2 -2
- package/dist/cli/utils/commander.d.ts.map +1 -1
- package/dist/cli/utils/commander.mjs +109 -0
- package/dist/cli/utils/commander.mjs.map +1 -0
- package/dist/cli/utils/data-transfer.d.ts +5 -5
- package/dist/cli/utils/data-transfer.d.ts.map +1 -1
- package/dist/cli/utils/data-transfer.js +32 -24
- package/dist/cli/utils/data-transfer.js.map +1 -1
- package/dist/cli/utils/data-transfer.mjs +347 -0
- package/dist/cli/utils/data-transfer.mjs.map +1 -0
- package/dist/cli/utils/helpers.d.ts +1 -1
- package/dist/cli/utils/helpers.d.ts.map +1 -1
- package/dist/cli/utils/helpers.mjs +100 -0
- package/dist/cli/utils/helpers.mjs.map +1 -0
- package/dist/cli/utils/logger.mjs +80 -0
- package/dist/cli/utils/logger.mjs.map +1 -0
- package/dist/cli/utils/pkg.d.ts.map +1 -1
- package/dist/cli/utils/telemetry.mjs +22 -0
- package/dist/cli/utils/telemetry.mjs.map +1 -0
- package/dist/cli/utils/tsconfig.d.ts.map +1 -1
- package/dist/cli/utils/tsconfig.mjs +23 -0
- package/dist/cli/utils/tsconfig.mjs.map +1 -0
- package/dist/node/build.mjs +58 -0
- package/dist/node/build.mjs.map +1 -0
- package/dist/node/core/admin-customisations.mjs +22 -0
- package/dist/node/core/admin-customisations.mjs.map +1 -0
- package/dist/node/core/aliases.d.ts +1 -1
- package/dist/node/core/aliases.d.ts.map +1 -1
- package/dist/node/core/aliases.js +8 -5
- package/dist/node/core/aliases.js.map +1 -1
- package/dist/node/core/aliases.mjs +31 -0
- package/dist/node/core/aliases.mjs.map +1 -0
- package/dist/node/core/config.d.ts.map +1 -1
- package/dist/node/core/config.mjs +16 -0
- package/dist/node/core/config.mjs.map +1 -0
- package/dist/node/core/dependencies.d.ts.map +1 -1
- package/dist/node/core/dependencies.js +5 -1
- package/dist/node/core/dependencies.js.map +1 -1
- package/dist/node/core/dependencies.mjs +155 -0
- package/dist/node/core/dependencies.mjs.map +1 -0
- package/dist/node/core/env.d.ts.map +1 -1
- package/dist/node/core/env.js +7 -4
- package/dist/node/core/env.js.map +1 -1
- package/dist/node/core/env.mjs +23 -0
- package/dist/node/core/env.mjs.map +1 -0
- package/dist/node/core/errors.mjs +29 -0
- package/dist/node/core/errors.mjs.map +1 -0
- package/dist/node/core/files.mjs +43 -0
- package/dist/node/core/files.mjs.map +1 -0
- package/dist/node/core/managers.mjs +17 -0
- package/dist/node/core/managers.mjs.map +1 -0
- package/dist/node/core/monorepo.mjs +20 -0
- package/dist/node/core/monorepo.mjs.map +1 -0
- package/dist/node/core/plugins.mjs +93 -0
- package/dist/node/core/plugins.mjs.map +1 -0
- package/dist/node/core/timer.mjs +27 -0
- package/dist/node/core/timer.mjs.map +1 -0
- package/dist/node/create-build-context.d.ts +3 -3
- package/dist/node/create-build-context.d.ts.map +1 -1
- package/dist/node/create-build-context.js +1 -1
- package/dist/node/create-build-context.js.map +1 -1
- package/dist/node/create-build-context.mjs +91 -0
- package/dist/node/create-build-context.mjs.map +1 -0
- package/dist/node/develop.d.ts.map +1 -1
- package/dist/node/develop.js +7 -1
- package/dist/node/develop.js.map +1 -1
- package/dist/node/develop.mjs +252 -0
- package/dist/node/develop.mjs.map +1 -0
- package/dist/node/staticFiles.d.ts.map +1 -1
- package/dist/node/staticFiles.js +25 -3
- package/dist/node/staticFiles.js.map +1 -1
- package/dist/node/staticFiles.mjs +76 -0
- package/dist/node/staticFiles.mjs.map +1 -0
- package/dist/node/types.d.ts +2 -2
- package/dist/node/types.d.ts.map +1 -1
- package/dist/node/vite/build.mjs +12 -0
- package/dist/node/vite/build.mjs.map +1 -0
- package/dist/node/vite/config.mjs +99 -0
- package/dist/node/vite/config.mjs.map +1 -0
- package/dist/node/vite/plugins.mjs +43 -0
- package/dist/node/vite/plugins.mjs.map +1 -0
- package/dist/node/vite/watch.js.map +1 -1
- package/dist/node/vite/watch.mjs +52 -0
- package/dist/node/vite/watch.mjs.map +1 -0
- package/dist/node/webpack/build.mjs +39 -0
- package/dist/node/webpack/build.mjs.map +1 -0
- package/dist/node/webpack/config.mjs +228 -0
- package/dist/node/webpack/config.mjs.map +1 -0
- package/dist/node/webpack/watch.js.map +1 -1
- package/dist/node/webpack/watch.mjs +92 -0
- package/dist/node/webpack/watch.mjs.map +1 -0
- package/package.json +35 -40
- package/dist/cli/commands/plugin/build.d.ts +0 -7
- package/dist/cli/commands/plugin/build.d.ts.map +0 -1
- package/dist/cli/commands/plugin/build.js +0 -88
- package/dist/cli/commands/plugin/build.js.map +0 -1
- package/dist/cli/commands/plugin/init/action.d.ts +0 -7
- package/dist/cli/commands/plugin/init/action.d.ts.map +0 -1
- package/dist/cli/commands/plugin/init/action.js +0 -414
- package/dist/cli/commands/plugin/init/action.js.map +0 -1
- package/dist/cli/commands/plugin/init/command.d.ts +0 -7
- package/dist/cli/commands/plugin/init/command.d.ts.map +0 -1
- package/dist/cli/commands/plugin/init/command.js +0 -9
- package/dist/cli/commands/plugin/init/command.js.map +0 -1
- package/dist/cli/commands/plugin/init/files/admin.d.ts +0 -5
- package/dist/cli/commands/plugin/init/files/admin.d.ts.map +0 -1
- package/dist/cli/commands/plugin/init/files/admin.js +0 -283
- package/dist/cli/commands/plugin/init/files/admin.js.map +0 -1
- package/dist/cli/commands/plugin/init/files/editorConfig.d.ts +0 -4
- package/dist/cli/commands/plugin/init/files/editorConfig.d.ts.map +0 -1
- package/dist/cli/commands/plugin/init/files/editorConfig.js +0 -26
- package/dist/cli/commands/plugin/init/files/editorConfig.js.map +0 -1
- package/dist/cli/commands/plugin/init/files/eslint.d.ts +0 -4
- package/dist/cli/commands/plugin/init/files/eslint.d.ts.map +0 -1
- package/dist/cli/commands/plugin/init/files/eslint.js +0 -11
- package/dist/cli/commands/plugin/init/files/eslint.js.map +0 -1
- package/dist/cli/commands/plugin/init/files/gitIgnore.d.ts +0 -4
- package/dist/cli/commands/plugin/init/files/gitIgnore.d.ts.map +0 -1
- package/dist/cli/commands/plugin/init/files/gitIgnore.js +0 -34
- package/dist/cli/commands/plugin/init/files/gitIgnore.js.map +0 -1
- package/dist/cli/commands/plugin/init/files/prettier.d.ts +0 -5
- package/dist/cli/commands/plugin/init/files/prettier.d.ts.map +0 -1
- package/dist/cli/commands/plugin/init/files/prettier.js +0 -25
- package/dist/cli/commands/plugin/init/files/prettier.js.map +0 -1
- package/dist/cli/commands/plugin/init/files/server.d.ts +0 -5
- package/dist/cli/commands/plugin/init/files/server.d.ts.map +0 -1
- package/dist/cli/commands/plugin/init/files/server.js +0 -360
- package/dist/cli/commands/plugin/init/files/server.js.map +0 -1
- package/dist/cli/commands/plugin/init/files/typescript.js +0 -66
- package/dist/cli/commands/plugin/init/files/typescript.js.map +0 -1
- package/dist/cli/commands/plugin/init/index.d.ts +0 -2
- package/dist/cli/commands/plugin/init/index.d.ts.map +0 -1
- package/dist/cli/commands/plugin/link-watch.d.ts +0 -7
- package/dist/cli/commands/plugin/link-watch.d.ts.map +0 -1
- package/dist/cli/commands/plugin/link-watch.js +0 -89
- package/dist/cli/commands/plugin/link-watch.js.map +0 -1
- package/dist/cli/commands/plugin/verify.d.ts +0 -7
- package/dist/cli/commands/plugin/verify.d.ts.map +0 -1
- package/dist/cli/commands/plugin/verify.js +0 -37
- package/dist/cli/commands/plugin/verify.js.map +0 -1
- package/dist/cli/commands/plugin/watch.d.ts +0 -7
- package/dist/cli/commands/plugin/watch.d.ts.map +0 -1
- package/dist/cli/commands/plugin/watch.js +0 -86
- package/dist/cli/commands/plugin/watch.js.map +0 -1
- package/dist/cli/utils/pkg.js +0 -108
- package/dist/cli/utils/pkg.js.map +0 -1
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import outdent from "outdent";
|
|
4
|
+
import { createElement } from "react";
|
|
5
|
+
import { renderToStaticMarkup } from "react-dom/server";
|
|
6
|
+
import { DefaultDocument } from "@strapi/admin/_internal";
|
|
7
|
+
const getEntryModule = (ctx) => {
|
|
8
|
+
const pluginsObject = ctx.plugins.map(({ name, importName }) => `'${name}': ${importName}`).join(",\n");
|
|
9
|
+
const pluginsImport = ctx.plugins.map(({ importName, modulePath }) => `import ${importName} from '${modulePath}';`).join("\n");
|
|
10
|
+
return outdent`
|
|
11
|
+
/**
|
|
12
|
+
* This file was automatically generated by Strapi.
|
|
13
|
+
* Any modifications made will be discarded.
|
|
14
|
+
*/
|
|
15
|
+
${pluginsImport}
|
|
16
|
+
import { renderAdmin } from "@strapi/strapi/admin"
|
|
17
|
+
|
|
18
|
+
${ctx.customisations?.modulePath ? `import customisations from '${ctx.customisations.modulePath}'` : ""}
|
|
19
|
+
|
|
20
|
+
renderAdmin(
|
|
21
|
+
document.getElementById("strapi"),
|
|
22
|
+
{
|
|
23
|
+
${ctx.customisations?.modulePath ? "customisations," : ""}
|
|
24
|
+
${ctx.features ? `features: ${JSON.stringify(ctx.features)},` : ""}
|
|
25
|
+
plugins: {
|
|
26
|
+
${pluginsObject}
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
`;
|
|
30
|
+
};
|
|
31
|
+
const getDocumentHTML = ({ logger, props = {} }) => {
|
|
32
|
+
const result = renderToStaticMarkup(createElement(DefaultDocument, props));
|
|
33
|
+
logger.debug("Rendered the HTML");
|
|
34
|
+
return outdent`<!DOCTYPE html>${result}`;
|
|
35
|
+
};
|
|
36
|
+
const AUTO_GENERATED_WARNING = `
|
|
37
|
+
This file was automatically generated by Strapi.
|
|
38
|
+
Any modifications made will be discarded.
|
|
39
|
+
`.trim();
|
|
40
|
+
const decorateHTMLWithAutoGeneratedWarning = (htmlTemplate) => htmlTemplate.replace(/<head/, `
|
|
41
|
+
<!--
|
|
42
|
+
${AUTO_GENERATED_WARNING}
|
|
43
|
+
-->
|
|
44
|
+
<head`);
|
|
45
|
+
const writeStaticClientFiles = async (ctx) => {
|
|
46
|
+
const prettier = await import("prettier");
|
|
47
|
+
await fs.mkdir(ctx.runtimeDir, { recursive: true });
|
|
48
|
+
ctx.logger.debug("Created the runtime directory");
|
|
49
|
+
const indexHtml = decorateHTMLWithAutoGeneratedWarning(
|
|
50
|
+
await getDocumentHTML({
|
|
51
|
+
logger: ctx.logger,
|
|
52
|
+
props: ctx.bundler === "vite" ? {
|
|
53
|
+
entryPath: `/${ctx.entry}`
|
|
54
|
+
} : void 0
|
|
55
|
+
})
|
|
56
|
+
);
|
|
57
|
+
await fs.writeFile(
|
|
58
|
+
path.join(ctx.runtimeDir, "index.html"),
|
|
59
|
+
await prettier.format(indexHtml, {
|
|
60
|
+
parser: "html"
|
|
61
|
+
})
|
|
62
|
+
);
|
|
63
|
+
ctx.logger.debug("Wrote the index.html file");
|
|
64
|
+
await fs.writeFile(
|
|
65
|
+
path.join(ctx.runtimeDir, "app.js"),
|
|
66
|
+
await prettier.format(getEntryModule(ctx), {
|
|
67
|
+
parser: "babel"
|
|
68
|
+
})
|
|
69
|
+
);
|
|
70
|
+
ctx.logger.debug("Wrote the app.js file");
|
|
71
|
+
};
|
|
72
|
+
export {
|
|
73
|
+
getDocumentHTML,
|
|
74
|
+
writeStaticClientFiles
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=staticFiles.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"staticFiles.mjs","sources":["../../src/node/staticFiles.ts"],"sourcesContent":["import fs from 'node:fs/promises';\nimport path from 'node:path';\nimport outdent from 'outdent';\nimport { createElement } from 'react';\nimport { renderToStaticMarkup } from 'react-dom/server';\nimport { DefaultDocument } from '@strapi/admin/_internal';\n\nimport type { BuildContext } from './create-build-context';\n\nconst getEntryModule = (ctx: BuildContext): string => {\n const pluginsObject = ctx.plugins\n .map(({ name, importName }) => `'${name}': ${importName}`)\n .join(',\\n');\n\n const pluginsImport = ctx.plugins\n .map(({ importName, modulePath }) => `import ${importName} from '${modulePath}';`)\n .join('\\n');\n\n return outdent`\n /**\n * This file was automatically generated by Strapi.\n * Any modifications made will be discarded.\n */\n ${pluginsImport}\n import { renderAdmin } from \"@strapi/strapi/admin\"\n\n ${\n ctx.customisations?.modulePath\n ? `import customisations from '${ctx.customisations.modulePath}'`\n : ''\n }\n\n renderAdmin(\n document.getElementById(\"strapi\"),\n {\n ${ctx.customisations?.modulePath ? 'customisations,' : ''}\n ${ctx.features ? `features: ${JSON.stringify(ctx.features)},` : ''}\n plugins: {\n ${pluginsObject}\n }\n })\n `;\n};\n\ninterface GetDocumentHTMLArgs extends Pick<BuildContext, 'logger'> {\n props?: {\n entryPath?: string;\n };\n}\n\n/**\n * TODO: Here in the future we could add the ability\n * to load a user's Document component?\n */\nconst getDocumentHTML = ({ logger, props = {} }: GetDocumentHTMLArgs) => {\n const result = renderToStaticMarkup(createElement(DefaultDocument, props));\n logger.debug('Rendered the HTML');\n\n return outdent`<!DOCTYPE html>${result}`;\n};\n\nconst AUTO_GENERATED_WARNING = `\nThis file was automatically generated by Strapi.\nAny modifications made will be discarded.\n`.trim();\n\n/**\n * Because we now auto-generate the index.html file,\n * we should be clear that people _should not_ modify it.\n *\n * @internal\n */\nconst decorateHTMLWithAutoGeneratedWarning = (htmlTemplate: string): string =>\n htmlTemplate.replace(/<head/, `\\n<!--\\n${AUTO_GENERATED_WARNING}\\n-->\\n<head`);\n\nconst writeStaticClientFiles = async (ctx: BuildContext) => {\n const prettier = await import('prettier'); // ESM-only\n\n /**\n * For everything to work effectively we create a client folder in `.strapi` at the cwd level.\n * We then use the function we need to \"createAdmin\" as well as generate the Document index.html as well.\n *\n * All this links together an imaginary \"src/index\" that then allows vite to correctly build the admin panel.\n */\n\n await fs.mkdir(ctx.runtimeDir, { recursive: true });\n ctx.logger.debug('Created the runtime directory');\n\n const indexHtml = decorateHTMLWithAutoGeneratedWarning(\n await getDocumentHTML({\n logger: ctx.logger,\n props:\n ctx.bundler === 'vite'\n ? {\n entryPath: `/${ctx.entry}`,\n }\n : undefined,\n })\n );\n\n await fs.writeFile(\n path.join(ctx.runtimeDir, 'index.html'),\n await prettier.format(indexHtml, {\n parser: 'html',\n })\n );\n ctx.logger.debug('Wrote the index.html file');\n await fs.writeFile(\n path.join(ctx.runtimeDir, 'app.js'),\n await prettier.format(getEntryModule(ctx), {\n parser: 'babel',\n })\n );\n ctx.logger.debug('Wrote the app.js file');\n};\n\nexport { writeStaticClientFiles, getDocumentHTML };\n"],"names":[],"mappings":";;;;;;AASA,MAAM,iBAAiB,CAAC,QAA8B;AACpD,QAAM,gBAAgB,IAAI,QACvB,IAAI,CAAC,EAAE,MAAM,WAAiB,MAAA,IAAI,IAAI,MAAM,UAAU,EAAE,EACxD,KAAK,KAAK;AAEb,QAAM,gBAAgB,IAAI,QACvB,IAAI,CAAC,EAAE,YAAY,WAAiB,MAAA,UAAU,UAAU,UAAU,UAAU,IAAI,EAChF,KAAK,IAAI;AAEL,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA,UAKC,aAAa;AAAA;AAAA;AAAA,UAIb,IAAI,gBAAgB,aAChB,+BAA+B,IAAI,eAAe,UAAU,MAC5D,EACN;AAAA;AAAA;AAAA;AAAA;AAAA,cAKM,IAAI,gBAAgB,aAAa,oBAAoB,EAAE;AAAA,cACvD,IAAI,WAAW,aAAa,KAAK,UAAU,IAAI,QAAQ,CAAC,MAAM,EAAE;AAAA;AAAA,UAEpE,aAAa;AAAA;AAAA;AAAA;AAIvB;AAYA,MAAM,kBAAkB,CAAC,EAAE,QAAQ,QAAQ,SAA8B;AACvE,QAAM,SAAS,qBAAqB,cAAc,iBAAiB,KAAK,CAAC;AACzE,SAAO,MAAM,mBAAmB;AAEhC,SAAO,yBAAyB,MAAM;AACxC;AAEA,MAAM,yBAAyB;AAAA;AAAA;AAAA,EAG7B,KAAK;AAQP,MAAM,uCAAuC,CAAC,iBAC5C,aAAa,QAAQ,SAAS;AAAA;AAAA,EAAW,sBAAsB;AAAA;AAAA,MAAc;AAEzE,MAAA,yBAAyB,OAAO,QAAsB;AACpD,QAAA,WAAW,MAAM,OAAO,UAAU;AASxC,QAAM,GAAG,MAAM,IAAI,YAAY,EAAE,WAAW,MAAM;AAC9C,MAAA,OAAO,MAAM,+BAA+B;AAEhD,QAAM,YAAY;AAAA,IAChB,MAAM,gBAAgB;AAAA,MACpB,QAAQ,IAAI;AAAA,MACZ,OACE,IAAI,YAAY,SACZ;AAAA,QACE,WAAW,IAAI,IAAI,KAAK;AAAA,MAE1B,IAAA;AAAA,IAAA,CACP;AAAA,EAAA;AAGH,QAAM,GAAG;AAAA,IACP,KAAK,KAAK,IAAI,YAAY,YAAY;AAAA,IACtC,MAAM,SAAS,OAAO,WAAW;AAAA,MAC/B,QAAQ;AAAA,IAAA,CACT;AAAA,EAAA;AAEC,MAAA,OAAO,MAAM,2BAA2B;AAC5C,QAAM,GAAG;AAAA,IACP,KAAK,KAAK,IAAI,YAAY,QAAQ;AAAA,IAClC,MAAM,SAAS,OAAO,eAAe,GAAG,GAAG;AAAA,MACzC,QAAQ;AAAA,IAAA,CACT;AAAA,EAAA;AAEC,MAAA,OAAO,MAAM,uBAAuB;AAC1C;"}
|
package/dist/node/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Core } from '@strapi/types';
|
|
2
2
|
import type { CLIContext } from '../cli/types';
|
|
3
3
|
import { BuildOptions } from './build';
|
|
4
4
|
interface BaseContext {
|
|
@@ -43,7 +43,7 @@ interface BaseContext {
|
|
|
43
43
|
/**
|
|
44
44
|
* The Strapi instance
|
|
45
45
|
*/
|
|
46
|
-
strapi: Strapi;
|
|
46
|
+
strapi: Core.Strapi;
|
|
47
47
|
/**
|
|
48
48
|
* The browserslist target either loaded from the user's workspace or falling back to the default
|
|
49
49
|
*/
|
package/dist/node/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/node/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/node/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,UAAU,WAAW;IACnB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS,CAAC,CAAC,SAAS,CAAC,CAAC;IAC5D;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,MAAM,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;IAE7B;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;IACpB;;OAEG;IACH,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,CAAC,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC;CACnC;AAED,YAAY,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { resolveProductionConfig, mergeConfigWithUserConfig } from "./config.mjs";
|
|
2
|
+
const build = async (ctx) => {
|
|
3
|
+
const config = await resolveProductionConfig(ctx);
|
|
4
|
+
const finalConfig = await mergeConfigWithUserConfig(config, ctx);
|
|
5
|
+
const { build: viteBuild } = await import("vite");
|
|
6
|
+
ctx.logger.debug("Vite config", finalConfig);
|
|
7
|
+
await viteBuild(finalConfig);
|
|
8
|
+
};
|
|
9
|
+
export {
|
|
10
|
+
build
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=build.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.mjs","sources":["../../../src/node/vite/build.ts"],"sourcesContent":["import { mergeConfigWithUserConfig, resolveProductionConfig } from './config';\n\nimport type { BuildContext } from '../create-build-context';\n\nconst build = async (ctx: BuildContext) => {\n const config = await resolveProductionConfig(ctx);\n const finalConfig = await mergeConfigWithUserConfig(config, ctx);\n\n const { build: viteBuild } = await import('vite');\n\n ctx.logger.debug('Vite config', finalConfig);\n\n await viteBuild(finalConfig);\n};\n\nexport { build };\n"],"names":[],"mappings":";AAIM,MAAA,QAAQ,OAAO,QAAsB;AACnC,QAAA,SAAS,MAAM,wBAAwB,GAAG;AAChD,QAAM,cAAc,MAAM,0BAA0B,QAAQ,GAAG;AAE/D,QAAM,EAAE,OAAO,UAAc,IAAA,MAAM,OAAO,MAAM;AAE5C,MAAA,OAAO,MAAM,eAAe,WAAW;AAE3C,QAAM,UAAU,WAAW;AAC7B;"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import browserslistToEsbuild from "browserslist-to-esbuild";
|
|
2
|
+
import react from "@vitejs/plugin-react-swc";
|
|
3
|
+
import { getUserConfig } from "../core/config.mjs";
|
|
4
|
+
import { loadStrapiMonorepo } from "../core/monorepo.mjs";
|
|
5
|
+
import { getMonorepoAliases } from "../core/aliases.mjs";
|
|
6
|
+
import { buildFilesPlugin } from "./plugins.mjs";
|
|
7
|
+
const resolveBaseConfig = async (ctx) => {
|
|
8
|
+
const target = browserslistToEsbuild(ctx.target);
|
|
9
|
+
return {
|
|
10
|
+
root: ctx.cwd,
|
|
11
|
+
build: {
|
|
12
|
+
emptyOutDir: false,
|
|
13
|
+
// Rely on CLI to do this
|
|
14
|
+
outDir: ctx.distDir,
|
|
15
|
+
target
|
|
16
|
+
},
|
|
17
|
+
cacheDir: "node_modules/.strapi/vite",
|
|
18
|
+
configFile: false,
|
|
19
|
+
define: {
|
|
20
|
+
"process.env": ctx.env
|
|
21
|
+
},
|
|
22
|
+
envPrefix: "STRAPI_ADMIN_",
|
|
23
|
+
optimizeDeps: {
|
|
24
|
+
include: [
|
|
25
|
+
// pre-bundle React dependencies to avoid React duplicates,
|
|
26
|
+
// even if React dependencies are not direct dependencies
|
|
27
|
+
// https://react.dev/warnings/invalid-hook-call-warning#duplicate-react
|
|
28
|
+
"react",
|
|
29
|
+
`react/jsx-runtime`,
|
|
30
|
+
"react-dom/client",
|
|
31
|
+
"styled-components",
|
|
32
|
+
"react-router-dom"
|
|
33
|
+
]
|
|
34
|
+
},
|
|
35
|
+
resolve: {
|
|
36
|
+
// https://react.dev/warnings/invalid-hook-call-warning#duplicate-react
|
|
37
|
+
dedupe: ["react", "react-dom", "react-router-dom", "styled-components"]
|
|
38
|
+
},
|
|
39
|
+
plugins: [react(), buildFilesPlugin(ctx)]
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
const resolveProductionConfig = async (ctx) => {
|
|
43
|
+
const {
|
|
44
|
+
options: { minify, sourcemaps }
|
|
45
|
+
} = ctx;
|
|
46
|
+
const baseConfig = await resolveBaseConfig(ctx);
|
|
47
|
+
return {
|
|
48
|
+
...baseConfig,
|
|
49
|
+
base: ctx.basePath,
|
|
50
|
+
logLevel: "silent",
|
|
51
|
+
mode: "production",
|
|
52
|
+
build: {
|
|
53
|
+
...baseConfig.build,
|
|
54
|
+
assetsDir: "",
|
|
55
|
+
minify,
|
|
56
|
+
sourcemap: sourcemaps,
|
|
57
|
+
rollupOptions: {
|
|
58
|
+
input: {
|
|
59
|
+
strapi: ctx.entry
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
const resolveDevelopmentConfig = async (ctx) => {
|
|
66
|
+
const monorepo = await loadStrapiMonorepo(ctx.cwd);
|
|
67
|
+
const baseConfig = await resolveBaseConfig(ctx);
|
|
68
|
+
return {
|
|
69
|
+
...baseConfig,
|
|
70
|
+
mode: "development",
|
|
71
|
+
resolve: {
|
|
72
|
+
...baseConfig.resolve,
|
|
73
|
+
alias: {
|
|
74
|
+
...baseConfig.resolve?.alias,
|
|
75
|
+
...getMonorepoAliases({ monorepo })
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
server: {
|
|
79
|
+
middlewareMode: true,
|
|
80
|
+
open: ctx.options.open,
|
|
81
|
+
hmr: true
|
|
82
|
+
},
|
|
83
|
+
appType: "custom"
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
const USER_CONFIGS = ["vite.config.js", "vite.config.mjs", "vite.config.ts"];
|
|
87
|
+
const mergeConfigWithUserConfig = async (config, ctx) => {
|
|
88
|
+
const userConfig = await getUserConfig(USER_CONFIGS, ctx);
|
|
89
|
+
if (userConfig) {
|
|
90
|
+
return userConfig(config);
|
|
91
|
+
}
|
|
92
|
+
return config;
|
|
93
|
+
};
|
|
94
|
+
export {
|
|
95
|
+
mergeConfigWithUserConfig,
|
|
96
|
+
resolveDevelopmentConfig,
|
|
97
|
+
resolveProductionConfig
|
|
98
|
+
};
|
|
99
|
+
//# sourceMappingURL=config.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.mjs","sources":["../../../src/node/vite/config.ts"],"sourcesContent":["import type { InlineConfig, UserConfig } from 'vite';\nimport browserslistToEsbuild from 'browserslist-to-esbuild';\nimport react from '@vitejs/plugin-react-swc';\n\nimport { getUserConfig } from '../core/config';\nimport { loadStrapiMonorepo } from '../core/monorepo';\nimport { getMonorepoAliases } from '../core/aliases';\nimport type { BuildContext } from '../create-build-context';\nimport { buildFilesPlugin } from './plugins';\n\nconst resolveBaseConfig = async (ctx: BuildContext): Promise<InlineConfig> => {\n const target = browserslistToEsbuild(ctx.target);\n\n return {\n root: ctx.cwd,\n build: {\n emptyOutDir: false, // Rely on CLI to do this\n outDir: ctx.distDir,\n target,\n },\n cacheDir: 'node_modules/.strapi/vite',\n configFile: false,\n define: {\n 'process.env': ctx.env,\n },\n envPrefix: 'STRAPI_ADMIN_',\n optimizeDeps: {\n include: [\n // pre-bundle React dependencies to avoid React duplicates,\n // even if React dependencies are not direct dependencies\n // https://react.dev/warnings/invalid-hook-call-warning#duplicate-react\n 'react',\n `react/jsx-runtime`,\n 'react-dom/client',\n 'styled-components',\n 'react-router-dom',\n ],\n },\n resolve: {\n // https://react.dev/warnings/invalid-hook-call-warning#duplicate-react\n dedupe: ['react', 'react-dom', 'react-router-dom', 'styled-components'],\n },\n plugins: [react(), buildFilesPlugin(ctx)],\n };\n};\n\nconst resolveProductionConfig = async (ctx: BuildContext): Promise<InlineConfig> => {\n const {\n options: { minify, sourcemaps },\n } = ctx;\n\n const baseConfig = await resolveBaseConfig(ctx);\n\n return {\n ...baseConfig,\n base: ctx.basePath,\n logLevel: 'silent',\n mode: 'production',\n build: {\n ...baseConfig.build,\n assetsDir: '',\n minify,\n sourcemap: sourcemaps,\n rollupOptions: {\n input: {\n strapi: ctx.entry,\n },\n },\n },\n };\n};\n\nconst resolveDevelopmentConfig = async (ctx: BuildContext): Promise<InlineConfig> => {\n const monorepo = await loadStrapiMonorepo(ctx.cwd);\n const baseConfig = await resolveBaseConfig(ctx);\n\n return {\n ...baseConfig,\n mode: 'development',\n resolve: {\n ...baseConfig.resolve,\n alias: {\n ...baseConfig.resolve?.alias,\n ...getMonorepoAliases({ monorepo }),\n },\n },\n server: {\n middlewareMode: true,\n open: ctx.options.open,\n hmr: true,\n },\n appType: 'custom',\n };\n};\n\nconst USER_CONFIGS = ['vite.config.js', 'vite.config.mjs', 'vite.config.ts'];\n\ntype UserViteConfig = (config: UserConfig) => UserConfig;\n\nconst mergeConfigWithUserConfig = async (config: InlineConfig, ctx: BuildContext) => {\n const userConfig = await getUserConfig<UserViteConfig>(USER_CONFIGS, ctx);\n\n if (userConfig) {\n return userConfig(config);\n }\n\n return config;\n};\n\nexport { mergeConfigWithUserConfig, resolveProductionConfig, resolveDevelopmentConfig };\n"],"names":[],"mappings":";;;;;;AAUA,MAAM,oBAAoB,OAAO,QAA6C;AACtE,QAAA,SAAS,sBAAsB,IAAI,MAAM;AAExC,SAAA;AAAA,IACL,MAAM,IAAI;AAAA,IACV,OAAO;AAAA,MACL,aAAa;AAAA;AAAA,MACb,QAAQ,IAAI;AAAA,MACZ;AAAA,IACF;AAAA,IACA,UAAU;AAAA,IACV,YAAY;AAAA,IACZ,QAAQ;AAAA,MACN,eAAe,IAAI;AAAA,IACrB;AAAA,IACA,WAAW;AAAA,IACX,cAAc;AAAA,MACZ,SAAS;AAAA;AAAA;AAAA;AAAA,QAIP;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,IACA,SAAS;AAAA;AAAA,MAEP,QAAQ,CAAC,SAAS,aAAa,oBAAoB,mBAAmB;AAAA,IACxE;AAAA,IACA,SAAS,CAAC,MAAA,GAAS,iBAAiB,GAAG,CAAC;AAAA,EAAA;AAE5C;AAEM,MAAA,0BAA0B,OAAO,QAA6C;AAC5E,QAAA;AAAA,IACJ,SAAS,EAAE,QAAQ,WAAW;AAAA,EAC5B,IAAA;AAEE,QAAA,aAAa,MAAM,kBAAkB,GAAG;AAEvC,SAAA;AAAA,IACL,GAAG;AAAA,IACH,MAAM,IAAI;AAAA,IACV,UAAU;AAAA,IACV,MAAM;AAAA,IACN,OAAO;AAAA,MACL,GAAG,WAAW;AAAA,MACd,WAAW;AAAA,MACX;AAAA,MACA,WAAW;AAAA,MACX,eAAe;AAAA,QACb,OAAO;AAAA,UACL,QAAQ,IAAI;AAAA,QACd;AAAA,MACF;AAAA,IACF;AAAA,EAAA;AAEJ;AAEM,MAAA,2BAA2B,OAAO,QAA6C;AACnF,QAAM,WAAW,MAAM,mBAAmB,IAAI,GAAG;AAC3C,QAAA,aAAa,MAAM,kBAAkB,GAAG;AAEvC,SAAA;AAAA,IACL,GAAG;AAAA,IACH,MAAM;AAAA,IACN,SAAS;AAAA,MACP,GAAG,WAAW;AAAA,MACd,OAAO;AAAA,QACL,GAAG,WAAW,SAAS;AAAA,QACvB,GAAG,mBAAmB,EAAE,UAAU;AAAA,MACpC;AAAA,IACF;AAAA,IACA,QAAQ;AAAA,MACN,gBAAgB;AAAA,MAChB,MAAM,IAAI,QAAQ;AAAA,MAClB,KAAK;AAAA,IACP;AAAA,IACA,SAAS;AAAA,EAAA;AAEb;AAEA,MAAM,eAAe,CAAC,kBAAkB,mBAAmB,gBAAgB;AAIrE,MAAA,4BAA4B,OAAO,QAAsB,QAAsB;AACnF,QAAM,aAAa,MAAM,cAA8B,cAAc,GAAG;AAExE,MAAI,YAAY;AACd,WAAO,WAAW,MAAM;AAAA,EAC1B;AAEO,SAAA;AACT;"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { getDocumentHTML } from "../staticFiles.mjs";
|
|
2
|
+
const buildFilesPlugin = (ctx) => {
|
|
3
|
+
const CHUNK_ID = ".strapi/client/app.js";
|
|
4
|
+
return {
|
|
5
|
+
name: "strapi/server/build-files",
|
|
6
|
+
apply: "build",
|
|
7
|
+
buildStart() {
|
|
8
|
+
this.emitFile({
|
|
9
|
+
type: "chunk",
|
|
10
|
+
id: CHUNK_ID,
|
|
11
|
+
name: "strapi"
|
|
12
|
+
});
|
|
13
|
+
},
|
|
14
|
+
async generateBundle(_options, outputBundle) {
|
|
15
|
+
const bundle = outputBundle;
|
|
16
|
+
const entryFile = Object.values(bundle).find(
|
|
17
|
+
(file) => file.type === "chunk" && file.name === "strapi" && file.facadeModuleId?.endsWith(CHUNK_ID)
|
|
18
|
+
);
|
|
19
|
+
if (!entryFile) {
|
|
20
|
+
throw new Error(`Failed to find entry file in bundle (${CHUNK_ID})`);
|
|
21
|
+
}
|
|
22
|
+
if (entryFile.type !== "chunk") {
|
|
23
|
+
throw new Error("Entry file is not a chunk");
|
|
24
|
+
}
|
|
25
|
+
const entryFileName = entryFile.fileName;
|
|
26
|
+
const entryPath = ["/admin".replace(/\/+$/, ""), entryFileName].join("/");
|
|
27
|
+
this.emitFile({
|
|
28
|
+
type: "asset",
|
|
29
|
+
fileName: "index.html",
|
|
30
|
+
source: getDocumentHTML({
|
|
31
|
+
logger: ctx.logger,
|
|
32
|
+
props: {
|
|
33
|
+
entryPath
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export {
|
|
41
|
+
buildFilesPlugin
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=plugins.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins.mjs","sources":["../../../src/node/vite/plugins.ts"],"sourcesContent":["import type { Plugin } from 'vite';\n\nimport { getDocumentHTML } from '../staticFiles';\nimport type { BuildContext } from '../create-build-context';\n\nconst buildFilesPlugin = (ctx: BuildContext): Plugin => {\n const CHUNK_ID = '.strapi/client/app.js';\n\n return {\n name: 'strapi/server/build-files',\n apply: 'build',\n buildStart() {\n this.emitFile({\n type: 'chunk',\n id: CHUNK_ID,\n name: 'strapi',\n });\n },\n async generateBundle(_options, outputBundle) {\n const bundle = outputBundle;\n const entryFile = Object.values(bundle).find(\n (file) =>\n file.type === 'chunk' && file.name === 'strapi' && file.facadeModuleId?.endsWith(CHUNK_ID)\n );\n\n if (!entryFile) {\n throw new Error(`Failed to find entry file in bundle (${CHUNK_ID})`);\n }\n\n if (entryFile.type !== 'chunk') {\n throw new Error('Entry file is not a chunk');\n }\n\n const entryFileName = entryFile.fileName;\n const entryPath = ['/admin'.replace(/\\/+$/, ''), entryFileName].join('/');\n\n this.emitFile({\n type: 'asset',\n fileName: 'index.html',\n source: getDocumentHTML({\n logger: ctx.logger,\n props: {\n entryPath,\n },\n }),\n });\n },\n };\n};\n\nexport { buildFilesPlugin };\n"],"names":[],"mappings":";AAKM,MAAA,mBAAmB,CAAC,QAA8B;AACtD,QAAM,WAAW;AAEV,SAAA;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,aAAa;AACX,WAAK,SAAS;AAAA,QACZ,MAAM;AAAA,QACN,IAAI;AAAA,QACJ,MAAM;AAAA,MAAA,CACP;AAAA,IACH;AAAA,IACA,MAAM,eAAe,UAAU,cAAc;AAC3C,YAAM,SAAS;AACf,YAAM,YAAY,OAAO,OAAO,MAAM,EAAE;AAAA,QACtC,CAAC,SACC,KAAK,SAAS,WAAW,KAAK,SAAS,YAAY,KAAK,gBAAgB,SAAS,QAAQ;AAAA,MAAA;AAG7F,UAAI,CAAC,WAAW;AACd,cAAM,IAAI,MAAM,wCAAwC,QAAQ,GAAG;AAAA,MACrE;AAEI,UAAA,UAAU,SAAS,SAAS;AACxB,cAAA,IAAI,MAAM,2BAA2B;AAAA,MAC7C;AAEA,YAAM,gBAAgB,UAAU;AAC1B,YAAA,YAAY,CAAC,SAAS,QAAQ,QAAQ,EAAE,GAAG,aAAa,EAAE,KAAK,GAAG;AAExE,WAAK,SAAS;AAAA,QACZ,MAAM;AAAA,QACN,UAAU;AAAA,QACV,QAAQ,gBAAgB;AAAA,UACtB,QAAQ,IAAI;AAAA,UACZ,OAAO;AAAA,YACL;AAAA,UACF;AAAA,QAAA,CACD;AAAA,MAAA,CACF;AAAA,IACH;AAAA,EAAA;AAEJ;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watch.js","sources":["../../../src/node/vite/watch.ts"],"sourcesContent":["import path from 'node:path';\nimport fs from 'node:fs/promises';\nimport type {
|
|
1
|
+
{"version":3,"file":"watch.js","sources":["../../../src/node/vite/watch.ts"],"sourcesContent":["import path from 'node:path';\nimport fs from 'node:fs/promises';\nimport type { Core } from '@strapi/types';\n\nimport { mergeConfigWithUserConfig, resolveDevelopmentConfig } from './config';\n\nimport type { BuildContext } from '../create-build-context';\n\ninterface ViteWatcher {\n close(): Promise<void>;\n}\n\nconst watch = async (ctx: BuildContext): Promise<ViteWatcher> => {\n const config = await resolveDevelopmentConfig(ctx);\n const finalConfig = await mergeConfigWithUserConfig(config, ctx);\n\n ctx.logger.debug('Vite config', finalConfig);\n\n const { createServer } = await import('vite');\n\n const vite = await createServer(finalConfig);\n\n ctx.strapi.server.app.use((ctx, next) => {\n return new Promise((resolve, reject) => {\n vite.middlewares(ctx.req, ctx.res, (err: unknown) => {\n if (err) {\n reject(err);\n } else {\n resolve(next());\n }\n });\n });\n });\n\n const serveAdmin: Core.MiddlewareHandler = async (koaCtx, next) => {\n await next();\n\n if (koaCtx.method !== 'HEAD' && koaCtx.method !== 'GET') {\n return;\n }\n\n if (koaCtx.body != null || koaCtx.status !== 404) {\n return;\n }\n\n const url = koaCtx.originalUrl;\n\n let template = await fs.readFile(path.relative(ctx.cwd, '.strapi/client/index.html'), 'utf-8');\n template = await vite.transformIndexHtml(url, template);\n\n koaCtx.type = 'html';\n koaCtx.body = template;\n };\n\n ctx.strapi.server.routes([\n {\n method: 'GET',\n path: `${ctx.basePath}:path*`,\n handler: serveAdmin,\n config: { auth: false },\n },\n ]);\n\n return {\n async close() {\n await vite.close();\n },\n };\n};\n\nexport { watch };\nexport type { ViteWatcher };\n"],"names":["config","resolveDevelopmentConfig","mergeConfigWithUserConfig","ctx","fs","path"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYM,MAAA,QAAQ,OAAO,QAA4C;AACzD,QAAAA,WAAS,MAAMC,gCAAyB,GAAG;AACjD,QAAM,cAAc,MAAMC,OAAAA,0BAA0BF,UAAQ,GAAG;AAE3D,MAAA,OAAO,MAAM,eAAe,WAAW;AAE3C,QAAM,EAAE,aAAA,IAAiB,MAAM,OAAO,MAAM;AAEtC,QAAA,OAAO,MAAM,aAAa,WAAW;AAE3C,MAAI,OAAO,OAAO,IAAI,IAAI,CAACG,MAAK,SAAS;AACvC,WAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,WAAK,YAAYA,KAAI,KAAKA,KAAI,KAAK,CAAC,QAAiB;AACnD,YAAI,KAAK;AACP,iBAAO,GAAG;AAAA,QAAA,OACL;AACL,kBAAQ,MAAM;AAAA,QAChB;AAAA,MAAA,CACD;AAAA,IAAA,CACF;AAAA,EAAA,CACF;AAEK,QAAA,aAAqC,OAAO,QAAQ,SAAS;AACjE,UAAM,KAAK;AAEX,QAAI,OAAO,WAAW,UAAU,OAAO,WAAW,OAAO;AACvD;AAAA,IACF;AAEA,QAAI,OAAO,QAAQ,QAAQ,OAAO,WAAW,KAAK;AAChD;AAAA,IACF;AAEA,UAAM,MAAM,OAAO;AAEf,QAAA,WAAW,MAAMC,oBAAG,SAASC,cAAA,QAAK,SAAS,IAAI,KAAK,2BAA2B,GAAG,OAAO;AAC7F,eAAW,MAAM,KAAK,mBAAmB,KAAK,QAAQ;AAEtD,WAAO,OAAO;AACd,WAAO,OAAO;AAAA,EAAA;AAGZ,MAAA,OAAO,OAAO,OAAO;AAAA,IACvB;AAAA,MACE,QAAQ;AAAA,MACR,MAAM,GAAG,IAAI,QAAQ;AAAA,MACrB,SAAS;AAAA,MACT,QAAQ,EAAE,MAAM,MAAM;AAAA,IACxB;AAAA,EAAA,CACD;AAEM,SAAA;AAAA,IACL,MAAM,QAAQ;AACZ,YAAM,KAAK;IACb;AAAA,EAAA;AAEJ;;"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import { resolveDevelopmentConfig, mergeConfigWithUserConfig } from "./config.mjs";
|
|
4
|
+
const watch = async (ctx) => {
|
|
5
|
+
const config = await resolveDevelopmentConfig(ctx);
|
|
6
|
+
const finalConfig = await mergeConfigWithUserConfig(config, ctx);
|
|
7
|
+
ctx.logger.debug("Vite config", finalConfig);
|
|
8
|
+
const { createServer } = await import("vite");
|
|
9
|
+
const vite = await createServer(finalConfig);
|
|
10
|
+
ctx.strapi.server.app.use((ctx2, next) => {
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
|
+
vite.middlewares(ctx2.req, ctx2.res, (err) => {
|
|
13
|
+
if (err) {
|
|
14
|
+
reject(err);
|
|
15
|
+
} else {
|
|
16
|
+
resolve(next());
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
const serveAdmin = async (koaCtx, next) => {
|
|
22
|
+
await next();
|
|
23
|
+
if (koaCtx.method !== "HEAD" && koaCtx.method !== "GET") {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (koaCtx.body != null || koaCtx.status !== 404) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const url = koaCtx.originalUrl;
|
|
30
|
+
let template = await fs.readFile(path.relative(ctx.cwd, ".strapi/client/index.html"), "utf-8");
|
|
31
|
+
template = await vite.transformIndexHtml(url, template);
|
|
32
|
+
koaCtx.type = "html";
|
|
33
|
+
koaCtx.body = template;
|
|
34
|
+
};
|
|
35
|
+
ctx.strapi.server.routes([
|
|
36
|
+
{
|
|
37
|
+
method: "GET",
|
|
38
|
+
path: `${ctx.basePath}:path*`,
|
|
39
|
+
handler: serveAdmin,
|
|
40
|
+
config: { auth: false }
|
|
41
|
+
}
|
|
42
|
+
]);
|
|
43
|
+
return {
|
|
44
|
+
async close() {
|
|
45
|
+
await vite.close();
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
export {
|
|
50
|
+
watch
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=watch.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watch.mjs","sources":["../../../src/node/vite/watch.ts"],"sourcesContent":["import path from 'node:path';\nimport fs from 'node:fs/promises';\nimport type { Core } from '@strapi/types';\n\nimport { mergeConfigWithUserConfig, resolveDevelopmentConfig } from './config';\n\nimport type { BuildContext } from '../create-build-context';\n\ninterface ViteWatcher {\n close(): Promise<void>;\n}\n\nconst watch = async (ctx: BuildContext): Promise<ViteWatcher> => {\n const config = await resolveDevelopmentConfig(ctx);\n const finalConfig = await mergeConfigWithUserConfig(config, ctx);\n\n ctx.logger.debug('Vite config', finalConfig);\n\n const { createServer } = await import('vite');\n\n const vite = await createServer(finalConfig);\n\n ctx.strapi.server.app.use((ctx, next) => {\n return new Promise((resolve, reject) => {\n vite.middlewares(ctx.req, ctx.res, (err: unknown) => {\n if (err) {\n reject(err);\n } else {\n resolve(next());\n }\n });\n });\n });\n\n const serveAdmin: Core.MiddlewareHandler = async (koaCtx, next) => {\n await next();\n\n if (koaCtx.method !== 'HEAD' && koaCtx.method !== 'GET') {\n return;\n }\n\n if (koaCtx.body != null || koaCtx.status !== 404) {\n return;\n }\n\n const url = koaCtx.originalUrl;\n\n let template = await fs.readFile(path.relative(ctx.cwd, '.strapi/client/index.html'), 'utf-8');\n template = await vite.transformIndexHtml(url, template);\n\n koaCtx.type = 'html';\n koaCtx.body = template;\n };\n\n ctx.strapi.server.routes([\n {\n method: 'GET',\n path: `${ctx.basePath}:path*`,\n handler: serveAdmin,\n config: { auth: false },\n },\n ]);\n\n return {\n async close() {\n await vite.close();\n },\n };\n};\n\nexport { watch };\nexport type { ViteWatcher };\n"],"names":["ctx"],"mappings":";;;AAYM,MAAA,QAAQ,OAAO,QAA4C;AACzD,QAAA,SAAS,MAAM,yBAAyB,GAAG;AACjD,QAAM,cAAc,MAAM,0BAA0B,QAAQ,GAAG;AAE3D,MAAA,OAAO,MAAM,eAAe,WAAW;AAE3C,QAAM,EAAE,aAAA,IAAiB,MAAM,OAAO,MAAM;AAEtC,QAAA,OAAO,MAAM,aAAa,WAAW;AAE3C,MAAI,OAAO,OAAO,IAAI,IAAI,CAACA,MAAK,SAAS;AACvC,WAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,WAAK,YAAYA,KAAI,KAAKA,KAAI,KAAK,CAAC,QAAiB;AACnD,YAAI,KAAK;AACP,iBAAO,GAAG;AAAA,QAAA,OACL;AACL,kBAAQ,MAAM;AAAA,QAChB;AAAA,MAAA,CACD;AAAA,IAAA,CACF;AAAA,EAAA,CACF;AAEK,QAAA,aAAqC,OAAO,QAAQ,SAAS;AACjE,UAAM,KAAK;AAEX,QAAI,OAAO,WAAW,UAAU,OAAO,WAAW,OAAO;AACvD;AAAA,IACF;AAEA,QAAI,OAAO,QAAQ,QAAQ,OAAO,WAAW,KAAK;AAChD;AAAA,IACF;AAEA,UAAM,MAAM,OAAO;AAEf,QAAA,WAAW,MAAM,GAAG,SAAS,KAAK,SAAS,IAAI,KAAK,2BAA2B,GAAG,OAAO;AAC7F,eAAW,MAAM,KAAK,mBAAmB,KAAK,QAAQ;AAEtD,WAAO,OAAO;AACd,WAAO,OAAO;AAAA,EAAA;AAGZ,MAAA,OAAO,OAAO,OAAO;AAAA,IACvB;AAAA,MACE,QAAQ;AAAA,MACR,MAAM,GAAG,IAAI,QAAQ;AAAA,MACrB,SAAS;AAAA,MACT,QAAQ,EAAE,MAAM,MAAM;AAAA,IACxB;AAAA,EAAA,CACD;AAEM,SAAA;AAAA,IACL,MAAM,QAAQ;AACZ,YAAM,KAAK;IACb;AAAA,EAAA;AAEJ;"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import webpack from "webpack";
|
|
2
|
+
import { resolveProductionConfig, mergeConfigWithUserConfig } from "./config.mjs";
|
|
3
|
+
import { isError } from "../core/errors.mjs";
|
|
4
|
+
const build = async (ctx) => {
|
|
5
|
+
const config = await resolveProductionConfig(ctx);
|
|
6
|
+
const finalConfig = await mergeConfigWithUserConfig(config, ctx);
|
|
7
|
+
ctx.logger.debug("Webpack config", finalConfig);
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
webpack(finalConfig, (err, stats) => {
|
|
10
|
+
if (stats) {
|
|
11
|
+
if (stats.hasErrors()) {
|
|
12
|
+
ctx.logger.error(
|
|
13
|
+
stats.toString({
|
|
14
|
+
chunks: false,
|
|
15
|
+
colors: true
|
|
16
|
+
})
|
|
17
|
+
);
|
|
18
|
+
reject();
|
|
19
|
+
} else if (ctx.options.stats) {
|
|
20
|
+
ctx.logger.info(
|
|
21
|
+
stats.toString({
|
|
22
|
+
chunks: false,
|
|
23
|
+
colors: true
|
|
24
|
+
})
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
resolve(true);
|
|
28
|
+
}
|
|
29
|
+
if (err && isError(err)) {
|
|
30
|
+
ctx.logger.error(err.message);
|
|
31
|
+
reject();
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
export {
|
|
37
|
+
build
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=build.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.mjs","sources":["../../../src/node/webpack/build.ts"],"sourcesContent":["import webpack from 'webpack';\n\nimport { mergeConfigWithUserConfig, resolveProductionConfig } from './config';\nimport { isError } from '../core/errors';\n\nimport type { BuildContext } from '../create-build-context';\n\nconst build = async (ctx: BuildContext) => {\n const config = await resolveProductionConfig(ctx);\n const finalConfig = await mergeConfigWithUserConfig(config, ctx);\n\n ctx.logger.debug('Webpack config', finalConfig);\n\n return new Promise((resolve, reject) => {\n webpack(finalConfig, (err, stats) => {\n if (stats) {\n if (stats.hasErrors()) {\n ctx.logger.error(\n stats.toString({\n chunks: false,\n colors: true,\n })\n );\n\n reject();\n } else if (ctx.options.stats) {\n ctx.logger.info(\n stats.toString({\n chunks: false,\n colors: true,\n })\n );\n }\n\n resolve(true);\n }\n\n if (err && isError(err)) {\n ctx.logger.error(err.message);\n reject();\n }\n });\n });\n};\n\nexport { build };\n"],"names":[],"mappings":";;;AAOM,MAAA,QAAQ,OAAO,QAAsB;AACnC,QAAA,SAAS,MAAM,wBAAwB,GAAG;AAChD,QAAM,cAAc,MAAM,0BAA0B,QAAQ,GAAG;AAE3D,MAAA,OAAO,MAAM,kBAAkB,WAAW;AAE9C,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AAC9B,YAAA,aAAa,CAAC,KAAK,UAAU;AACnC,UAAI,OAAO;AACL,YAAA,MAAM,aAAa;AACrB,cAAI,OAAO;AAAA,YACT,MAAM,SAAS;AAAA,cACb,QAAQ;AAAA,cACR,QAAQ;AAAA,YAAA,CACT;AAAA,UAAA;AAGI;QAAA,WACE,IAAI,QAAQ,OAAO;AAC5B,cAAI,OAAO;AAAA,YACT,MAAM,SAAS;AAAA,cACb,QAAQ;AAAA,cACR,QAAQ;AAAA,YAAA,CACT;AAAA,UAAA;AAAA,QAEL;AAEA,gBAAQ,IAAI;AAAA,MACd;AAEI,UAAA,OAAO,QAAQ,GAAG,GAAG;AACnB,YAAA,OAAO,MAAM,IAAI,OAAO;AACrB;MACT;AAAA,IAAA,CACD;AAAA,EAAA,CACF;AACH;"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import ReactRefreshWebpackPlugin from "@pmmmwh/react-refresh-webpack-plugin";
|
|
2
|
+
import browserslistToEsbuild from "browserslist-to-esbuild";
|
|
3
|
+
import { ESBuildMinifyPlugin } from "esbuild-loader";
|
|
4
|
+
import ForkTsCheckerPlugin from "fork-ts-checker-webpack-plugin";
|
|
5
|
+
import HtmlWebpackPlugin from "html-webpack-plugin";
|
|
6
|
+
import MiniCssExtractPlugin from "mini-css-extract-plugin";
|
|
7
|
+
import crypto from "node:crypto";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import readPkgUp from "read-pkg-up";
|
|
10
|
+
import { HotModuleReplacementPlugin, DefinePlugin } from "webpack";
|
|
11
|
+
import { BundleAnalyzerPlugin } from "webpack-bundle-analyzer";
|
|
12
|
+
import { loadStrapiMonorepo } from "../core/monorepo.mjs";
|
|
13
|
+
import { getUserConfig } from "../core/config.mjs";
|
|
14
|
+
import { getMonorepoAliases } from "../core/aliases.mjs";
|
|
15
|
+
const resolveBaseConfig = async (ctx) => {
|
|
16
|
+
const target = browserslistToEsbuild(ctx.target);
|
|
17
|
+
return {
|
|
18
|
+
experiments: {
|
|
19
|
+
topLevelAwait: true
|
|
20
|
+
},
|
|
21
|
+
entry: {
|
|
22
|
+
main: [`./${ctx.entry}`]
|
|
23
|
+
},
|
|
24
|
+
resolve: {
|
|
25
|
+
alias: {
|
|
26
|
+
react: getModulePath("react"),
|
|
27
|
+
"react-dom": getModulePath("react-dom"),
|
|
28
|
+
"styled-components": getModulePath("styled-components"),
|
|
29
|
+
"react-router-dom": getModulePath("react-router-dom")
|
|
30
|
+
},
|
|
31
|
+
extensions: [".js", ".jsx", ".react.js", ".ts", ".tsx"]
|
|
32
|
+
},
|
|
33
|
+
module: {
|
|
34
|
+
rules: [
|
|
35
|
+
{
|
|
36
|
+
test: /\.(ts|tsx)$/,
|
|
37
|
+
loader: require.resolve("esbuild-loader"),
|
|
38
|
+
options: {
|
|
39
|
+
loader: "tsx",
|
|
40
|
+
target,
|
|
41
|
+
jsx: "automatic"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
test: /\.(js|jsx|mjs)$/,
|
|
46
|
+
use: {
|
|
47
|
+
loader: require.resolve("esbuild-loader"),
|
|
48
|
+
options: {
|
|
49
|
+
loader: "jsx",
|
|
50
|
+
target,
|
|
51
|
+
jsx: "automatic"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
test: /\.m?js/,
|
|
57
|
+
resolve: {
|
|
58
|
+
fullySpecified: false
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
test: /\.css$/i,
|
|
63
|
+
use: [require.resolve("style-loader"), require.resolve("css-loader")]
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
test: /\.(svg|eot|otf|ttf|woff|woff2)$/,
|
|
67
|
+
type: "asset/resource"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/, /\.ico$/],
|
|
71
|
+
type: "asset",
|
|
72
|
+
parser: {
|
|
73
|
+
dataUrlCondition: {
|
|
74
|
+
maxSize: 1e3
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
test: /\.(mp4|webm)$/,
|
|
80
|
+
type: "asset",
|
|
81
|
+
parser: {
|
|
82
|
+
dataUrlCondition: {
|
|
83
|
+
maxSize: 1e4
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
},
|
|
89
|
+
plugins: [
|
|
90
|
+
new HtmlWebpackPlugin({
|
|
91
|
+
inject: true,
|
|
92
|
+
template: path.resolve(ctx.runtimeDir, "index.html")
|
|
93
|
+
}),
|
|
94
|
+
new DefinePlugin(
|
|
95
|
+
Object.entries(ctx.env).reduce((acc, [key, value]) => {
|
|
96
|
+
acc[`process.env.${key}`] = JSON.stringify(value);
|
|
97
|
+
return acc;
|
|
98
|
+
}, {})
|
|
99
|
+
),
|
|
100
|
+
ctx.tsconfig && new ForkTsCheckerPlugin({
|
|
101
|
+
typescript: {
|
|
102
|
+
configFile: ctx.tsconfig.path,
|
|
103
|
+
configOverwrite: {
|
|
104
|
+
compilerOptions: {
|
|
105
|
+
sourceMap: ctx.options.sourcemaps
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
].filter(Boolean)
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
const resolveDevelopmentConfig = async (ctx) => {
|
|
114
|
+
const baseConfig = await resolveBaseConfig(ctx);
|
|
115
|
+
const monorepo = await loadStrapiMonorepo(ctx.cwd);
|
|
116
|
+
return {
|
|
117
|
+
...baseConfig,
|
|
118
|
+
cache: {
|
|
119
|
+
type: "filesystem",
|
|
120
|
+
// version cache when there are changes to aliases
|
|
121
|
+
buildDependencies: {
|
|
122
|
+
config: [__filename]
|
|
123
|
+
},
|
|
124
|
+
version: crypto.createHash("md5").update(Object.entries(baseConfig.resolve.alias ?? {}).join()).digest("hex")
|
|
125
|
+
},
|
|
126
|
+
resolve: {
|
|
127
|
+
...baseConfig.resolve,
|
|
128
|
+
alias: {
|
|
129
|
+
...baseConfig.resolve.alias,
|
|
130
|
+
...getMonorepoAliases({ monorepo })
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
entry: {
|
|
134
|
+
...baseConfig.entry,
|
|
135
|
+
main: [
|
|
136
|
+
`${require.resolve("webpack-hot-middleware/client")}?path=/__webpack_hmr`,
|
|
137
|
+
...baseConfig.entry.main
|
|
138
|
+
]
|
|
139
|
+
},
|
|
140
|
+
stats: "errors-warnings",
|
|
141
|
+
mode: "development",
|
|
142
|
+
devtool: "inline-source-map",
|
|
143
|
+
output: {
|
|
144
|
+
filename: "[name].js",
|
|
145
|
+
path: ctx.distPath,
|
|
146
|
+
publicPath: ctx.basePath
|
|
147
|
+
},
|
|
148
|
+
infrastructureLogging: {
|
|
149
|
+
level: "error"
|
|
150
|
+
},
|
|
151
|
+
plugins: [
|
|
152
|
+
...baseConfig.plugins,
|
|
153
|
+
new HotModuleReplacementPlugin(),
|
|
154
|
+
new ReactRefreshWebpackPlugin()
|
|
155
|
+
]
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
const resolveProductionConfig = async (ctx) => {
|
|
159
|
+
const target = browserslistToEsbuild(ctx.target);
|
|
160
|
+
const baseConfig = await resolveBaseConfig(ctx);
|
|
161
|
+
return {
|
|
162
|
+
...baseConfig,
|
|
163
|
+
stats: "errors-only",
|
|
164
|
+
mode: "production",
|
|
165
|
+
bail: true,
|
|
166
|
+
devtool: ctx.options.sourcemaps ? "source-map" : false,
|
|
167
|
+
output: {
|
|
168
|
+
path: ctx.distPath,
|
|
169
|
+
publicPath: ctx.basePath,
|
|
170
|
+
// Utilize long-term caching by adding content hashes (not compilation hashes)
|
|
171
|
+
// to compiled assets for production
|
|
172
|
+
filename: "[name].[contenthash:8].js",
|
|
173
|
+
chunkFilename: "[name].[contenthash:8].chunk.js"
|
|
174
|
+
},
|
|
175
|
+
optimization: {
|
|
176
|
+
minimize: ctx.options.minify,
|
|
177
|
+
minimizer: [
|
|
178
|
+
new ESBuildMinifyPlugin({
|
|
179
|
+
target,
|
|
180
|
+
css: true
|
|
181
|
+
// Apply minification to CSS assets
|
|
182
|
+
})
|
|
183
|
+
],
|
|
184
|
+
moduleIds: "deterministic",
|
|
185
|
+
runtimeChunk: true
|
|
186
|
+
},
|
|
187
|
+
plugins: [
|
|
188
|
+
...baseConfig.plugins,
|
|
189
|
+
new MiniCssExtractPlugin({
|
|
190
|
+
filename: "[name].[chunkhash].css",
|
|
191
|
+
chunkFilename: "[name].[chunkhash].chunkhash.css",
|
|
192
|
+
ignoreOrder: true
|
|
193
|
+
}),
|
|
194
|
+
ctx.options.stats && new BundleAnalyzerPlugin()
|
|
195
|
+
// TODO: find out if this is an actual issue or just a ts bug
|
|
196
|
+
].filter(Boolean)
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
const USER_CONFIGS = ["webpack.config.js", "webpack.config.mjs", "webpack.config.ts"];
|
|
200
|
+
const mergeConfigWithUserConfig = async (config, ctx) => {
|
|
201
|
+
const userConfig = await getUserConfig(USER_CONFIGS, ctx);
|
|
202
|
+
if (userConfig) {
|
|
203
|
+
if (typeof userConfig === "function") {
|
|
204
|
+
const webpack = await import("webpack");
|
|
205
|
+
return userConfig(config, webpack);
|
|
206
|
+
}
|
|
207
|
+
ctx.logger.warn(
|
|
208
|
+
`You've exported something other than a function from ${path.join(
|
|
209
|
+
ctx.appDir,
|
|
210
|
+
"src",
|
|
211
|
+
"admin",
|
|
212
|
+
"webpack.config"
|
|
213
|
+
)}, this will ignored.`
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
return config;
|
|
217
|
+
};
|
|
218
|
+
const getModulePath = (mod) => {
|
|
219
|
+
const modulePath = require.resolve(mod);
|
|
220
|
+
const pkg = readPkgUp.sync({ cwd: path.dirname(modulePath) });
|
|
221
|
+
return pkg ? path.dirname(pkg.path) : modulePath;
|
|
222
|
+
};
|
|
223
|
+
export {
|
|
224
|
+
mergeConfigWithUserConfig,
|
|
225
|
+
resolveDevelopmentConfig,
|
|
226
|
+
resolveProductionConfig
|
|
227
|
+
};
|
|
228
|
+
//# sourceMappingURL=config.mjs.map
|