createMainFile 方法
实现思路:
生成项目的
main.jsx
文件由于原始项目引用了
_global.scss
_overhide.scss
,可能是由于 全局颜色变量等原因 和 样式覆盖 的原因,公共组件平台需要和原始项目保持一致,所以这里也导入了这两个 scss 文件
实现代码
点击 展开/收起 jsx 代码
import fs from 'fs';
import path from 'path';
function createMainFile() {
const indexFilePath = path.join(
process.cwd(),
'components-page',
'src',
'main.jsx',
);
const indexContent = `
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import './_global.scss';
import './_overhide.scss';
ReactDOM.render(<App />, document.getElementById('root'));
`;
if (!fs.existsSync(path.dirname(indexFilePath))) {
fs.mkdirSync(path.dirname(indexFilePath), { recursive: true });
}
fs.writeFileSync(indexFilePath, indexContent.trim());
console.log('------------------------------------------------------------');
console.log(`main.jsx 已经创建,请查看:${indexFilePath}`);
}
export default createMainFile;