@jellyyang/plugin-vite-encoding
Version:
For Vite build, load Arco Design styles on demand
38 lines • 1.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.toUtf8 = void 0;
const pkg = require('../../package.json');
function toUtf8(str) {
return str
.split('')
.map((ch) => (ch.charCodeAt(0) <= 0x7f ? ch : '\\u' + ('0000' + ch.charCodeAt(0).toString(16)).slice(-4)))
.join('');
}
exports.toUtf8 = toUtf8;
function vitePluginEncoding(options) {
return {
name: pkg.name,
generateBundle(_, bundle) {
for (const file in bundle) {
const chunk = bundle[file];
let shouldTransform = false;
for (const pattern of options.filePatterns) {
if (file.match(new RegExp(pattern))) {
shouldTransform = true;
}
}
if (!shouldTransform) {
continue;
}
// 如果是 JavaScript 文件
if (chunk.type === 'chunk' && chunk?.code && /\.js$/.test(file)) {
// 将内容转换为 UTF-8 编码
const utf8Content = toUtf8(chunk.code);
chunk.code = utf8Content;
}
}
},
};
}
exports.default = vitePluginEncoding;
//# sourceMappingURL=index.js.map