mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 13:39:24 +08:00
* refactor: core/build and cli/build.js * fix: build * fix: bug * fix: replaceAll to replace * fix: node version check * fix: add require check * fix: esbuild other ext * fix: process json * fix: exlude jsx-runtime * feat: split chunk * fix: minify plugin client bundle * fix: compatibility * fix: support import() * feat: update docs * fix: server deps * feat: demo * fix: remove cjs treeshake * fix: local error * fix: bug * fix: lazy load * fix: rewrites * fix: remove dynamic import function * feat: doc demo * fix: codesanbox vite template * fix: codesanbox demo * fix: hide stackblitz * fix: revert rspack * fix: test bug * fix: delete console * fix: import dayjs locale --------- Co-authored-by: chenos <chenlinxh@gmail.com>
71 lines
2.0 KiB
TypeScript
71 lines
2.0 KiB
TypeScript
import path from 'path';
|
|
import fg from 'fast-glob';
|
|
import { build as viteBuild } from 'vite';
|
|
import { build as tsupBuild } from 'tsup';
|
|
import { libInjectCss } from 'vite-plugin-lib-inject-css';
|
|
import react from '@vitejs/plugin-react';
|
|
import { PkgLog } from './utils';
|
|
import { globExcludeFiles } from './constant';
|
|
|
|
export async function buildClient(cwd: string, sourcemap: boolean = false, log: PkgLog) {
|
|
log('build client');
|
|
|
|
await Promise.all([buildLib(cwd, sourcemap, 'cjs'), buildLib(cwd, sourcemap, 'es')]);
|
|
await buildLocale(cwd);
|
|
}
|
|
|
|
export function buildLib(cwd: string, sourcemap: boolean, format: 'cjs' | 'es') {
|
|
const outDir = path.resolve(cwd, format === 'cjs' ? 'lib' : 'es');
|
|
const entry = path.join(cwd, 'src/index.ts').replaceAll(/\\/g, '/');
|
|
const cwdWin = cwd.replaceAll(/\\/g, '/');
|
|
const cwdUnix = cwd.replaceAll(/\//g, '\\');
|
|
|
|
return viteBuild({
|
|
mode: 'production',
|
|
define: {
|
|
'process.env.NODE_ENV': JSON.stringify('production'),
|
|
},
|
|
build: {
|
|
minify: false,
|
|
outDir,
|
|
cssCodeSplit: true,
|
|
emptyOutDir: true,
|
|
sourcemap,
|
|
lib: {
|
|
entry,
|
|
formats: [format],
|
|
fileName: 'index',
|
|
},
|
|
target: ['es2015', 'edge88', 'firefox78', 'chrome87', 'safari14'],
|
|
rollupOptions: {
|
|
cache: true,
|
|
treeshake: true,
|
|
external(id) {
|
|
if (id.startsWith('.') || id.startsWith(cwdUnix) || id.startsWith(cwdWin)) {
|
|
return false;
|
|
}
|
|
return true;
|
|
},
|
|
},
|
|
},
|
|
plugins: [react(), libInjectCss()],
|
|
});
|
|
}
|
|
|
|
export function buildLocale(cwd: string) {
|
|
const entry = fg.globSync(['src/locale/**', ...globExcludeFiles], { cwd, absolute: true });
|
|
const outDir = path.resolve(cwd, 'lib', 'locale');
|
|
return tsupBuild({
|
|
entry,
|
|
splitting: false,
|
|
clean: false,
|
|
bundle: false,
|
|
silent: true,
|
|
treeshake: false,
|
|
target: 'node16',
|
|
keepNames: true,
|
|
outDir,
|
|
format: 'cjs',
|
|
skipNodeModulesBundle: true,
|
|
});
|
|
} |