@strapi/strapi 5.48.0 → 5.49.0
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 +9 -9
- package/dist/admin.js +17 -7
- package/dist/admin.js.map +1 -1
- package/dist/node/core/plugins.d.ts.map +1 -1
- package/dist/node/create-build-context.d.ts +0 -4
- package/dist/node/create-build-context.d.ts.map +1 -1
- package/dist/node/vite/config.d.ts.map +1 -1
- package/dist/node/vite/resolve-development-config.test.d.ts +2 -0
- package/dist/node/vite/resolve-development-config.test.d.ts.map +1 -0
- package/dist/node/vite/watch.d.ts.map +1 -1
- package/dist/node/webpack/config.d.ts.map +1 -1
- package/dist/package.json.js +1 -1
- package/dist/package.json.mjs +1 -1
- package/dist/src/cli/commands/admin/active-user.js +6 -2
- package/dist/src/cli/commands/admin/active-user.js.map +1 -1
- package/dist/src/cli/commands/admin/block-user.js +6 -2
- package/dist/src/cli/commands/admin/block-user.js.map +1 -1
- package/dist/src/cli/commands/admin/create-user.js +5 -1
- package/dist/src/cli/commands/admin/create-user.js.map +1 -1
- package/dist/src/cli/commands/admin/delete-user.js +6 -2
- package/dist/src/cli/commands/admin/delete-user.js.map +1 -1
- package/dist/src/cli/commands/admin/list-users.js +16 -11
- package/dist/src/cli/commands/admin/list-users.js.map +1 -1
- package/dist/src/cli/commands/admin/reset-user-password.js +6 -2
- package/dist/src/cli/commands/admin/reset-user-password.js.map +1 -1
- package/dist/src/cli/commands/components/list.js +7 -2
- package/dist/src/cli/commands/components/list.js.map +1 -1
- package/dist/src/cli/commands/configuration/dump.js +5 -1
- package/dist/src/cli/commands/configuration/dump.js.map +1 -1
- package/dist/src/cli/commands/configuration/restore.js +8 -3
- package/dist/src/cli/commands/configuration/restore.js.map +1 -1
- package/dist/src/cli/commands/console.js +5 -1
- package/dist/src/cli/commands/console.js.map +1 -1
- package/dist/src/cli/commands/content-types/list.js +7 -2
- package/dist/src/cli/commands/content-types/list.js.map +1 -1
- package/dist/src/cli/commands/controllers/list.js +7 -2
- package/dist/src/cli/commands/controllers/list.js.map +1 -1
- package/dist/src/cli/commands/develop.js +5 -1
- package/dist/src/cli/commands/develop.js.map +1 -1
- package/dist/src/cli/commands/export/action.js +11 -5
- package/dist/src/cli/commands/export/action.js.map +1 -1
- package/dist/src/cli/commands/hooks/list.js +7 -2
- package/dist/src/cli/commands/hooks/list.js.map +1 -1
- package/dist/src/cli/commands/import/action.js +7 -2
- package/dist/src/cli/commands/import/action.js.map +1 -1
- package/dist/src/cli/commands/import/command.js +6 -2
- package/dist/src/cli/commands/import/command.js.map +1 -1
- package/dist/src/cli/commands/middlewares/list.js +7 -2
- package/dist/src/cli/commands/middlewares/list.js.map +1 -1
- package/dist/src/cli/commands/openapi/generate.js +17 -11
- package/dist/src/cli/commands/openapi/generate.js.map +1 -1
- package/dist/src/cli/commands/policies/list.js +7 -2
- package/dist/src/cli/commands/policies/list.js.map +1 -1
- package/dist/src/cli/commands/routes/list.js +8 -3
- package/dist/src/cli/commands/routes/list.js.map +1 -1
- package/dist/src/cli/commands/services/list.js +7 -2
- package/dist/src/cli/commands/services/list.js.map +1 -1
- package/dist/src/cli/commands/start.js +8 -3
- package/dist/src/cli/commands/start.js.map +1 -1
- package/dist/src/cli/commands/telemetry/disable.js +14 -9
- package/dist/src/cli/commands/telemetry/disable.js.map +1 -1
- package/dist/src/cli/commands/telemetry/enable.js +14 -9
- package/dist/src/cli/commands/telemetry/enable.js.map +1 -1
- package/dist/src/cli/commands/transfer/action.js +5 -1
- package/dist/src/cli/commands/transfer/action.js.map +1 -1
- package/dist/src/cli/commands/ts/generate-types.js +5 -1
- package/dist/src/cli/commands/ts/generate-types.js.map +1 -1
- package/dist/src/cli/utils/commander.js +5 -1
- package/dist/src/cli/utils/commander.js.map +1 -1
- package/dist/src/cli/utils/data-transfer.js +28 -21
- package/dist/src/cli/utils/data-transfer.js.map +1 -1
- package/dist/src/cli/utils/helpers.js +7 -3
- package/dist/src/cli/utils/helpers.js.map +1 -1
- package/dist/src/cli/utils/logger.js +15 -10
- package/dist/src/cli/utils/logger.js.map +1 -1
- package/dist/src/cli/utils/tsconfig.js +9 -4
- package/dist/src/cli/utils/tsconfig.js.map +1 -1
- package/dist/src/node/build.js +3 -2
- package/dist/src/node/build.js.map +1 -1
- package/dist/src/node/core/admin-customisations.js +6 -2
- package/dist/src/node/core/admin-customisations.js.map +1 -1
- package/dist/src/node/core/aliases.js +5 -1
- package/dist/src/node/core/aliases.js.map +1 -1
- package/dist/src/node/core/config.js +5 -1
- package/dist/src/node/core/config.js.map +1 -1
- package/dist/src/node/core/dependencies.js +33 -22
- package/dist/src/node/core/dependencies.js.map +1 -1
- package/dist/src/node/core/ensure-admin-dependencies.js +5 -1
- package/dist/src/node/core/ensure-admin-dependencies.js.map +1 -1
- package/dist/src/node/core/env.js +7 -2
- package/dist/src/node/core/env.js.map +1 -1
- package/dist/src/node/core/errors.js +9 -3
- package/dist/src/node/core/errors.js.map +1 -1
- package/dist/src/node/core/files.js +6 -2
- package/dist/src/node/core/files.js.map +1 -1
- package/dist/src/node/core/linked-packages.js +5 -1
- package/dist/src/node/core/linked-packages.js.map +1 -1
- package/dist/src/node/core/monorepo.js +8 -3
- package/dist/src/node/core/monorepo.js.map +1 -1
- package/dist/src/node/core/plugins.js +35 -12
- package/dist/src/node/core/plugins.js.map +1 -1
- package/dist/src/node/core/plugins.mjs +19 -3
- package/dist/src/node/core/plugins.mjs.map +1 -1
- package/dist/src/node/core/resolve-module.js +8 -3
- package/dist/src/node/core/resolve-module.js.map +1 -1
- package/dist/src/node/create-build-context.js +16 -9
- package/dist/src/node/create-build-context.js.map +1 -1
- package/dist/src/node/create-build-context.mjs.map +1 -1
- package/dist/src/node/develop.js +14 -8
- package/dist/src/node/develop.js.map +1 -1
- package/dist/src/node/staticFiles.js +11 -5
- package/dist/src/node/staticFiles.js.map +1 -1
- package/dist/src/node/vite/config.js +23 -5
- package/dist/src/node/vite/config.js.map +1 -1
- package/dist/src/node/vite/config.mjs +18 -4
- package/dist/src/node/vite/config.mjs.map +1 -1
- package/dist/src/node/vite/watch.js +7 -62
- package/dist/src/node/vite/watch.js.map +1 -1
- package/dist/src/node/vite/watch.mjs +2 -62
- package/dist/src/node/vite/watch.mjs.map +1 -1
- package/dist/src/node/webpack/build.js +5 -1
- package/dist/src/node/webpack/build.js.map +1 -1
- package/dist/src/node/webpack/config.js +19 -9
- package/dist/src/node/webpack/config.js.map +1 -1
- package/dist/src/node/webpack/config.mjs +2 -1
- package/dist/src/node/webpack/config.mjs.map +1 -1
- package/dist/src/node/webpack/watch.js +11 -4
- package/dist/src/node/webpack/watch.js.map +1 -1
- package/package.json +26 -26
|
@@ -1 +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 { getModulePath } from '../core/resolve-module';\nimport { isDesignSystemLinked } from '../core/linked-packages';\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 const isMonorepoExampleApp = (ctx.strapi as any).internal_config?.uuid === 'getstarted';\n const designSystemLinked = isDesignSystemLinked();\n\n return {\n root: ctx.cwd,\n base: ctx.basePath,\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: {},\n 'process.env': JSON.stringify(ctx.env),\n },\n envPrefix: 'STRAPI_ADMIN_',\n optimizeDeps: {\n // When design-system is linked (portal:, file:, yarn link), exclude from pre-bundling\n // so changes are reflected without clearing node_modules/.strapi/vite cache\n ...(designSystemLinked && { exclude: ['@strapi/design-system'] }),\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 // Pre-bundle design-system so plugin custom field chunks (dynamic imports) resolve\n // to the same instance as the main app. Otherwise TooltipProvider/DesignSystemProvider\n // context from the root is not seen by components in plugin chunks.\n // Omit when linked so local changes are picked up (see exclude above)\n ...(!designSystemLinked ? ['@strapi/design-system'] : []),\n '@radix-ui/react-tooltip',\n // Pre-bundle lodash: design-system uses named imports (e.g. assignWith) but lodash\n // is CommonJS-only; pre-bundling converts it to ESM for the browser\n 'lodash',\n // Pre-bundle prismjs so plugin chunks get a valid ESM namespace (prismjs is UMD and can\n // otherwise expose an empty object when bundled, causing \"Prism is not defined\" in admin).\n 'prismjs',\n /**\n * Pre-bundle other dependencies that would otherwise cause a page reload when imported.\n * See \"performance\" section: https://vite.dev/guide/dep-pre-bundling.html#the-why\n * Only include dependencies for our internal example apps, otherwise it will break\n * real user apps that may not have those dependencies.\n */\n ...(isMonorepoExampleApp\n ? [\n '@dnd-kit/core',\n '@dnd-kit/sortable',\n '@dnd-kit/utilities',\n '@dnd-kit/modifiers',\n '@radix-ui/react-toolbar',\n 'codemirror5',\n 'codemirror5/addon/display/placeholder',\n 'date-fns-tz',\n 'date-fns/format',\n 'date-fns/formatISO',\n 'highlight.js',\n 'lodash/capitalize',\n 'lodash/fp',\n 'lodash/groupBy',\n 'lodash/has',\n 'lodash/isNil',\n 'lodash/locale',\n 'lodash/map',\n 'lodash/mapValues',\n 'lodash/pull',\n 'lodash/size',\n 'lodash/sortBy',\n 'lodash/tail',\n 'lodash/toLower',\n 'lodash/toNumber',\n 'lodash/toString',\n 'lodash/truncate',\n 'lodash/uniq',\n 'lodash/upperFirst',\n 'markdown-it',\n 'markdown-it-abbr',\n 'markdown-it-container',\n 'markdown-it-deflist',\n 'markdown-it-emoji',\n 'markdown-it-footnote',\n 'markdown-it-ins',\n 'markdown-it-mark',\n 'markdown-it-sub',\n 'markdown-it-sup',\n 'prismjs/components/*.js',\n 'react-colorful',\n 'react-dnd-html5-backend',\n 'react-window',\n 'sanitize-html',\n 'semver',\n 'semver/functions/lt',\n 'semver/functions/valid',\n 'slate',\n 'slate-history',\n 'slate-react',\n 'motion',\n ]\n : []),\n ],\n },\n resolve: {\n // https://react.dev/warnings/invalid-hook-call-warning#duplicate-react\n // Include design-system so plugin chunks use the same instance and inherit root context\n dedupe: [\n 'react',\n 'react-dom',\n 'react-router-dom',\n 'styled-components',\n '@strapi/design-system',\n '@radix-ui/react-tooltip',\n 'lodash',\n ],\n // Explicit aliases ensure resolution under pnpm's strict dependency isolation,\n // where packages imported by plugins may not be resolvable from plugin chunks\n alias: {\n react: getModulePath('react'),\n 'react-dom': getModulePath('react-dom'),\n 'react-router-dom': getModulePath('react-router-dom'),\n 'styled-components': getModulePath('styled-components'),\n '@strapi/design-system': getModulePath('@strapi/design-system'),\n '@radix-ui/react-tooltip': getModulePath('@radix-ui/react-tooltip'),\n lodash: getModulePath('lodash'),\n },\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 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 cors: false,\n middlewareMode: true,\n open: ctx.options.open,\n hmr: {\n overlay: false,\n server: ctx.options.hmrServer,\n clientPort: ctx.options.hmrClientPort,\n },\n },\n appType: 'custom',\n };\n};\n\nconst USER_CONFIGS = ['vite.config.js', 'vite.config.mjs', 'vite.config.ts', 'vite.config.mts'];\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":["resolveBaseConfig","ctx","target","browserslistToEsbuild","isMonorepoExampleApp","strapi","internal_config","uuid","designSystemLinked","isDesignSystemLinked","root","cwd","base","basePath","build","emptyOutDir","outDir","distDir","cacheDir","configFile","define","process","JSON","stringify","env","envPrefix","optimizeDeps","exclude","include","resolve","dedupe","alias","react","getModulePath","lodash","plugins","buildFilesPlugin","resolveProductionConfig","options","minify","sourcemaps","baseConfig","logLevel","mode","assetsDir","sourcemap","rollupOptions","input","entry","resolveDevelopmentConfig","monorepo","loadStrapiMonorepo","getMonorepoAliases","server","cors","middlewareMode","open","hmr","overlay","hmrServer","clientPort","hmrClientPort","appType","USER_CONFIGS","mergeConfigWithUserConfig","config","userConfig","getUserConfig"],"mappings":";;;;;;;;;AAYA,MAAMA,oBAAoB,OAAOC,GAAAA,GAAAA;IAC/B,MAAMC,MAAAA,GAASC,qBAAAA,CAAsBF,GAAAA,CAAIC,MAAM,CAAA;AAC/C,IAAA,MAAME,uBAAuB,GAACH,CAAII,MAAM,CAASC,eAAe,EAAEC,IAAAA,KAAS,YAAA;AAC3E,IAAA,MAAMC,kBAAAA,GAAqBC,oBAAAA,EAAAA;IAE3B,OAAO;AACLC,QAAAA,IAAAA,EAAMT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A,CAAIqC,OAAO,CAACqB,SAAS;gBAC7BC,UAAAA,EAAY3D,GAAAA,CAAIqC,OAAO,CAACuB;AAC1B;AACF,SAAA;QACAC,OAAAA,EAAS;AACX,KAAA;AACF;AAEA,MAAMC,YAAAA,GAAe;AAAC,IAAA,gBAAA;AAAkB,IAAA,iBAAA;AAAmB,IAAA,gBAAA;AAAkB,IAAA;AAAkB,CAAA;AAI/F,MAAMC,yBAAAA,GAA4B,OAAOC,MAAAA,EAAsBhE,GAAAA,GAAAA;IAC7D,MAAMiE,UAAAA,GAAa,MAAMC,aAAAA,CAA8BJ,YAAAA,EAAc9D,GAAAA,CAAAA;AAErE,IAAA,IAAIiE,UAAAA,EAAY;AACd,QAAA,OAAOA,UAAAA,CAAWD,MAAAA,CAAAA;AACpB,IAAA;IAEA,OAAOA,MAAAA;AACT;;;;"}
|
|
1
|
+
{"version":3,"file":"config.mjs","sources":["../../../../src/node/vite/config.ts"],"sourcesContent":["import type { InlineConfig, UserConfig } from 'vite';\nimport react from '@vitejs/plugin-react-swc';\n\nimport { getUserConfig } from '../core/config';\nimport { getModulePath } from '../core/resolve-module';\nimport { isDesignSystemLinked } from '../core/linked-packages';\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 { default: browserslistToEsbuild } = await import('browserslist-to-esbuild');\n const target = browserslistToEsbuild(ctx.target);\n const isMonorepoExampleApp = (ctx.strapi as any).internal_config?.uuid === 'getstarted';\n const designSystemLinked = isDesignSystemLinked();\n\n return {\n root: ctx.cwd,\n base: ctx.basePath,\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: {},\n 'process.env': JSON.stringify(ctx.env),\n },\n envPrefix: 'STRAPI_ADMIN_',\n optimizeDeps: {\n // When design-system is linked (portal:, file:, yarn link), exclude from pre-bundling\n // so changes are reflected without clearing node_modules/.strapi/vite cache\n ...(designSystemLinked && { exclude: ['@strapi/design-system'] }),\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 // Admin + RTK Query share react-redux context; pre-bundle so dev chunks cannot load a\n // second copy (avoids \"could not find react-redux context value\" after upgrades / hoisting).\n 'react-redux',\n '@reduxjs/toolkit',\n // Pre-bundle design-system so plugin custom field chunks (dynamic imports) resolve\n // to the same instance as the main app. Otherwise TooltipProvider/DesignSystemProvider\n // context from the root is not seen by components in plugin chunks.\n // Omit when linked so local changes are picked up (see exclude above)\n ...(!designSystemLinked ? ['@strapi/design-system'] : []),\n '@radix-ui/react-tooltip',\n // Pre-bundle lodash: design-system uses named imports (e.g. assignWith) but lodash\n // is CommonJS-only; pre-bundling converts it to ESM for the browser\n 'lodash',\n // Pre-bundle prismjs so plugin chunks get a valid ESM namespace (prismjs is UMD and can\n // otherwise expose an empty object when bundled, causing \"Prism is not defined\" in admin).\n 'prismjs',\n /**\n * Pre-bundle other dependencies that would otherwise cause a page reload when imported.\n * See \"performance\" section: https://vite.dev/guide/dep-pre-bundling.html#the-why\n * Only include dependencies for our internal example apps, otherwise it will break\n * real user apps that may not have those dependencies.\n */\n ...(isMonorepoExampleApp\n ? [\n '@dnd-kit/core',\n '@dnd-kit/sortable',\n '@dnd-kit/utilities',\n '@dnd-kit/modifiers',\n '@radix-ui/react-toolbar',\n 'codemirror5',\n 'codemirror5/addon/display/placeholder',\n 'date-fns-tz',\n 'date-fns/format',\n 'date-fns/formatISO',\n 'highlight.js',\n 'lodash/capitalize',\n 'lodash/fp',\n 'lodash/groupBy',\n 'lodash/has',\n 'lodash/isNil',\n 'lodash/locale',\n 'lodash/map',\n 'lodash/mapValues',\n 'lodash/pull',\n 'lodash/size',\n 'lodash/sortBy',\n 'lodash/tail',\n 'lodash/toLower',\n 'lodash/toNumber',\n 'lodash/toString',\n 'lodash/truncate',\n 'lodash/uniq',\n 'lodash/upperFirst',\n 'markdown-it',\n 'markdown-it-abbr',\n 'markdown-it-container',\n 'markdown-it-deflist',\n 'markdown-it-emoji',\n 'markdown-it-footnote',\n 'markdown-it-ins',\n 'markdown-it-mark',\n 'markdown-it-sub',\n 'markdown-it-sup',\n 'prismjs/components/*.js',\n 'react-colorful',\n 'react-dnd-html5-backend',\n 'react-window',\n 'semver',\n 'semver/functions/lt',\n 'semver/functions/valid',\n 'slate',\n 'slate-history',\n 'slate-react',\n 'motion',\n ]\n : []),\n ],\n },\n resolve: {\n // https://react.dev/warnings/invalid-hook-call-warning#duplicate-react\n // Include design-system so plugin chunks use the same instance and inherit root context\n dedupe: [\n 'react',\n 'react-dom',\n 'react-router-dom',\n 'styled-components',\n 'react-redux',\n '@reduxjs/toolkit',\n '@strapi/design-system',\n '@radix-ui/react-tooltip',\n 'lodash',\n ],\n // Explicit aliases ensure resolution under pnpm's strict dependency isolation,\n // where packages imported by plugins may not be resolvable from plugin chunks\n alias: {\n react: getModulePath('react'),\n 'react-dom': getModulePath('react-dom'),\n 'react-router-dom': getModulePath('react-router-dom'),\n 'styled-components': getModulePath('styled-components'),\n 'react-redux': getModulePath('react-redux'),\n '@reduxjs/toolkit': getModulePath('@reduxjs/toolkit'),\n '@strapi/design-system': getModulePath('@strapi/design-system'),\n '@radix-ui/react-tooltip': getModulePath('@radix-ui/react-tooltip'),\n lodash: getModulePath('lodash'),\n },\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 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 cors: false,\n /**\n * In middleware mode Strapi forwards the browser Host from reverse proxies (nginx, Traefik).\n * Vite 5+ blocks unknown hosts unless explicitly allowed (#23491).\n */\n allowedHosts: true,\n middlewareMode: true,\n open: ctx.options.open,\n hmr: {\n overlay: false,\n /**\n * Use Strapi's http.Server so HMR websockets reuse the app's listen port. A separate listener\n * plus clientPort pushes browsers toward host:5173-style URLs that fail behind proxies that\n * only expose the Strapi server port (#23491, #23008).\n */\n server: ctx.strapi.server.httpServer,\n },\n },\n appType: 'custom',\n };\n};\n\nconst USER_CONFIGS = ['vite.config.js', 'vite.config.mjs', 'vite.config.ts', 'vite.config.mts'];\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":["resolveBaseConfig","ctx","default","browserslistToEsbuild","target","isMonorepoExampleApp","strapi","internal_config","uuid","designSystemLinked","isDesignSystemLinked","root","cwd","base","basePath","build","emptyOutDir","outDir","distDir","cacheDir","configFile","define","process","JSON","stringify","env","envPrefix","optimizeDeps","exclude","include","resolve","dedupe","alias","react","getModulePath","lodash","plugins","buildFilesPlugin","resolveProductionConfig","options","minify","sourcemaps","baseConfig","logLevel","mode","assetsDir","sourcemap","rollupOptions","input","entry","resolveDevelopmentConfig","monorepo","loadStrapiMonorepo","getMonorepoAliases","server","cors","allowedHosts","middlewareMode","open","hmr","overlay","httpServer","appType","USER_CONFIGS","mergeConfigWithUserConfig","config","userConfig","getUserConfig"],"mappings":";;;;;;;;AAWA,MAAMA,oBAAoB,OAAOC,GAAAA,GAAAA;AAC/B,IAAA,MAAM,EAAEC,OAAAA,EAASC,qBAAqB,EAAE,GAAG,MAAM,OAAO,yBAAA,CAAA;IACxD,MAAMC,MAAAA,GAASD,qBAAAA,CAAsBF,GAAAA,CAAIG,MAAM,CAAA;AAC/C,IAAA,MAAMC,uBAAuB,GAACJ,CAAIK,MAAM,CAASC,eAAe,EAAEC,IAAAA,KAAS,YAAA;AAC3E,IAAA,MAAMC,kBAAAA,GAAqBC,oBAAAA,EAAAA;IAE3B,OAAO;AACLC,QAAAA,IAAAA,EAAMV,IAAIW,GAAG;AACbC,QAAAA,IAAAA,EAAMZ,IAAIa,QAAQ;QAClBC,KAAAA,EAAO;YACLC,WAAAA,EAAa,KAAA;AACbC,YAAAA,MAAAA,EAAQhB,IAAIiB,OAAO;AACnBd,YAAAA;AACF,SAAA;QACAe,QAAAA,EAAU,2BAAA;QACVC,UAAAA,EAAY,KAAA;QACZC,MAAAA,EAAQ;AACNC,YAAAA,OAAAA,EAAS,EAAC;AACV,YAAA,aAAA,EAAeC,IAAAA,CAAKC,SAAS,CAACvB,GAAAA,CAAIwB,GAAG;AACvC,SAAA;QACAC,SAAAA,EAAW,eAAA;QACXC,YAAAA,EAAc;;;AAGZ,YAAA,GAAIlB,kBAAAA,IAAsB;gBAAEmB,OAAAA,EAAS;AAAC,oBAAA;AAAwB;aAAE;YAChEC,OAAAA,EAAS;;;;AAIP,gBAAA,OAAA;AACA,gBAAA,CAAC,iBAAiB,CAAC;AACnB,gBAAA,kBAAA;AACA,gBAAA,mBAAA;AACA,gBAAA,kBAAA;;;AAGA,gBAAA,aAAA;AACA,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;IAEA,OAAOA,MAAAA;AACT;;;;"}
|
|
@@ -1,63 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var path = require('node:path');
|
|
4
|
-
var http = require('node:http');
|
|
5
4
|
var fs = require('node:fs/promises');
|
|
6
|
-
var node_net = require('node:net');
|
|
7
5
|
var config = require('./config.js');
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
reject(new Error(`No available ports found after ${MAX_PORT_ATTEMPTS} attempts.`));
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
const server = new node_net.Server();
|
|
18
|
-
server.listen(startingPort, ()=>{
|
|
19
|
-
const { port } = server.address();
|
|
20
|
-
server.close(()=>resolve(port));
|
|
21
|
-
});
|
|
22
|
-
server.on('error', (err)=>{
|
|
23
|
-
if (err.code === 'EADDRINUSE') {
|
|
24
|
-
resolve(findAvailablePort(startingPort + 1, attemptsLeft - 1));
|
|
25
|
-
} else {
|
|
26
|
-
reject(err);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
const createHMRServer = ()=>{
|
|
32
|
-
return http.createServer(// http server request handler. keeps the same with
|
|
33
|
-
// https://github.com/websockets/ws/blob/45e17acea791d865df6b255a55182e9c42e5877a/lib/websocket-server.js#L88-L96
|
|
34
|
-
(_, res)=>{
|
|
35
|
-
const body = http.STATUS_CODES[426]; // Upgrade Required
|
|
36
|
-
res.writeHead(426, {
|
|
37
|
-
'Content-Length': body?.length ?? 0,
|
|
38
|
-
'Content-Type': 'text/plain'
|
|
39
|
-
});
|
|
40
|
-
res.end(body);
|
|
41
|
-
});
|
|
42
|
-
};
|
|
7
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
|
|
9
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
10
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
11
|
+
|
|
43
12
|
const watch = async (ctx)=>{
|
|
44
|
-
const
|
|
45
|
-
// Allowing Vite to find an available port doesn't work, so we'll find an available port manually
|
|
46
|
-
// and use that. There is therefore a very slight race condition if you start up two servers at the same time
|
|
47
|
-
// one might fail, or it might start up but listen on the wrong port.
|
|
48
|
-
const availablePort = await findAvailablePort(HMR_DEFAULT_PORT);
|
|
49
|
-
ctx.options.hmrServer = hmrServer;
|
|
50
|
-
ctx.options.hmrClientPort = availablePort;
|
|
51
|
-
const config$1 = await config.resolveDevelopmentConfig(ctx);
|
|
52
|
-
const finalConfig = await config.mergeConfigWithUserConfig(config$1, ctx);
|
|
53
|
-
const hmrConfig = config$1.server?.hmr;
|
|
54
|
-
// If the server used for Vite hmr is the one we've created (<> no user override)
|
|
55
|
-
if (typeof hmrConfig === 'object' && hmrConfig.server === hmrServer) {
|
|
56
|
-
// Only restart the hmr server when Strapi's server is listening
|
|
57
|
-
strapi.server.httpServer.on('listening', async ()=>{
|
|
58
|
-
hmrServer.listen(availablePort);
|
|
59
|
-
});
|
|
60
|
-
}
|
|
13
|
+
const finalConfig = await config.mergeConfigWithUserConfig(await config.resolveDevelopmentConfig(ctx), ctx);
|
|
61
14
|
ctx.logger.debug('Vite config', finalConfig);
|
|
62
15
|
const { createServer } = await import('vite');
|
|
63
16
|
const vite = await createServer(finalConfig);
|
|
@@ -95,7 +48,7 @@ const watch = async (ctx)=>{
|
|
|
95
48
|
}
|
|
96
49
|
const url = koaCtx.originalUrl;
|
|
97
50
|
try {
|
|
98
|
-
let template = await
|
|
51
|
+
let template = await fs__default.default.readFile(path__default.default.relative(ctx.cwd, '.strapi/client/index.html'), 'utf-8');
|
|
99
52
|
template = await vite.transformIndexHtml(url, template);
|
|
100
53
|
koaCtx.type = 'html';
|
|
101
54
|
koaCtx.body = template;
|
|
@@ -120,14 +73,6 @@ const watch = async (ctx)=>{
|
|
|
120
73
|
return {
|
|
121
74
|
async close () {
|
|
122
75
|
await vite.close();
|
|
123
|
-
if (hmrServer.listening) {
|
|
124
|
-
// Manually close the hmr server
|
|
125
|
-
// /!\ This operation MUST be done after calling .close() on the vite
|
|
126
|
-
// instance to avoid flaky behaviors with attached clients
|
|
127
|
-
await new Promise((resolve, reject)=>{
|
|
128
|
-
hmrServer.close((err)=>err ? reject(err) : resolve());
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
76
|
}
|
|
132
77
|
};
|
|
133
78
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watch.js","sources":["../../../../src/node/vite/watch.ts"],"sourcesContent":["import path from 'node:path';\nimport http from 'node:http';\nimport fs from 'node:fs/promises';\nimport { Server } from 'node:net';\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 HMR_DEFAULT_PORT = 5173;\nconst MAX_PORT_ATTEMPTS = 30;\n\nconst findAvailablePort = (\n startingPort: number,\n attemptsLeft = MAX_PORT_ATTEMPTS\n): Promise<number> => {\n return new Promise((resolve, reject) => {\n if (attemptsLeft <= 0) {\n reject(new Error(`No available ports found after ${MAX_PORT_ATTEMPTS} attempts.`));\n return;\n }\n\n const server = new Server();\n server.listen(startingPort, () => {\n const { port } = server.address() as { port: number };\n server.close(() => resolve(port));\n });\n\n server.on('error', (err: any) => {\n if (err.code === 'EADDRINUSE') {\n resolve(findAvailablePort(startingPort + 1, attemptsLeft - 1));\n } else {\n reject(err);\n }\n });\n });\n};\n\nconst createHMRServer = () => {\n return http.createServer(\n // http server request handler. keeps the same with\n // https://github.com/websockets/ws/blob/45e17acea791d865df6b255a55182e9c42e5877a/lib/websocket-server.js#L88-L96\n (_, res) => {\n const body = http.STATUS_CODES[426]; // Upgrade Required\n\n res.writeHead(426, {\n 'Content-Length': body?.length ?? 0,\n 'Content-Type': 'text/plain',\n });\n\n res.end(body);\n }\n );\n};\n\nconst watch = async (ctx: BuildContext): Promise<ViteWatcher> => {\n const hmrServer = createHMRServer();\n\n // Allowing Vite to find an available port doesn't work, so we'll find an available port manually\n // and use that. There is therefore a very slight race condition if you start up two servers at the same time\n // one might fail, or it might start up but listen on the wrong port.\n const availablePort = await findAvailablePort(HMR_DEFAULT_PORT);\n ctx.options.hmrServer = hmrServer;\n ctx.options.hmrClientPort = availablePort;\n\n const config = await resolveDevelopmentConfig(ctx);\n\n const finalConfig = await mergeConfigWithUserConfig(config, ctx);\n\n const hmrConfig = config.server?.hmr;\n\n // If the server used for Vite hmr is the one we've created (<> no user override)\n if (typeof hmrConfig === 'object' && hmrConfig.server === hmrServer) {\n // Only restart the hmr server when Strapi's server is listening\n strapi.server.httpServer.on('listening', async () => {\n hmrServer.listen(availablePort);\n });\n }\n\n ctx.logger.debug('Vite config', finalConfig);\n\n const { createServer } = await import('vite');\n\n const vite = await createServer(finalConfig);\n\n const viteMiddlewares: Core.MiddlewareHandler = (koaCtx, next) => {\n return new Promise((resolve, reject) => {\n const prefix = ctx.basePath.replace(ctx.adminPath, '').replace(/\\/+$/, '');\n\n const originalPath = koaCtx.path;\n if (!koaCtx.path.startsWith(prefix)) {\n koaCtx.path = `${prefix}${koaCtx.path}`;\n }\n\n // Set cache-control headers to prevent caching issues during development restarts\n koaCtx.set('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate');\n koaCtx.set('Pragma', 'no-cache');\n koaCtx.set('Expires', '0');\n koaCtx.set('Surrogate-Control', 'no-store');\n\n vite.middlewares(koaCtx.req, koaCtx.res, (err: unknown) => {\n if (err) {\n reject(err);\n } else {\n if (!koaCtx.res.headersSent) {\n koaCtx.path = originalPath;\n }\n\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 try {\n let template = await fs.readFile(\n path.relative(ctx.cwd, '.strapi/client/index.html'),\n 'utf-8'\n );\n template = await vite.transformIndexHtml(url, template);\n\n koaCtx.type = 'html';\n koaCtx.body = template;\n } catch (error) {\n ctx.logger.error('Failed to serve admin panel in development mode:', error);\n // Don't fallback to other handlers in development mode to prevent MIME type conflicts\n koaCtx.status = 500;\n koaCtx.body = 'Admin panel temporarily unavailable during server restart';\n }\n };\n\n const adminRoute = `${ctx.adminPath}/:path*`;\n\n // Remove any existing admin routes to prevent conflicts during restart\n const existingRoutes = ctx.strapi.server.router.stack.filter(\n (layer) => layer.path === adminRoute\n );\n existingRoutes.forEach((route) => {\n const index = ctx.strapi.server.router.stack.indexOf(route);\n if (index > -1) {\n ctx.strapi.server.router.stack.splice(index, 1);\n }\n });\n\n ctx.strapi.server.router.get(adminRoute, serveAdmin);\n ctx.strapi.server.router.use(adminRoute, viteMiddlewares);\n\n return {\n async close() {\n await vite.close();\n\n if (hmrServer.listening) {\n // Manually close the hmr server\n // /!\\ This operation MUST be done after calling .close() on the vite\n // instance to avoid flaky behaviors with attached clients\n await new Promise<void>((resolve, reject) => {\n hmrServer.close((err) => (err ? reject(err) : resolve()));\n });\n }\n },\n };\n};\n\nexport { watch };\nexport type { ViteWatcher };\n"],"names":["HMR_DEFAULT_PORT","MAX_PORT_ATTEMPTS","findAvailablePort","startingPort","attemptsLeft","Promise","resolve","reject","Error","server","Server","listen","port","address","close","on","err","code","createHMRServer","http","createServer","_","res","body","STATUS_CODES","writeHead","length","end","watch","ctx","hmrServer","availablePort","options","hmrClientPort","config","resolveDevelopmentConfig","finalConfig","mergeConfigWithUserConfig","hmrConfig","hmr","strapi","httpServer","logger","debug","vite","viteMiddlewares","koaCtx","next","prefix","basePath","replace","adminPath","originalPath","path","startsWith","set","middlewares","req","headersSent","serveAdmin","method","status","url","originalUrl","template","fs","readFile","relative","cwd","transformIndexHtml","type","error","adminRoute","existingRoutes","router","stack","filter","layer","forEach","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AC,CAACC,KAAAA,GAAAA;QACtB,MAAMC,KAAAA,GAAQnD,GAAAA,CAAIW,MAAM,CAAC/B,MAAM,CAACiE,MAAM,CAACC,KAAK,CAACM,OAAO,CAACF,KAAAA,CAAAA;QACrD,IAAIC,KAAAA,GAAQ,EAAC,EAAG;YACdnD,GAAAA,CAAIW,MAAM,CAAC/B,MAAM,CAACiE,MAAM,CAACC,KAAK,CAACO,MAAM,CAACF,KAAAA,EAAO,CAAA,CAAA;AAC/C,QAAA;AACF,IAAA,CAAA,CAAA;IAEAnD,GAAAA,CAAIW,MAAM,CAAC/B,MAAM,CAACiE,MAAM,CAACS,GAAG,CAACX,UAAAA,EAAYb,UAAAA,CAAAA;IACzC9B,GAAAA,CAAIW,MAAM,CAAC/B,MAAM,CAACiE,MAAM,CAACU,GAAG,CAACZ,UAAAA,EAAY3B,eAAAA,CAAAA;IAEzC,OAAO;QACL,MAAM/B,KAAAA,CAAAA,GAAAA;AACJ,YAAA,MAAM8B,KAAK9B,KAAK,EAAA;YAEhB,IAAIgB,SAAAA,CAAUuD,SAAS,EAAE;;;;gBAIvB,MAAM,IAAIhF,OAAAA,CAAc,CAACC,OAAAA,EAASC,MAAAA,GAAAA;AAChCuB,oBAAAA,SAAAA,CAAUhB,KAAK,CAAC,CAACE,GAAAA,GAASA,GAAAA,GAAMT,OAAOS,GAAAA,CAAAA,GAAOV,OAAAA,EAAAA,CAAAA;AAChD,gBAAA,CAAA,CAAA;AACF,YAAA;AACF,QAAA;AACF,KAAA;AACF;;;;"}
|
|
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 finalConfig = await mergeConfigWithUserConfig(await resolveDevelopmentConfig(ctx), 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 const viteMiddlewares: Core.MiddlewareHandler = (koaCtx, next) => {\n return new Promise((resolve, reject) => {\n const prefix = ctx.basePath.replace(ctx.adminPath, '').replace(/\\/+$/, '');\n\n const originalPath = koaCtx.path;\n if (!koaCtx.path.startsWith(prefix)) {\n koaCtx.path = `${prefix}${koaCtx.path}`;\n }\n\n // Set cache-control headers to prevent caching issues during development restarts\n koaCtx.set('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate');\n koaCtx.set('Pragma', 'no-cache');\n koaCtx.set('Expires', '0');\n koaCtx.set('Surrogate-Control', 'no-store');\n\n vite.middlewares(koaCtx.req, koaCtx.res, (err: unknown) => {\n if (err) {\n reject(err);\n } else {\n if (!koaCtx.res.headersSent) {\n koaCtx.path = originalPath;\n }\n\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 try {\n let template = await fs.readFile(\n path.relative(ctx.cwd, '.strapi/client/index.html'),\n 'utf-8'\n );\n template = await vite.transformIndexHtml(url, template);\n\n koaCtx.type = 'html';\n koaCtx.body = template;\n } catch (error) {\n ctx.logger.error('Failed to serve admin panel in development mode:', error);\n // Don't fallback to other handlers in development mode to prevent MIME type conflicts\n koaCtx.status = 500;\n koaCtx.body = 'Admin panel temporarily unavailable during server restart';\n }\n };\n\n const adminRoute = `${ctx.adminPath}/:path*`;\n\n // Remove any existing admin routes to prevent conflicts during restart\n const existingRoutes = ctx.strapi.server.router.stack.filter(\n (layer) => layer.path === adminRoute\n );\n existingRoutes.forEach((route) => {\n const index = ctx.strapi.server.router.stack.indexOf(route);\n if (index > -1) {\n ctx.strapi.server.router.stack.splice(index, 1);\n }\n });\n\n ctx.strapi.server.router.get(adminRoute, serveAdmin);\n ctx.strapi.server.router.use(adminRoute, viteMiddlewares);\n\n return {\n async close() {\n await vite.close();\n },\n };\n};\n\nexport { watch };\nexport type { ViteWatcher };\n"],"names":["watch","ctx","finalConfig","mergeConfigWithUserConfig","resolveDevelopmentConfig","logger","debug","createServer","vite","viteMiddlewares","koaCtx","next","Promise","resolve","reject","prefix","basePath","replace","adminPath","originalPath","path","startsWith","set","middlewares","req","res","err","headersSent","serveAdmin","method","body","status","url","originalUrl","template","fs","readFile","relative","cwd","transformIndexHtml","type","error","adminRoute","existingRoutes","strapi","server","router","stack","filter","layer","forEach","route","index","indexOf","splice","get","use","close"],"mappings":";;;;;;;;;;;AAYA,MAAMA,QAAQ,OAAOC,GAAAA,GAAAA;AACnB,IAAA,MAAMC,WAAAA,GAAc,MAAMC,gCAAAA,CAA0B,MAAMC,gCAAyBH,GAAAA,CAAAA,EAAMA,GAAAA,CAAAA;AAEzFA,IAAAA,GAAAA,CAAII,MAAM,CAACC,KAAK,CAAC,aAAA,EAAeJ,WAAAA,CAAAA;AAEhC,IAAA,MAAM,EAAEK,YAAY,EAAE,GAAG,MAAM,OAAO,MAAA,CAAA;IAEtC,MAAMC,IAAAA,GAAO,MAAMD,YAAAA,CAAaL,WAAAA,CAAAA;IAEhC,MAAMO,eAAAA,GAA0C,CAACC,MAAAA,EAAQC,IAAAA,GAAAA;QACvD,OAAO,IAAIC,OAAAA,CAAQ,CAACC,OAAAA,EAASC,MAAAA,GAAAA;AAC3B,YAAA,MAAMC,MAAAA,GAASd,GAAAA,CAAIe,QAAQ,CAACC,OAAO,CAAChB,GAAAA,CAAIiB,SAAS,EAAE,EAAA,CAAA,CAAID,OAAO,CAAC,MAAA,EAAQ,EAAA,CAAA;YAEvE,MAAME,YAAAA,GAAeT,OAAOU,IAAI;AAChC,YAAA,IAAI,CAACV,MAAAA,CAAOU,IAA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I2C,MAAM,CAACC,MAAM,CAACC,MAAM,CAACS,GAAG,CAACb,UAAAA,EAAYd,UAAAA,CAAAA;IACzC3B,GAAAA,CAAI2C,MAAM,CAACC,MAAM,CAACC,MAAM,CAACU,GAAG,CAACd,UAAAA,EAAYjC,eAAAA,CAAAA;IAEzC,OAAO;QACL,MAAMgD,KAAAA,CAAAA,GAAAA;AACJ,YAAA,MAAMjD,KAAKiD,KAAK,EAAA;AAClB,QAAA;AACF,KAAA;AACF;;;;"}
|
|
@@ -1,61 +1,9 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import http from 'node:http';
|
|
3
2
|
import fs from 'node:fs/promises';
|
|
4
|
-
import {
|
|
5
|
-
import { resolveDevelopmentConfig, mergeConfigWithUserConfig } from './config.mjs';
|
|
3
|
+
import { mergeConfigWithUserConfig, resolveDevelopmentConfig } from './config.mjs';
|
|
6
4
|
|
|
7
|
-
const HMR_DEFAULT_PORT = 5173;
|
|
8
|
-
const MAX_PORT_ATTEMPTS = 30;
|
|
9
|
-
const findAvailablePort = (startingPort, attemptsLeft = MAX_PORT_ATTEMPTS)=>{
|
|
10
|
-
return new Promise((resolve, reject)=>{
|
|
11
|
-
if (attemptsLeft <= 0) {
|
|
12
|
-
reject(new Error(`No available ports found after ${MAX_PORT_ATTEMPTS} attempts.`));
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
const server = new Server();
|
|
16
|
-
server.listen(startingPort, ()=>{
|
|
17
|
-
const { port } = server.address();
|
|
18
|
-
server.close(()=>resolve(port));
|
|
19
|
-
});
|
|
20
|
-
server.on('error', (err)=>{
|
|
21
|
-
if (err.code === 'EADDRINUSE') {
|
|
22
|
-
resolve(findAvailablePort(startingPort + 1, attemptsLeft - 1));
|
|
23
|
-
} else {
|
|
24
|
-
reject(err);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
const createHMRServer = ()=>{
|
|
30
|
-
return http.createServer(// http server request handler. keeps the same with
|
|
31
|
-
// https://github.com/websockets/ws/blob/45e17acea791d865df6b255a55182e9c42e5877a/lib/websocket-server.js#L88-L96
|
|
32
|
-
(_, res)=>{
|
|
33
|
-
const body = http.STATUS_CODES[426]; // Upgrade Required
|
|
34
|
-
res.writeHead(426, {
|
|
35
|
-
'Content-Length': body?.length ?? 0,
|
|
36
|
-
'Content-Type': 'text/plain'
|
|
37
|
-
});
|
|
38
|
-
res.end(body);
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
5
|
const watch = async (ctx)=>{
|
|
42
|
-
const
|
|
43
|
-
// Allowing Vite to find an available port doesn't work, so we'll find an available port manually
|
|
44
|
-
// and use that. There is therefore a very slight race condition if you start up two servers at the same time
|
|
45
|
-
// one might fail, or it might start up but listen on the wrong port.
|
|
46
|
-
const availablePort = await findAvailablePort(HMR_DEFAULT_PORT);
|
|
47
|
-
ctx.options.hmrServer = hmrServer;
|
|
48
|
-
ctx.options.hmrClientPort = availablePort;
|
|
49
|
-
const config = await resolveDevelopmentConfig(ctx);
|
|
50
|
-
const finalConfig = await mergeConfigWithUserConfig(config, ctx);
|
|
51
|
-
const hmrConfig = config.server?.hmr;
|
|
52
|
-
// If the server used for Vite hmr is the one we've created (<> no user override)
|
|
53
|
-
if (typeof hmrConfig === 'object' && hmrConfig.server === hmrServer) {
|
|
54
|
-
// Only restart the hmr server when Strapi's server is listening
|
|
55
|
-
strapi.server.httpServer.on('listening', async ()=>{
|
|
56
|
-
hmrServer.listen(availablePort);
|
|
57
|
-
});
|
|
58
|
-
}
|
|
6
|
+
const finalConfig = await mergeConfigWithUserConfig(await resolveDevelopmentConfig(ctx), ctx);
|
|
59
7
|
ctx.logger.debug('Vite config', finalConfig);
|
|
60
8
|
const { createServer } = await import('vite');
|
|
61
9
|
const vite = await createServer(finalConfig);
|
|
@@ -118,14 +66,6 @@ const watch = async (ctx)=>{
|
|
|
118
66
|
return {
|
|
119
67
|
async close () {
|
|
120
68
|
await vite.close();
|
|
121
|
-
if (hmrServer.listening) {
|
|
122
|
-
// Manually close the hmr server
|
|
123
|
-
// /!\ This operation MUST be done after calling .close() on the vite
|
|
124
|
-
// instance to avoid flaky behaviors with attached clients
|
|
125
|
-
await new Promise((resolve, reject)=>{
|
|
126
|
-
hmrServer.close((err)=>err ? reject(err) : resolve());
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
69
|
}
|
|
130
70
|
};
|
|
131
71
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watch.mjs","sources":["../../../../src/node/vite/watch.ts"],"sourcesContent":["import path from 'node:path';\nimport http from 'node:http';\nimport fs from 'node:fs/promises';\nimport { Server } from 'node:net';\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 HMR_DEFAULT_PORT = 5173;\nconst MAX_PORT_ATTEMPTS = 30;\n\nconst findAvailablePort = (\n startingPort: number,\n attemptsLeft = MAX_PORT_ATTEMPTS\n): Promise<number> => {\n return new Promise((resolve, reject) => {\n if (attemptsLeft <= 0) {\n reject(new Error(`No available ports found after ${MAX_PORT_ATTEMPTS} attempts.`));\n return;\n }\n\n const server = new Server();\n server.listen(startingPort, () => {\n const { port } = server.address() as { port: number };\n server.close(() => resolve(port));\n });\n\n server.on('error', (err: any) => {\n if (err.code === 'EADDRINUSE') {\n resolve(findAvailablePort(startingPort + 1, attemptsLeft - 1));\n } else {\n reject(err);\n }\n });\n });\n};\n\nconst createHMRServer = () => {\n return http.createServer(\n // http server request handler. keeps the same with\n // https://github.com/websockets/ws/blob/45e17acea791d865df6b255a55182e9c42e5877a/lib/websocket-server.js#L88-L96\n (_, res) => {\n const body = http.STATUS_CODES[426]; // Upgrade Required\n\n res.writeHead(426, {\n 'Content-Length': body?.length ?? 0,\n 'Content-Type': 'text/plain',\n });\n\n res.end(body);\n }\n );\n};\n\nconst watch = async (ctx: BuildContext): Promise<ViteWatcher> => {\n const hmrServer = createHMRServer();\n\n // Allowing Vite to find an available port doesn't work, so we'll find an available port manually\n // and use that. There is therefore a very slight race condition if you start up two servers at the same time\n // one might fail, or it might start up but listen on the wrong port.\n const availablePort = await findAvailablePort(HMR_DEFAULT_PORT);\n ctx.options.hmrServer = hmrServer;\n ctx.options.hmrClientPort = availablePort;\n\n const config = await resolveDevelopmentConfig(ctx);\n\n const finalConfig = await mergeConfigWithUserConfig(config, ctx);\n\n const hmrConfig = config.server?.hmr;\n\n // If the server used for Vite hmr is the one we've created (<> no user override)\n if (typeof hmrConfig === 'object' && hmrConfig.server === hmrServer) {\n // Only restart the hmr server when Strapi's server is listening\n strapi.server.httpServer.on('listening', async () => {\n hmrServer.listen(availablePort);\n });\n }\n\n ctx.logger.debug('Vite config', finalConfig);\n\n const { createServer } = await import('vite');\n\n const vite = await createServer(finalConfig);\n\n const viteMiddlewares: Core.MiddlewareHandler = (koaCtx, next) => {\n return new Promise((resolve, reject) => {\n const prefix = ctx.basePath.replace(ctx.adminPath, '').replace(/\\/+$/, '');\n\n const originalPath = koaCtx.path;\n if (!koaCtx.path.startsWith(prefix)) {\n koaCtx.path = `${prefix}${koaCtx.path}`;\n }\n\n // Set cache-control headers to prevent caching issues during development restarts\n koaCtx.set('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate');\n koaCtx.set('Pragma', 'no-cache');\n koaCtx.set('Expires', '0');\n koaCtx.set('Surrogate-Control', 'no-store');\n\n vite.middlewares(koaCtx.req, koaCtx.res, (err: unknown) => {\n if (err) {\n reject(err);\n } else {\n if (!koaCtx.res.headersSent) {\n koaCtx.path = originalPath;\n }\n\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 try {\n let template = await fs.readFile(\n path.relative(ctx.cwd, '.strapi/client/index.html'),\n 'utf-8'\n );\n template = await vite.transformIndexHtml(url, template);\n\n koaCtx.type = 'html';\n koaCtx.body = template;\n } catch (error) {\n ctx.logger.error('Failed to serve admin panel in development mode:', error);\n // Don't fallback to other handlers in development mode to prevent MIME type conflicts\n koaCtx.status = 500;\n koaCtx.body = 'Admin panel temporarily unavailable during server restart';\n }\n };\n\n const adminRoute = `${ctx.adminPath}/:path*`;\n\n // Remove any existing admin routes to prevent conflicts during restart\n const existingRoutes = ctx.strapi.server.router.stack.filter(\n (layer) => layer.path === adminRoute\n );\n existingRoutes.forEach((route) => {\n const index = ctx.strapi.server.router.stack.indexOf(route);\n if (index > -1) {\n ctx.strapi.server.router.stack.splice(index, 1);\n }\n });\n\n ctx.strapi.server.router.get(adminRoute, serveAdmin);\n ctx.strapi.server.router.use(adminRoute, viteMiddlewares);\n\n return {\n async close() {\n await vite.close();\n\n if (hmrServer.listening) {\n // Manually close the hmr server\n // /!\\ This operation MUST be done after calling .close() on the vite\n // instance to avoid flaky behaviors with attached clients\n await new Promise<void>((resolve, reject) => {\n hmrServer.close((err) => (err ? reject(err) : resolve()));\n });\n }\n },\n };\n};\n\nexport { watch };\nexport type { ViteWatcher };\n"],"names":["HMR_DEFAULT_PORT","MAX_PORT_ATTEMPTS","findAvailablePort","startingPort","attemptsLeft","Promise","resolve","reject","Error","server","Server","listen","port","address","close","on","err","code","createHMRServer","http","createServer","_","res","body","STATUS_CODES","writeHead","length","end","watch","ctx","hmrServer","availablePort","options","hmrClientPort","config","resolveDevelopmentConfig","finalConfig","mergeConfigWithUserConfig","hmrConfig","hmr","strapi","httpServer","logger","debug","vite","viteMiddlewares","koaCtx","next","prefix","basePath","replace","adminPath","originalPath","path","startsWith","set","middlewares","req","headersSent","serveAdmin","method","status","url","originalUrl","template","fs","readFile","relative","cwd","transformIndexHtml","type","error","adminRoute","existingRoutes","router","stack","filter","layer","forEach","route","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AACC,KAAAA,GAAAA;QACtB,MAAMC,KAAAA,GAAQnD,GAAAA,CAAIW,MAAM,CAAC/B,MAAM,CAACiE,MAAM,CAACC,KAAK,CAACM,OAAO,CAACF,KAAAA,CAAAA;QACrD,IAAIC,KAAAA,GAAQ,EAAC,EAAG;YACdnD,GAAAA,CAAIW,MAAM,CAAC/B,MAAM,CAACiE,MAAM,CAACC,KAAK,CAACO,MAAM,CAACF,KAAAA,EAAO,CAAA,CAAA;AAC/C,QAAA;AACF,IAAA,CAAA,CAAA;IAEAnD,GAAAA,CAAIW,MAAM,CAAC/B,MAAM,CAACiE,MAAM,CAACS,GAAG,CAACX,UAAAA,EAAYb,UAAAA,CAAAA;IACzC9B,GAAAA,CAAIW,MAAM,CAAC/B,MAAM,CAACiE,MAAM,CAACU,GAAG,CAACZ,UAAAA,EAAY3B,eAAAA,CAAAA;IAEzC,OAAO;QACL,MAAM/B,KAAAA,CAAAA,GAAAA;AACJ,YAAA,MAAM8B,KAAK9B,KAAK,EAAA;YAEhB,IAAIgB,SAAAA,CAAUuD,SAAS,EAAE;;;;gBAIvB,MAAM,IAAIhF,OAAAA,CAAc,CAACC,OAAAA,EAASC,MAAAA,GAAAA;AAChCuB,oBAAAA,SAAAA,CAAUhB,KAAK,CAAC,CAACE,GAAAA,GAASA,GAAAA,GAAMT,OAAOS,GAAAA,CAAAA,GAAOV,OAAAA,EAAAA,CAAAA;AAChD,gBAAA,CAAA,CAAA;AACF,YAAA;AACF,QAAA;AACF,KAAA;AACF;;;;"}
|
|
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 finalConfig = await mergeConfigWithUserConfig(await resolveDevelopmentConfig(ctx), 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 const viteMiddlewares: Core.MiddlewareHandler = (koaCtx, next) => {\n return new Promise((resolve, reject) => {\n const prefix = ctx.basePath.replace(ctx.adminPath, '').replace(/\\/+$/, '');\n\n const originalPath = koaCtx.path;\n if (!koaCtx.path.startsWith(prefix)) {\n koaCtx.path = `${prefix}${koaCtx.path}`;\n }\n\n // Set cache-control headers to prevent caching issues during development restarts\n koaCtx.set('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate');\n koaCtx.set('Pragma', 'no-cache');\n koaCtx.set('Expires', '0');\n koaCtx.set('Surrogate-Control', 'no-store');\n\n vite.middlewares(koaCtx.req, koaCtx.res, (err: unknown) => {\n if (err) {\n reject(err);\n } else {\n if (!koaCtx.res.headersSent) {\n koaCtx.path = originalPath;\n }\n\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 try {\n let template = await fs.readFile(\n path.relative(ctx.cwd, '.strapi/client/index.html'),\n 'utf-8'\n );\n template = await vite.transformIndexHtml(url, template);\n\n koaCtx.type = 'html';\n koaCtx.body = template;\n } catch (error) {\n ctx.logger.error('Failed to serve admin panel in development mode:', error);\n // Don't fallback to other handlers in development mode to prevent MIME type conflicts\n koaCtx.status = 500;\n koaCtx.body = 'Admin panel temporarily unavailable during server restart';\n }\n };\n\n const adminRoute = `${ctx.adminPath}/:path*`;\n\n // Remove any existing admin routes to prevent conflicts during restart\n const existingRoutes = ctx.strapi.server.router.stack.filter(\n (layer) => layer.path === adminRoute\n );\n existingRoutes.forEach((route) => {\n const index = ctx.strapi.server.router.stack.indexOf(route);\n if (index > -1) {\n ctx.strapi.server.router.stack.splice(index, 1);\n }\n });\n\n ctx.strapi.server.router.get(adminRoute, serveAdmin);\n ctx.strapi.server.router.use(adminRoute, viteMiddlewares);\n\n return {\n async close() {\n await vite.close();\n },\n };\n};\n\nexport { watch };\nexport type { ViteWatcher };\n"],"names":["watch","ctx","finalConfig","mergeConfigWithUserConfig","resolveDevelopmentConfig","logger","debug","createServer","vite","viteMiddlewares","koaCtx","next","Promise","resolve","reject","prefix","basePath","replace","adminPath","originalPath","path","startsWith","set","middlewares","req","res","err","headersSent","serveAdmin","method","body","status","url","originalUrl","template","fs","readFile","relative","cwd","transformIndexHtml","type","error","adminRoute","existingRoutes","strapi","server","router","stack","filter","layer","forEach","route","index","indexOf","splice","get","use","close"],"mappings":";;;;AAYA,MAAMA,QAAQ,OAAOC,GAAAA,GAAAA;AACnB,IAAA,MAAMC,WAAAA,GAAc,MAAMC,yBAAAA,CAA0B,MAAMC,yBAAyBH,GAAAA,CAAAA,EAAMA,GAAAA,CAAAA;AAEzFA,IAAAA,GAAAA,CAAII,MAAM,CAACC,KAAK,CAAC,aAAA,EAAeJ,WAAAA,CAAAA;AAEhC,IAAA,MAAM,EAAEK,YAAY,EAAE,GAAG,MAAM,OAAO,MAAA,CAAA;IAEtC,MAAMC,IAAAA,GAAO,MAAMD,YAAAA,CAAaL,WAAAA,CAAAA;IAEhC,MAAMO,eAAAA,GAA0C,CAACC,MAAAA,EAAQC,IAAAA,GAAAA;QACvD,OAAO,IAAIC,OAAAA,CAAQ,CAACC,OAAAA,EAASC,MAAAA,GAAAA;AAC3B,YAAA,MAAMC,MAAAA,GAASd,GAAAA,CAAIe,QAAQ,CAACC,OAAO,CAAChB,GAAAA,CAAIiB,SAAS,EAAE,EAAA,CAAA,CAAID,OAAO,CAAC,MAAA,EAAQ,EAAA,CAAA;YAEvE,MAAME,YAAAA,GAAeT,OAAOU,IAAI;AAChC,YAAA,IAAI,CAACV,MAAAA,CAAOU,IAAI,CAACC,UA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ACC,MAAM,CAACC,MAAM,CAACS,GAAG,CAACb,UAAAA,EAAYd,UAAAA,CAAAA;IACzC3B,GAAAA,CAAI2C,MAAM,CAACC,MAAM,CAACC,MAAM,CAACU,GAAG,CAACd,UAAAA,EAAYjC,eAAAA,CAAAA;IAEzC,OAAO;QACL,MAAMgD,KAAAA,CAAAA,GAAAA;AACJ,YAAA,MAAMjD,KAAKiD,KAAK,EAAA;AAClB,QAAA;AACF,KAAA;AACF;;;;"}
|
|
@@ -4,12 +4,16 @@ var webpack = require('webpack');
|
|
|
4
4
|
var config = require('./config.js');
|
|
5
5
|
var errors = require('../core/errors.js');
|
|
6
6
|
|
|
7
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
|
|
9
|
+
var webpack__default = /*#__PURE__*/_interopDefault(webpack);
|
|
10
|
+
|
|
7
11
|
const build = async (ctx)=>{
|
|
8
12
|
const config$1 = await config.resolveProductionConfig(ctx);
|
|
9
13
|
const finalConfig = await config.mergeConfigWithUserConfig(config$1, ctx);
|
|
10
14
|
ctx.logger.debug('Webpack config', finalConfig);
|
|
11
15
|
return new Promise((resolve, reject)=>{
|
|
12
|
-
|
|
16
|
+
webpack__default.default(finalConfig, (err, stats)=>{
|
|
13
17
|
if (stats) {
|
|
14
18
|
if (stats.hasErrors()) {
|
|
15
19
|
ctx.logger.error(stats.toString({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","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":["build","ctx","config","resolveProductionConfig","finalConfig","mergeConfigWithUserConfig","logger","debug","Promise","resolve","reject","webpack","err","stats","hasErrors","error","toString","chunks","colors","options","info","isError","message"],"mappings":"
|
|
1
|
+
{"version":3,"file":"build.js","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":["build","ctx","config","resolveProductionConfig","finalConfig","mergeConfigWithUserConfig","logger","debug","Promise","resolve","reject","webpack","err","stats","hasErrors","error","toString","chunks","colors","options","info","isError","message"],"mappings":";;;;;;;;;;AAOA,MAAMA,QAAQ,OAAOC,GAAAA,GAAAA;IACnB,MAAMC,QAAAA,GAAS,MAAMC,8BAAAA,CAAwBF,GAAAA,CAAAA;IAC7C,MAAMG,WAAAA,GAAc,MAAMC,gCAAAA,CAA0BH,QAAAA,EAAQD,GAAAA,CAAAA;AAE5DA,IAAAA,GAAAA,CAAIK,MAAM,CAACC,KAAK,CAAC,gBAAA,EAAkBH,WAAAA,CAAAA;IAEnC,OAAO,IAAII,OAAAA,CAAQ,CAACC,OAAAA,EAASC,MAAAA,GAAAA;QAC3BC,wBAAAA,CAAQP,WAAAA,EAAa,CAACQ,GAAAA,EAAKC,KAAAA,GAAAA;AACzB,YAAA,IAAIA,KAAAA,EAAO;gBACT,IAAIA,KAAAA,CAAMC,SAAS,EAAA,EAAI;AACrBb,oBAAAA,GAAAA,CAAIK,MAAM,CAACS,KAAK,CACdF,KAAAA,CAAMG,QAAQ,CAAC;wBACbC,MAAAA,EAAQ,KAAA;wBACRC,MAAAA,EAAQ;AACV,qBAAA,CAAA,CAAA;AAGFR,oBAAAA,MAAAA,EAAAA;AACF,gBAAA,CAAA,MAAO,IAAIT,GAAAA,CAAIkB,OAAO,CAACN,KAAK,EAAE;AAC5BZ,oBAAAA,GAAAA,CAAIK,MAAM,CAACc,IAAI,CACbP,KAAAA,CAAMG,QAAQ,CAAC;wBACbC,MAAAA,EAAQ,KAAA;wBACRC,MAAAA,EAAQ;AACV,qBAAA,CAAA,CAAA;AAEJ,gBAAA;gBAEAT,OAAAA,CAAQ,IAAA,CAAA;AACV,YAAA;YAEA,IAAIG,GAAAA,IAAOS,eAAQT,GAAAA,CAAAA,EAAM;AACvBX,gBAAAA,GAAAA,CAAIK,MAAM,CAACS,KAAK,CAACH,IAAIU,OAAO,CAAA;AAC5BZ,gBAAAA,MAAAA,EAAAA;AACF,YAAA;AACF,QAAA,CAAA,CAAA;AACF,IAAA,CAAA,CAAA;AACF;;;;"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
|
|
4
|
-
var browserslistToEsbuild = require('browserslist-to-esbuild');
|
|
5
4
|
var esbuildLoader = require('esbuild-loader');
|
|
6
5
|
var ForkTsCheckerPlugin = require('fork-ts-checker-webpack-plugin');
|
|
7
6
|
var HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
@@ -16,7 +15,17 @@ var linkedPackages = require('../core/linked-packages.js');
|
|
|
16
15
|
var aliases = require('../core/aliases.js');
|
|
17
16
|
var resolveModule = require('../core/resolve-module.js');
|
|
18
17
|
|
|
18
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
19
|
+
|
|
20
|
+
var ReactRefreshWebpackPlugin__default = /*#__PURE__*/_interopDefault(ReactRefreshWebpackPlugin);
|
|
21
|
+
var ForkTsCheckerPlugin__default = /*#__PURE__*/_interopDefault(ForkTsCheckerPlugin);
|
|
22
|
+
var HtmlWebpackPlugin__default = /*#__PURE__*/_interopDefault(HtmlWebpackPlugin);
|
|
23
|
+
var MiniCssExtractPlugin__default = /*#__PURE__*/_interopDefault(MiniCssExtractPlugin);
|
|
24
|
+
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
25
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
26
|
+
|
|
19
27
|
const resolveBaseConfig = async (ctx)=>{
|
|
28
|
+
const { default: browserslistToEsbuild } = await import('browserslist-to-esbuild');
|
|
20
29
|
const target = browserslistToEsbuild(ctx.target);
|
|
21
30
|
return {
|
|
22
31
|
experiments: {
|
|
@@ -111,15 +120,15 @@ const resolveBaseConfig = async (ctx)=>{
|
|
|
111
120
|
]
|
|
112
121
|
},
|
|
113
122
|
plugins: [
|
|
114
|
-
new
|
|
123
|
+
new HtmlWebpackPlugin__default.default({
|
|
115
124
|
inject: true,
|
|
116
|
-
template:
|
|
125
|
+
template: path__default.default.resolve(ctx.runtimeDir, 'index.html')
|
|
117
126
|
}),
|
|
118
127
|
new webpack.DefinePlugin(Object.entries(ctx.env).reduce((acc, [key, value])=>{
|
|
119
128
|
acc[`process.env.${key}`] = JSON.stringify(value);
|
|
120
129
|
return acc;
|
|
121
130
|
}, {})),
|
|
122
|
-
ctx.tsconfig && new
|
|
131
|
+
ctx.tsconfig && new ForkTsCheckerPlugin__default.default({
|
|
123
132
|
typescript: {
|
|
124
133
|
configFile: ctx.tsconfig.path,
|
|
125
134
|
configOverwrite: {
|
|
@@ -148,11 +157,11 @@ const resolveDevelopmentConfig = async (ctx)=>{
|
|
|
148
157
|
// When design-system is linked, invalidate cache when it changes
|
|
149
158
|
...linkedDesignSystemPath && {
|
|
150
159
|
designSystem: [
|
|
151
|
-
|
|
160
|
+
path__default.default.join(linkedDesignSystemPath, 'dist')
|
|
152
161
|
]
|
|
153
162
|
}
|
|
154
163
|
},
|
|
155
|
-
version:
|
|
164
|
+
version: crypto__default.default.createHash('md5').update(Object.entries(baseConfig.resolve.alias ?? {}).join()).digest('hex')
|
|
156
165
|
},
|
|
157
166
|
resolve: {
|
|
158
167
|
...baseConfig.resolve,
|
|
@@ -184,11 +193,12 @@ const resolveDevelopmentConfig = async (ctx)=>{
|
|
|
184
193
|
plugins: [
|
|
185
194
|
...baseConfig.plugins,
|
|
186
195
|
new webpack.HotModuleReplacementPlugin(),
|
|
187
|
-
new
|
|
196
|
+
new ReactRefreshWebpackPlugin__default.default()
|
|
188
197
|
]
|
|
189
198
|
};
|
|
190
199
|
};
|
|
191
200
|
const resolveProductionConfig = async (ctx)=>{
|
|
201
|
+
const { default: browserslistToEsbuild } = await import('browserslist-to-esbuild');
|
|
192
202
|
const target = browserslistToEsbuild(ctx.target);
|
|
193
203
|
const baseConfig = await resolveBaseConfig(ctx);
|
|
194
204
|
return {
|
|
@@ -218,7 +228,7 @@ const resolveProductionConfig = async (ctx)=>{
|
|
|
218
228
|
},
|
|
219
229
|
plugins: [
|
|
220
230
|
...baseConfig.plugins,
|
|
221
|
-
new
|
|
231
|
+
new MiniCssExtractPlugin__default.default({
|
|
222
232
|
filename: '[name].[chunkhash].css',
|
|
223
233
|
chunkFilename: '[name].[chunkhash].chunkhash.css',
|
|
224
234
|
ignoreOrder: true
|
|
@@ -239,7 +249,7 @@ const mergeConfigWithUserConfig = async (config$1, ctx)=>{
|
|
|
239
249
|
const webpack = await import('webpack');
|
|
240
250
|
return userConfig(config$1, webpack);
|
|
241
251
|
}
|
|
242
|
-
ctx.logger.warn(`You've exported something other than a function from ${
|
|
252
|
+
ctx.logger.warn(`You've exported something other than a function from ${path__default.default.join(ctx.appDir, 'src', 'admin', 'webpack.config')}, this will ignored.`);
|
|
243
253
|
}
|
|
244
254
|
return config$1;
|
|
245
255
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sources":["../../../../src/node/webpack/config.ts"],"sourcesContent":["import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';\nimport browserslistToEsbuild from 'browserslist-to-esbuild';\nimport { EsbuildPlugin } from 'esbuild-loader';\nimport ForkTsCheckerPlugin from 'fork-ts-checker-webpack-plugin';\nimport HtmlWebpackPlugin from 'html-webpack-plugin';\nimport MiniCssExtractPlugin from 'mini-css-extract-plugin';\nimport crypto from 'node:crypto';\nimport path from 'node:path';\nimport { Configuration, DefinePlugin, HotModuleReplacementPlugin } from 'webpack';\nimport { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';\n\nimport { loadStrapiMonorepo } from '../core/monorepo';\nimport type { BuildContext } from '../create-build-context';\nimport { getUserConfig } from '../core/config';\nimport { getLinkedDesignSystemPath } from '../core/linked-packages';\nimport { getMonorepoAliases } from '../core/aliases';\nimport { getModulePath } from '../core/resolve-module';\n\nconst resolveBaseConfig = async (ctx: BuildContext) => {\n const target = browserslistToEsbuild(ctx.target);\n\n return {\n experiments: {\n topLevelAwait: true,\n },\n entry: {\n main: [`./${ctx.entry}`],\n },\n resolve: {\n alias: {\n react: getModulePath('react'),\n 'react-dom': getModulePath('react-dom'),\n 'styled-components': getModulePath('styled-components'),\n 'react-router-dom': getModulePath('react-router-dom'),\n // Force single instance so plugin custom field chunks inherit root DesignSystemProvider context\n '@strapi/design-system': getModulePath('@strapi/design-system'),\n '@radix-ui/react-tooltip': getModulePath('@radix-ui/react-tooltip'),\n },\n extensions: ['.js', '.jsx', '.react.js', '.ts', '.tsx'],\n },\n module: {\n rules: [\n {\n test: /\\.(ts|tsx)$/,\n loader: require.resolve('esbuild-loader'),\n options: {\n loader: 'tsx',\n target,\n jsx: 'automatic',\n },\n },\n {\n test: /\\.(js|jsx|mjs)$/,\n use: {\n loader: require.resolve('esbuild-loader'),\n options: {\n loader: 'jsx',\n target,\n jsx: 'automatic',\n },\n },\n },\n {\n test: /\\.m?js/,\n resolve: {\n fullySpecified: false,\n },\n },\n {\n test: /\\.css$/i,\n use: [require.resolve('style-loader'), require.resolve('css-loader')],\n },\n {\n test: /\\.(svg|eot|otf|ttf|woff|woff2)$/,\n type: 'asset/resource',\n },\n {\n test: [/\\.bmp$/, /\\.gif$/, /\\.jpe?g$/, /\\.png$/, /\\.ico$/],\n type: 'asset',\n parser: {\n dataUrlCondition: {\n maxSize: 1000,\n },\n },\n },\n {\n test: /\\.(mp4|webm)$/,\n type: 'asset',\n parser: {\n dataUrlCondition: {\n maxSize: 10000,\n },\n },\n },\n ],\n },\n plugins: [\n new HtmlWebpackPlugin({\n inject: true,\n template: path.resolve(ctx.runtimeDir, 'index.html'),\n }),\n new DefinePlugin(\n Object.entries(ctx.env).reduce<Record<string, string>>((acc, [key, value]) => {\n acc[`process.env.${key}`] = JSON.stringify(value);\n return acc;\n }, {})\n ),\n ctx.tsconfig &&\n new ForkTsCheckerPlugin({\n typescript: {\n configFile: ctx.tsconfig.path,\n configOverwrite: {\n compilerOptions: {\n sourceMap: ctx.options.sourcemaps,\n },\n },\n },\n }),\n ].filter(Boolean),\n };\n};\n\nconst resolveDevelopmentConfig = async (ctx: BuildContext): Promise<Configuration> => {\n const baseConfig = await resolveBaseConfig(ctx);\n const monorepo = await loadStrapiMonorepo(ctx.cwd);\n const linkedDesignSystemPath = getLinkedDesignSystemPath();\n\n return {\n ...baseConfig,\n cache: {\n type: 'filesystem',\n // version cache when there are changes to aliases\n buildDependencies: {\n config: [__filename],\n // When design-system is linked, invalidate cache when it changes\n ...(linkedDesignSystemPath && {\n designSystem: [path.join(linkedDesignSystemPath, 'dist')],\n }),\n },\n version: crypto\n .createHash('md5')\n .update(Object.entries(baseConfig.resolve.alias ?? {}).join())\n .digest('hex'),\n },\n resolve: {\n ...baseConfig.resolve,\n alias: {\n ...baseConfig.resolve.alias,\n ...getMonorepoAliases({ monorepo }),\n },\n },\n entry: {\n ...baseConfig.entry,\n main: [\n `${require.resolve('webpack-hot-middleware/client')}?path=/__webpack_hmr`,\n ...baseConfig.entry.main,\n ],\n },\n stats: 'errors-warnings',\n mode: 'development',\n devtool: 'inline-source-map',\n output: {\n filename: '[name].js',\n path: ctx.distPath,\n publicPath: `${ctx.basePath.replace(/\\/$/, '')}/`,\n },\n infrastructureLogging: {\n level: 'error',\n },\n plugins: [\n ...baseConfig.plugins,\n new HotModuleReplacementPlugin(),\n new ReactRefreshWebpackPlugin(),\n ],\n };\n};\n\nconst resolveProductionConfig = async (ctx: BuildContext): Promise<Configuration> => {\n const target = browserslistToEsbuild(ctx.target);\n\n const baseConfig = await resolveBaseConfig(ctx);\n\n return {\n ...baseConfig,\n stats: 'errors-only',\n mode: 'production',\n bail: true,\n devtool: ctx.options.sourcemaps ? 'source-map' : false,\n output: {\n path: ctx.distPath,\n publicPath: `${ctx.basePath.replace(/\\/$/, '')}/`,\n // Utilize long-term caching by adding content hashes (not compilation hashes)\n // to compiled assets for production\n filename: '[name].[contenthash:8].js',\n chunkFilename: '[name].[contenthash:8].chunk.js',\n },\n optimization: {\n minimize: ctx.options.minify,\n minimizer: [\n new EsbuildPlugin({\n target,\n css: true, // Apply minification to CSS assets\n }),\n ],\n moduleIds: 'deterministic',\n runtimeChunk: true,\n },\n plugins: [\n ...baseConfig.plugins,\n new MiniCssExtractPlugin({\n filename: '[name].[chunkhash].css',\n chunkFilename: '[name].[chunkhash].chunkhash.css',\n ignoreOrder: true,\n }),\n ctx.options.stats && new BundleAnalyzerPlugin(),\n ].filter(Boolean),\n };\n};\n\nconst USER_CONFIGS = ['webpack.config.js', 'webpack.config.mjs', 'webpack.config.ts'];\n\ntype UserWebpackConfig = (config: Configuration, webpack: unknown) => Configuration;\n\nconst mergeConfigWithUserConfig = async (config: Configuration, ctx: BuildContext) => {\n const userConfig = await getUserConfig<UserWebpackConfig>(USER_CONFIGS, ctx);\n\n if (userConfig) {\n if (typeof userConfig === 'function') {\n const webpack = await import('webpack');\n return userConfig(config, webpack);\n }\n\n ctx.logger.warn(\n `You've exported something other than a function from ${path.join(\n ctx.appDir,\n 'src',\n 'admin',\n 'webpack.config'\n )}, this will ignored.`\n );\n }\n\n return config;\n};\n\nexport { mergeConfigWithUserConfig, resolveDevelopmentConfig, resolveProductionConfig };\n"],"names":["resolveBaseConfig","ctx","target","browserslistToEsbuild","experiments","topLevelAwait","entry","main","resolve","alias","react","getModulePath","extensions","module","rules","test","loader","require","options","jsx","use","fullySpecified","type","parser","dataUrlCondition","maxSize","plugins","HtmlWebpackPlugin","inject","template","path","runtimeDir","DefinePlugin","Object","entries","env","reduce","acc","key","value","JSON","stringify","tsconfig","ForkTsCheckerPlugin","typescript","configFile","configOverwrite","compilerOptions","sourceMap","sourcemaps","filter","Boolean","resolveDevelopmentConfig","baseConfig","monorepo","loadStrapiMonorepo","cwd","linkedDesignSystemPath","getLinkedDesignSystemPath","cache","buildDependencies","config","__filename","designSystem","join","version","crypto","createHash","update","digest","getMonorepoAliases","stats","mode","devtool","output","filename","distPath","publicPath","basePath","replace","infrastructureLogging","level","HotModuleReplacementPlugin","ReactRefreshWebpackPlugin","resolveProductionConfig","bail","chunkFilename","optimization","minimize","minify","minimizer","EsbuildPlugin","css","moduleIds","runtimeChunk","MiniCssExtractPlugin","ignoreOrder","BundleAnalyzerPlugin","USER_CONFIGS","mergeConfigWithUserConfig","userConfig","getUserConfig","webpack","logger","warn","appDir"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,MAAMA,oBAAoB,OAAOC,GAAAA,GAAAA;IAC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,CAACC,IAAI,CACb,CAAC,qDAAqD,EAAE1E,IAAAA,CAAKkC,IAAI,CAC/D/D,IAAIwG,MAAM,EACV,OACA,OAAA,EACA,gBAAA,CAAA,CACA,oBAAoB,CAAC,CAAA;AAE3B,IAAA;IAEA,OAAO5C,QAAAA;AACT;;;;;;"}
|
|
1
|
+
{"version":3,"file":"config.js","sources":["../../../../src/node/webpack/config.ts"],"sourcesContent":["import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';\nimport { EsbuildPlugin } from 'esbuild-loader';\nimport ForkTsCheckerPlugin from 'fork-ts-checker-webpack-plugin';\nimport HtmlWebpackPlugin from 'html-webpack-plugin';\nimport MiniCssExtractPlugin from 'mini-css-extract-plugin';\nimport crypto from 'node:crypto';\nimport path from 'node:path';\nimport { Configuration, DefinePlugin, HotModuleReplacementPlugin } from 'webpack';\nimport { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';\n\nimport { loadStrapiMonorepo } from '../core/monorepo';\nimport type { BuildContext } from '../create-build-context';\nimport { getUserConfig } from '../core/config';\nimport { getLinkedDesignSystemPath } from '../core/linked-packages';\nimport { getMonorepoAliases } from '../core/aliases';\nimport { getModulePath } from '../core/resolve-module';\n\nconst resolveBaseConfig = async (ctx: BuildContext) => {\n const { default: browserslistToEsbuild } = await import('browserslist-to-esbuild');\n const target = browserslistToEsbuild(ctx.target);\n\n return {\n experiments: {\n topLevelAwait: true,\n },\n entry: {\n main: [`./${ctx.entry}`],\n },\n resolve: {\n alias: {\n react: getModulePath('react'),\n 'react-dom': getModulePath('react-dom'),\n 'styled-components': getModulePath('styled-components'),\n 'react-router-dom': getModulePath('react-router-dom'),\n // Force single instance so plugin custom field chunks inherit root DesignSystemProvider context\n '@strapi/design-system': getModulePath('@strapi/design-system'),\n '@radix-ui/react-tooltip': getModulePath('@radix-ui/react-tooltip'),\n },\n extensions: ['.js', '.jsx', '.react.js', '.ts', '.tsx'],\n },\n module: {\n rules: [\n {\n test: /\\.(ts|tsx)$/,\n loader: require.resolve('esbuild-loader'),\n options: {\n loader: 'tsx',\n target,\n jsx: 'automatic',\n },\n },\n {\n test: /\\.(js|jsx|mjs)$/,\n use: {\n loader: require.resolve('esbuild-loader'),\n options: {\n loader: 'jsx',\n target,\n jsx: 'automatic',\n },\n },\n },\n {\n test: /\\.m?js/,\n resolve: {\n fullySpecified: false,\n },\n },\n {\n test: /\\.css$/i,\n use: [require.resolve('style-loader'), require.resolve('css-loader')],\n },\n {\n test: /\\.(svg|eot|otf|ttf|woff|woff2)$/,\n type: 'asset/resource',\n },\n {\n test: [/\\.bmp$/, /\\.gif$/, /\\.jpe?g$/, /\\.png$/, /\\.ico$/],\n type: 'asset',\n parser: {\n dataUrlCondition: {\n maxSize: 1000,\n },\n },\n },\n {\n test: /\\.(mp4|webm)$/,\n type: 'asset',\n parser: {\n dataUrlCondition: {\n maxSize: 10000,\n },\n },\n },\n ],\n },\n plugins: [\n new HtmlWebpackPlugin({\n inject: true,\n template: path.resolve(ctx.runtimeDir, 'index.html'),\n }),\n new DefinePlugin(\n Object.entries(ctx.env).reduce<Record<string, string>>((acc, [key, value]) => {\n acc[`process.env.${key}`] = JSON.stringify(value);\n return acc;\n }, {})\n ),\n ctx.tsconfig &&\n new ForkTsCheckerPlugin({\n typescript: {\n configFile: ctx.tsconfig.path,\n configOverwrite: {\n compilerOptions: {\n sourceMap: ctx.options.sourcemaps,\n },\n },\n },\n }),\n ].filter(Boolean),\n };\n};\n\nconst resolveDevelopmentConfig = async (ctx: BuildContext): Promise<Configuration> => {\n const baseConfig = await resolveBaseConfig(ctx);\n const monorepo = await loadStrapiMonorepo(ctx.cwd);\n const linkedDesignSystemPath = getLinkedDesignSystemPath();\n\n return {\n ...baseConfig,\n cache: {\n type: 'filesystem',\n // version cache when there are changes to aliases\n buildDependencies: {\n config: [__filename],\n // When design-system is linked, invalidate cache when it changes\n ...(linkedDesignSystemPath && {\n designSystem: [path.join(linkedDesignSystemPath, 'dist')],\n }),\n },\n version: crypto\n .createHash('md5')\n .update(Object.entries(baseConfig.resolve.alias ?? {}).join())\n .digest('hex'),\n },\n resolve: {\n ...baseConfig.resolve,\n alias: {\n ...baseConfig.resolve.alias,\n ...getMonorepoAliases({ monorepo }),\n },\n },\n entry: {\n ...baseConfig.entry,\n main: [\n `${require.resolve('webpack-hot-middleware/client')}?path=/__webpack_hmr`,\n ...baseConfig.entry.main,\n ],\n },\n stats: 'errors-warnings',\n mode: 'development',\n devtool: 'inline-source-map',\n output: {\n filename: '[name].js',\n path: ctx.distPath,\n publicPath: `${ctx.basePath.replace(/\\/$/, '')}/`,\n },\n infrastructureLogging: {\n level: 'error',\n },\n plugins: [\n ...baseConfig.plugins,\n new HotModuleReplacementPlugin(),\n new ReactRefreshWebpackPlugin(),\n ],\n };\n};\n\nconst resolveProductionConfig = async (ctx: BuildContext): Promise<Configuration> => {\n const { default: browserslistToEsbuild } = await import('browserslist-to-esbuild');\n const target = browserslistToEsbuild(ctx.target);\n\n const baseConfig = await resolveBaseConfig(ctx);\n\n return {\n ...baseConfig,\n stats: 'errors-only',\n mode: 'production',\n bail: true,\n devtool: ctx.options.sourcemaps ? 'source-map' : false,\n output: {\n path: ctx.distPath,\n publicPath: `${ctx.basePath.replace(/\\/$/, '')}/`,\n // Utilize long-term caching by adding content hashes (not compilation hashes)\n // to compiled assets for production\n filename: '[name].[contenthash:8].js',\n chunkFilename: '[name].[contenthash:8].chunk.js',\n },\n optimization: {\n minimize: ctx.options.minify,\n minimizer: [\n new EsbuildPlugin({\n target,\n css: true, // Apply minification to CSS assets\n }),\n ],\n moduleIds: 'deterministic',\n runtimeChunk: true,\n },\n plugins: [\n ...baseConfig.plugins,\n new MiniCssExtractPlugin({\n filename: '[name].[chunkhash].css',\n chunkFilename: '[name].[chunkhash].chunkhash.css',\n ignoreOrder: true,\n }),\n ctx.options.stats && new BundleAnalyzerPlugin(),\n ].filter(Boolean),\n };\n};\n\nconst USER_CONFIGS = ['webpack.config.js', 'webpack.config.mjs', 'webpack.config.ts'];\n\ntype UserWebpackConfig = (config: Configuration, webpack: unknown) => Configuration;\n\nconst mergeConfigWithUserConfig = async (config: Configuration, ctx: BuildContext) => {\n const userConfig = await getUserConfig<UserWebpackConfig>(USER_CONFIGS, ctx);\n\n if (userConfig) {\n if (typeof userConfig === 'function') {\n const webpack = await import('webpack');\n return userConfig(config, webpack);\n }\n\n ctx.logger.warn(\n `You've exported something other than a function from ${path.join(\n ctx.appDir,\n 'src',\n 'admin',\n 'webpack.config'\n )}, this will ignored.`\n );\n }\n\n return config;\n};\n\nexport { mergeConfigWithUserConfig, resolveDevelopmentConfig, resolveProductionConfig };\n"],"names":["resolveBaseConfig","ctx","default","browserslistToEsbuild","target","experiments","topLevelAwait","entry","main","resolve","alias","react","getModulePath","extensions","module","rules","test","loader","require","options","jsx","use","fullySpecified","type","parser","dataUrlCondition","maxSize","plugins","HtmlWebpackPlugin","inject","template","path","runtimeDir","DefinePlugin","Object","entries","env","reduce","acc","key","value","JSON","stringify","tsconfig","ForkTsCheckerPlugin","typescript","configFile","configOverwrite","compilerOptions","sourceMap","sourcemaps","filter","Boolean","resolveDevelopmentConfig","baseConfig","monorepo","loadStrapiMonorepo","cwd","linkedDesignSystemPath","getLinkedDesignSystemPath","cache","buildDependencies","config","__filename","designSystem","join","version","crypto","createHash","update","digest","getMonorepoAliases","stats","mode","devtool","output","filename","distPath","publicPath","basePath","replace","infrastructureLogging","level","HotModuleReplacementPlugin","ReactRefreshWebpackPlugin","resolveProductionConfig","bail","chunkFilename","optimization","minimize","minify","minimizer","EsbuildPlugin","css","moduleIds","runtimeChunk","MiniCssExtractPlugin","ignoreOrder","BundleAnalyzerPlugin","USER_CONFIGS","mergeConfigWithUserConfig","userConfig","getUserConfig","webpack","logger","warn","appDir"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,MAAMA,oBAAoB,OAAOC,GAAAA,GAAAA;AAC/B,IAAA,MAAM,EAAEC,OAAAA,EAASC,qBAAqB,EAAE,G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SAAA,CAAA;AAC7B,YAAA,OAAOF,WAAWvC,QAAAA,EAAQyC,OAAAA,CAAAA;AAC5B,QAAA;AAEAtG,QAAAA,GAAAA,CAAIuG,MAAM,CAACC,IAAI,CACb,CAAC,qDAAqD,EAAE1E,qBAAAA,CAAKkC,IAAI,CAC/DhE,IAAIyG,MAAM,EACV,OACA,OAAA,EACA,gBAAA,CAAA,CACA,oBAAoB,CAAC,CAAA;AAE3B,IAAA;IAEA,OAAO5C,QAAAA;AACT;;;;;;"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
|
|
2
|
-
import browserslistToEsbuild from 'browserslist-to-esbuild';
|
|
3
2
|
import { EsbuildPlugin } from 'esbuild-loader';
|
|
4
3
|
import ForkTsCheckerPlugin from 'fork-ts-checker-webpack-plugin';
|
|
5
4
|
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
@@ -15,6 +14,7 @@ import { getMonorepoAliases } from '../core/aliases.mjs';
|
|
|
15
14
|
import { getModulePath } from '../core/resolve-module.mjs';
|
|
16
15
|
|
|
17
16
|
const resolveBaseConfig = async (ctx)=>{
|
|
17
|
+
const { default: browserslistToEsbuild } = await import('browserslist-to-esbuild');
|
|
18
18
|
const target = browserslistToEsbuild(ctx.target);
|
|
19
19
|
return {
|
|
20
20
|
experiments: {
|
|
@@ -187,6 +187,7 @@ const resolveDevelopmentConfig = async (ctx)=>{
|
|
|
187
187
|
};
|
|
188
188
|
};
|
|
189
189
|
const resolveProductionConfig = async (ctx)=>{
|
|
190
|
+
const { default: browserslistToEsbuild } = await import('browserslist-to-esbuild');
|
|
190
191
|
const target = browserslistToEsbuild(ctx.target);
|
|
191
192
|
const baseConfig = await resolveBaseConfig(ctx);
|
|
192
193
|
return {
|