使用的 配置合并工具 @craco/craco
react 脚手架 创建 create-react-app filename --template typescript
想要的效果
想要改变入口文件的路径 想把入口文件放到别的文件夹里面
配置
const path = require('path')
const CracoLessPlugin = require('craco-less')
const resolve = (dir) => path.resolve(__dirname, dir)
console.log('==', resolve('src/react_index/index.tsx'))
module.exports = {
plugins: [
{
plugin: CracoLessPlugin,
options: {
lessLoaderOptions: {
lessOptions: {
javascriptEnabled: true
}
}
}
}
],
webpack: {
configure: (webpackConfig, { env, paths }) => {
// 设置项目的上下文目录
// 设置静态资源公共路径
// webpackConfig.entry = resolve('src') + '\\react_index\\index.tsx'
webpackConfig.entry = resolve('src/react_index/index.tsx')
// console.log(webpackConfig)
return webpackConfig
},
// configure: { entry: './src/react_index/index.tsx' },
alias: {
'@': resolve('src')
}
}
}
这个入口可以通过配置文件进行更改的。