-
Notifications
You must be signed in to change notification settings - Fork 32
builder v2 #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
builder v2 #131
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* extractCommon & extractVendor * default vendors * fix extractVendor * remove build-config.md * fix review * fix extractVendor
* open esModuleInterop * target to es6
* adjust default target browsers * use svgr for qiniu portal
Closed
* add analyz * add analyze command * fix self review * fix review
* watch build config file change * typo * watch for tsconfig.json * remove useless code * comment * typo
* fix css hot reload * optimize env logic
* use typescript 4.1.x * beta.9
* process source map * beta.11 * upgrade ts-loader * typo * use cheap-module-source-map instead of eval-source-map * move webpack-related fns to utils/webpack
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
变更内容
1. 依赖升级
主要包括:
2. transform 调整
stylus
、svg-sprite
、flow
&vue
的支持svgr
;关于 svgr,详见 https://react-svgr.com/3. 配置行为调整
file
逻辑处理;对于 react 项目,js/jsx/ts/tsx 中引入的 svg 资源默认通过 svgr 处理*.m.css
&*.m.less
文件默认启用 CSS Moduleslast 2 versions
调整为defaults
,具体区别见 https://github.com/browserslist/browserslistextends
目标,详见 build-config 支持 npm package 作为extends
目标 #140vue
qiniu/portal
,可以使用@qiniu/build-config/portal
代替optimization.extractVendor
不再支持指定 entry name,而是指定固定依赖的包名数组,例如["react", "react-dom"]
,详情见 支持 extractCommon & extractVendor nighca/builder#2optimization.highQualitySourceMap
,可开启高质量 source map,以提供更好的开发调试体验,详见 source map 行为优化 #1394. 其他
analyze
命令以分析 bundle 依赖,详见 新增 analyze 命令以分析 bundle 依赖 #132upload
命令时的上传行为,详见 上传行为优化 #128serve
命令时会监测配置文件变更并自动重启,详见 serve 时监测配置文件变更 #133升级文档
项目升级关注以下几个变更即可:
1. Typescript & Webpack 升级
对于 TS 项目,项目中依赖的 Typescript 版本也需要对应升级到 4.1.x,代码本身可能需要做对应调整
项目本身不需要引入 Webpack 作为依赖,不过需要注意,Webpack 5.x 不再默认将对 Node.js 运行环境的 polyfill 打包进 bundle(详见 https://webpack.js.org/blog/2020-10-10-webpack-5-release/#automatic-nodejs-polyfills-removed );如果项目代码依赖或间接依赖了 Node.js 环境才有的 module 或全局变量,可能会出现运行时错误。建议的处理方式是自己引入对应的 polyfill
一个例子是:若项目引入了
whatwg-url
,后者依赖 node 环境才会提供的Buffer
,在新 builder 构建后会出错2. React 升级
对于 React 项目,builder 使用 fast refresh 来优化组件的开发体验;fast refresh 依赖 React 17.x,因此这里需要将项目中的 react(及 react-dom 等相关依赖)的版本升级到 17.x
此外,原项目中的
react-hot-loader
依赖可以被干掉,代码中react-hot-loader
相关代码也都可以移除3. 对 svg 的引入
对于 react 项目,原本在 js/jsx/ts/tsx 文件中对 svg 文件进行引入会得到 svg-sprite 逻辑处理后的 id(一个字符串值),现在会得到一个 React component:
原先:
现在:
4. build-config
extends
如果原本
build-config.json
中extends: "qiniu/portal"
,需要调整为extends: "@qiniu/build-config/portal"
5.
optimization.extractVendor
如果项目配置了
optimization.extractVendor
,需要调整使用姿势,详见 nighca#26. 对 css module 的引入
如果项目中开启了 CSS module,并通过
在 JavaScript / Typescript 代码中引入,现在需要调整为
升级参考
Fusion Portal 的 builder 升级 PR https://github.com/qbox/portal-fusion/pull/693