@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
118 lines (114 loc) • 3.47 kB
JavaScript
;
var browserslistToEsbuild = require('browserslist-to-esbuild');
var react = require('@vitejs/plugin-react-swc');
var config = require('../core/config.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);
return {
root: ctx.cwd,
base: ctx.basePath,
build: {
emptyOutDir: false,
outDir: ctx.distDir,
target
},
cacheDir: 'node_modules/.strapi/vite',
configFile: false,
define: {
'process.env': ctx.env
},
envPrefix: 'STRAPI_ADMIN_',
optimizeDeps: {
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'
]
},
resolve: {
// https://react.dev/warnings/invalid-hook-call-warning#duplicate-react
dedupe: [
'react',
'react-dom',
'react-router-dom',
'styled-components'
]
},
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'
];
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