$ cnpm install @uyun/everest-scripts
该仓库 fork 了 Create React App.中的
react-scripts
package
为适配优云 web 开发,本项目在react-scripts
2.0 的基础上做了 3 件事
@uyun/less-plugin-themes
配合换肤使用./.everestrc.js
合并到默认 webpak config./webpack.config.js
合并到默认 webpak configmodule.exports = {
//配置多入库
entryChunk: {
index: './src/entry/index.js',
config: './src/entry/config.js'
},
// 同 webpack externals
externals: {
jquery: 'jQuery'
},
//配置别名,同 webpack alias
alias: {
Utils: './src/utils'
}
};
若.everest.js
还不满足需求,则可再跟目录添加./webpack.config.js
,该文件通过webpack-merge合并到 react-script 提供的 webpack config 中。
一般情况下无需用到该方法,比如想分析 js 包文件可以使用 Webpack Bundle Analyzer
# NPM
npm install --save-dev webpack-bundle-analyzer
# Yarn
yarn add -D webpack-bundle-analyzer
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
module.exports = {
plugins: [
new BundleAnalyzerPlugin()
]
}
package.json 中的 homePage 参数
"homepage": ".",
比如配置所有非静态资源都代理到 http://newprod.dev.cn
"proxy": "http://newprod.dev.cn",
src/setupProxy.js
文件const proxy = require('http-proxy-middleware');
module.exports = function(app) {
app.use(proxy(['/tenant', '/automation'], { target:'http://newprod.dev.cn' }));
app.use(proxy(['/api/v3'], { target: 'http://newprod.dev.cn/cmdb' }));
};
你可以通过在 shell 中设置环境变量或使用 .env 来调整各种开发和生产设置。跟多配置请参考 create-react-app 高级配置
自定义环境变量须以 REACTAPP开头
<title>%REACT_APP_WEBSITE_NAME%</title>
左侧的文件比右侧的文件具有更高的优先级
. npm start: .env.development.local, .env.development, .env.local, .env
. npm run build: .env.production.local,.env.production, .env.local, .env
. npm test: .env.test.local, .env.test, .env (note .env.local is missing)
Copyright 2013 - present © cnpmjs.org