9 Star 67 Fork 12

WeBank/fes-design

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
compilerCss.js 1.62 KB
一键复制 编辑 原始数据 按行查看 历史
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 };
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/WeBank/fes-design.git
git@gitee.com:WeBank/fes-design.git
WeBank
fes-design
fes-design
main

搜索帮助