代码拉取完成,页面将自动刷新
import VitePluginStyleInject from 'vite-plugin-style-inject';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import type { Plugin, ResolvedConfig } from 'vite';
import cleaner from 'rollup-plugin-cleaner';
import react from '@vitejs/plugin-react';
import url from '@rollup/plugin-url';
import { defineConfig } from 'vite';
import svgr from '@svgr/rollup';
import { exec } from 'child_process';
const globalName = 'emailEditor';
const output = './src/index.ts';
function consoleConfig(): Plugin {
return {
name: 'consoleConfig',
apply: 'serve',
enforce: "post",
configResolved(resolvedConfig: ResolvedConfig) {
console.log('resolvedConfig', resolvedConfig);
},
}
}
function dts(): Plugin {
return {
name: 'dts',
apply: 'build',
enforce: "post",
configResolved(resolvedConfig: ResolvedConfig) {
console.log('resolvedConfig', resolvedConfig);
},
generateBundle() {
// console.log("{{{{{ ------ generateBundle");
},
buildEnd() {
console.log(" ------ buildEnd ------ ");
exec(`tsc -p ${process.cwd()}/tsconfig.json`)
}
}
}
// https://vitejs.dev/config/
const config = defineConfig(({ command, mode }) => {
if (command === 'serve') {
return {
plugins: [
react(),
url(),
svgr({ icon: true }),
consoleConfig(),
],
}
}
return {
build: {
cssCodeSplit: true,
minify: false,
lib: {
entry: output,
fileName: (format, entryName) => {
console.log('----fileName', format, entryName);
return `${entryName}.js`
}
},
rollupOptions: {
input: output,
external: ['react-dom', 'react', 'react/jsx-runtime'],
output: [
{
dir: 'lib/es',
format: 'es',
preserveModules: true,
},
{
dir: 'lib/cjs',
format: 'cjs',
preserveModules: true,
exports: 'named',
},
{
dir: 'lib/umd',
format: 'umd',
name: globalName,
exports: 'named',
globals: {
react: 'React',
'react-dom': 'ReactDOM',
'react/jsx-runtime': 'jsxRuntime'
}
},
],
preserveEntrySignatures: 'strict',
},
},
plugins: [
cleaner({
targets: ['./lib']
}),
nodeResolve({
browser: true,
}),
react({
jsxRuntime: 'classic',
}),
VitePluginStyleInject(),
url(),
svgr({ icon: true }),
dts(),
],
}
})
export default config
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。