Skip to content

Commit

Permalink
fix(core): 修复打包后文件中文变成Unicode编码的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
enncy committed Dec 27, 2022
1 parent a976c1b commit ea6da2c
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion packages/core/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { visualizer } from 'rollup-plugin-visualizer';
import { defineConfig } from 'vite';
import banner from 'vite-plugin-banner';
import { author, description, homepage, license, name } from '../../package.json';
import { readFileSync, writeFileSync } from 'fs';
import path from 'path';

const bannerContent = `
/*!
Expand Down Expand Up @@ -32,5 +34,23 @@ export default defineConfig({
}
},

plugins: [visualizer(), banner(bannerContent)]
plugins: [
visualizer(),
banner(bannerContent),
{
// 将打包后的 unicode 中文全部转换成正常中文
name: 'escape-code',
closeBundle() {
const content = readFileSync(path.resolve(__dirname, '../../dist/index.js')).toString();
writeFileSync(
path.resolve(__dirname, '../../dist/index.js'),
unescape(
content.replace(/\\u([\d\w]{4})/gi, function (match, grp) {
return String.fromCharCode(parseInt(grp, 16));
})
)
);
}
}
]
});

0 comments on commit ea6da2c

Please sign in to comment.