赞
踩
使用create-react-app搭建React开发环境后,添加config-overrides.js文件,并修改package.json中对应命令后,执行
npm start
- // config-overrides.js
- var path = require('path')
- const rewireWebpackBundleAnalyzer = require('react-app-rewire-webpack-bundle-analyzer')
- const { injectBabelPlugin } = require('react-app-rewired') // 安装babel-plugin-import插件(按需加载组件代码及样式的babel插件)
- const rewireLess = require('react-app-rewire-less')
- const theme = require('./theme')
-
- module.exports = function override(config, env) {
- config.resolve.alias['@Components'] = resolve('src/components')
- config.resolve.alias['@Page'] = resolve('src/page')
- config.resolve.alias['@Services'] = resolve('src/services')
- config.resolve.alias['@Store'] = resolve('src/store')
- config.resolve.alias['@Utils'] = resolve('src/utils')
-
- // 自定义主题
- config = injectBabelPlugin(
- ['import', { libraryName: 'antd', libraryDirectory: 'es', style: true }], // change importing css to less
- config
- )
-
- config = rewireLess.withLoaderOptions({
- modifyVars:theme,
- javascriptEnabled:true
- })(config,env)
-
- return config
- }
- // package.json
- ...
- "scripts": {
- "start": "react-app-rewired --max_old_space_size=4096 --optimize_for_size start",
- "build": "cross-env NODE_ENV=production && react-app-rewired --max_old_space_size=4096 build",
- "lint": "eslint --fix src && prettier --write \"src/**/*.js\"",
- "test": "react-app-rewired test --env=jsdom"
- },
- ...
发报Erroe:Cannot find module 'react-scripts/package.json':
缺少react-scripts插件
安装react-scripts插件
npm install --save react-scripts
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。