@strapi/strapi
Version:
An open source headless CMS solution to create and manage your own API. It provides a powerful dashboard and features to make your life easier. Databases supported: MySQL, MariaDB, PostgreSQL, SQLite
218 lines (214 loc) • 8.52 kB
JavaScript
;
var browserslistToEsbuild = require('browserslist-to-esbuild');
var react = require('@vitejs/plugin-react-swc');
var config = require('../core/config.js');
var resolveModule = require('../core/resolve-module.js');
var linkedPackages = require('../core/linked-packages.js');
var monorepo = require('../core/monorepo.js');
var aliases = require('../core/aliases.js');
var plugins = require('./plugins.js');
const resolveBaseConfig = async (ctx)=>{
const target = browserslistToEsbuild(ctx.target);
const isMonorepoExampleApp = ctx.strapi.internal_config?.uuid === 'getstarted';
const designSystemLinked = linkedPackages.isDesignSystemLinked();
return {
root: ctx.cwd,
base: ctx.basePath,
build: {
emptyOutDir: false,
outDir: ctx.distDir,
target
},
cacheDir: 'node_modules/.strapi/vite',
configFile: false,
define: {
process: {},
'process.env': JSON.stringify(ctx.env)
},
envPrefix: 'STRAPI_ADMIN_',
optimizeDeps: {
// When design-system is linked (portal:, file:, yarn link), exclude from pre-bundling
// so changes are reflected without clearing node_modules/.strapi/vite cache
...designSystemLinked && {
exclude: [
'@strapi/design-system'
]
},
include: [
// pre-bundle React dependencies to avoid React duplicates,
// even if React dependencies are not direct dependencies
// https://react.dev/warnings/invalid-hook-call-warning#duplicate-react
'react',
`react/jsx-runtime`,
'react-dom/client',
'styled-components',
'react-router-dom',
// Pre-bundle design-system so plugin custom field chunks (dynamic imports) resolve
// to the same instance as the main app. Otherwise TooltipProvider/DesignSystemProvider
// context from the root is not seen by components in plugin chunks.
// Omit when linked so local changes are picked up (see exclude above)
...!designSystemLinked ? [
'@strapi/design-system'
] : [],
'@radix-ui/react-tooltip',
// Pre-bundle lodash: design-system uses named imports (e.g. assignWith) but lodash
// is CommonJS-only; pre-bundling converts it to ESM for the browser
'lodash',
// Pre-bundle prismjs so plugin chunks get a valid ESM namespace (prismjs is UMD and can
// otherwise expose an empty object when bundled, causing "Prism is not defined" in admin).
'prismjs',
/**
* Pre-bundle other dependencies that would otherwise cause a page reload when imported.
* See "performance" section: https://vite.dev/guide/dep-pre-bundling.html#the-why
* Only include dependencies for our internal example apps, otherwise it will break
* real user apps that may not have those dependencies.
*/ ...isMonorepoExampleApp ? [
'@dnd-kit/core',
'@dnd-kit/sortable',
'@dnd-kit/utilities',
'@dnd-kit/modifiers',
'@radix-ui/react-toolbar',
'codemirror5',
'codemirror5/addon/display/placeholder',
'date-fns-tz',
'date-fns/format',
'date-fns/formatISO',
'highlight.js',
'lodash/capitalize',
'lodash/fp',
'lodash/groupBy',
'lodash/has',
'lodash/isNil',
'lodash/locale',
'lodash/map',
'lodash/mapValues',
'lodash/pull',
'lodash/size',
'lodash/sortBy',
'lodash/tail',
'lodash/toLower',
'lodash/toNumber',
'lodash/toString',
'lodash/truncate',
'lodash/uniq',
'lodash/upperFirst',
'markdown-it',
'markdown-it-abbr',
'markdown-it-container',
'markdown-it-deflist',
'markdown-it-emoji',
'markdown-it-footnote',
'markdown-it-ins',
'markdown-it-mark',
'markdown-it-sub',
'markdown-it-sup',
'prismjs/components/*.js',
'react-colorful',
'react-dnd-html5-backend',
'react-window',
'sanitize-html',
'semver',
'semver/functions/lt',
'semver/functions/valid',
'slate',
'slate-history',
'slate-react',
'motion'
] : []
]
},
resolve: {
// https://react.dev/warnings/invalid-hook-call-warning#duplicate-react
// Include design-system so plugin chunks use the same instance and inherit root context
dedupe: [
'react',
'react-dom',
'react-router-dom',
'styled-components',
'@strapi/design-system',
'@radix-ui/react-tooltip',
'lodash'
],
// Explicit aliases ensure resolution under pnpm's strict dependency isolation,
// where packages imported by plugins may not be resolvable from plugin chunks
alias: {
react: resolveModule.getModulePath('react'),
'react-dom': resolveModule.getModulePath('react-dom'),
'react-router-dom': resolveModule.getModulePath('react-router-dom'),
'styled-components': resolveModule.getModulePath('styled-components'),
'@strapi/design-system': resolveModule.getModulePath('@strapi/design-system'),
'@radix-ui/react-tooltip': resolveModule.getModulePath('@radix-ui/react-tooltip'),
lodash: resolveModule.getModulePath('lodash')
}
},
plugins: [
react(),
plugins.buildFilesPlugin(ctx)
]
};
};
const resolveProductionConfig = async (ctx)=>{
const { options: { minify, sourcemaps } } = ctx;
const baseConfig = await resolveBaseConfig(ctx);
return {
...baseConfig,
logLevel: 'silent',
mode: 'production',
build: {
...baseConfig.build,
assetsDir: '',
minify,
sourcemap: sourcemaps,
rollupOptions: {
input: {
strapi: ctx.entry
}
}
}
};
};
const resolveDevelopmentConfig = async (ctx)=>{
const monorepo$1 = await monorepo.loadStrapiMonorepo(ctx.cwd);
const baseConfig = await resolveBaseConfig(ctx);
return {
...baseConfig,
mode: 'development',
resolve: {
...baseConfig.resolve,
alias: {
...baseConfig.resolve?.alias,
...aliases.getMonorepoAliases({
monorepo: monorepo$1
})
}
},
server: {
cors: false,
middlewareMode: true,
open: ctx.options.open,
hmr: {
overlay: false,
server: ctx.options.hmrServer,
clientPort: ctx.options.hmrClientPort
}
},
appType: 'custom'
};
};
const USER_CONFIGS = [
'vite.config.js',
'vite.config.mjs',
'vite.config.ts',
'vite.config.mts'
];
const mergeConfigWithUserConfig = async (config$1, ctx)=>{
const userConfig = await config.getUserConfig(USER_CONFIGS, ctx);
if (userConfig) {
return userConfig(config$1);
}
return config$1;
};
exports.mergeConfigWithUserConfig = mergeConfigWithUserConfig;
exports.resolveDevelopmentConfig = resolveDevelopmentConfig;
exports.resolveProductionConfig = resolveProductionConfig;
//# sourceMappingURL=config.js.map