build(widget): 移除 iife 格式并添加 UMD 复制插件
移除 lib.formats 中的 'iife' 格式,仅保留 'es' 和 'umd'。同时添加自定义 Vite 插件 copyUmdToCwdPlugin,在构建完成后将生成的 UMD 包 (cwd.umd.js) 复制为 cwd.js,以简化部分环境的引用路径。
This commit is contained in:
@@ -29,8 +29,24 @@ function copyDtsPlugin() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function copyUmdToCwdPlugin() {
|
||||||
|
return {
|
||||||
|
name: 'copy-umd-to-cwd',
|
||||||
|
closeBundle() {
|
||||||
|
const src = resolve(__dirname, 'dist/cwd.umd.js');
|
||||||
|
const dest = resolve(__dirname, 'dist/cwd.js');
|
||||||
|
try {
|
||||||
|
copyFileSync(src, dest);
|
||||||
|
console.log(`[copy-umd-to-cwd] Copied ${src} to ${dest}`);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`[copy-umd-to-cwd] Failed to copy UMD bundle to cwd.js: ${e}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [cssInjectedByJsPlugin(), copyDtsPlugin()],
|
plugins: [cssInjectedByJsPlugin(), copyDtsPlugin(), copyUmdToCwdPlugin()],
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@': resolve(__dirname, 'src'),
|
'@': resolve(__dirname, 'src'),
|
||||||
@@ -40,11 +56,10 @@ export default defineConfig({
|
|||||||
lib: {
|
lib: {
|
||||||
name: 'CWDComments',
|
name: 'CWDComments',
|
||||||
entry: resolve(__dirname, 'src/index.js'),
|
entry: resolve(__dirname, 'src/index.js'),
|
||||||
formats: ['es', 'umd', 'iife'],
|
formats: ['es', 'umd'],
|
||||||
fileName: (format) => {
|
fileName: (format) => {
|
||||||
if (format === 'es') return 'cwd.es.js';
|
if (format === 'es') return 'cwd.es.js';
|
||||||
if (format === 'umd') return 'cwd.umd.js';
|
return 'cwd.umd.js';
|
||||||
return 'cwd.js';
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
|
|||||||
Reference in New Issue
Block a user