代码拉取完成,页面将自动刷新
import path from 'node:path';
import { rollup } from 'rollup';
import fse from 'fs-extra';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import postcss from 'rollup-plugin-postcss';
import autoprefixer from 'autoprefixer';
async function compilerCss(entryPath, outputPath) {
const bundle = await rollup({
input: entryPath,
plugins: [
nodeResolve({
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'],
}),
postcss({
modules: false,
extract: true,
plugins: [autoprefixer],
}),
],
onwarn(warning, warn) {
if (warning.code === 'FILE_NAME_CONFLICT') return;
warn(warning);
},
});
await bundle.write({
file: outputPath,
});
await bundle.close();
}
async function compilerStyleDir(codePath, outputDir) {
fse.copySync(codePath, outputDir);
const jsIndexPath = path.join(codePath, 'index.ts');
if (fse.existsSync(jsIndexPath)) {
fse.moveSync(
path.join(outputDir, 'index.ts'),
path.join(outputDir, 'index.js'),
);
const cssEntryPath = path.join(outputDir, 'css.js');
fse.outputFileSync(
cssEntryPath,
fse.readFileSync(jsIndexPath, 'utf-8').replace(/\.less/g, '.css'),
);
}
const lessIndexPath = path.join(codePath, 'index.less');
if (fse.existsSync(lessIndexPath)) {
const cssFileName = path.join(outputDir, 'index.css');
compilerCss(lessIndexPath, cssFileName);
}
}
export { compilerStyleDir, compilerCss };
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。