Skip to content

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
merged 51 commits into from
Aug 27, 2021
Merged

builder v2 #131

merged 51 commits into from
Aug 27, 2021

Conversation

nighca
Copy link
Collaborator

@nighca nighca commented May 10, 2021

变更内容

1. 依赖升级

主要包括:

  • webpack 4.x -> 5.x(以及相关的 webpack plugin & loader 等)
  • 内置的 Typescript 3.4.x -> 4.1.x(注意这里指的不是 builder 编译自己使用的 Typescript,而是 builder 对 TS 项目进行构建使用的 Typescript)

2. transform 调整

  • 移除对 transform stylussvg-spriteflow & vue 的支持
  • 引入新的 transform svgr;关于 svgr,详见 https://react-svgr.com/

3. 配置行为调整

4. 其他

升级文档

项目升级关注以下几个变更即可:

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:

原先:

import icon from './icon.svg'

<SVGIcon src={icon} className={...} />

现在:

import Icon from './icon.svg'

<Icon className={...} />

4. build-config extends

如果原本 build-config.jsonextends: "qiniu/portal",需要调整为 extends: "@qiniu/build-config/portal"

5. optimization.extractVendor

如果项目配置了 optimization.extractVendor,需要调整使用姿势,详见 nighca#2

6. 对 css module 的引入

如果项目中开启了 CSS module,并通过

import * as style from 'foo.m.less'

在 JavaScript / Typescript 代码中引入,现在需要调整为

import style from 'foo.m.less'

升级参考

Fusion Portal 的 builder 升级 PR https://github.com/qbox/portal-fusion/pull/693

@nighca nighca mentioned this pull request May 10, 2021
liaoyu and others added 9 commits May 17, 2021 16:35
* add analyz

* add analyze command

* fix self review

* fix review
* debug build-sample.sh

* debug samples for CI

* update browserslist db

* update circle ci node versions
* 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
@nighca nighca closed this Aug 6, 2021
@nighca nighca reopened this Aug 6, 2021
@nighca nighca mentioned this pull request Aug 11, 2021
nighca added 8 commits August 12, 2021 09:33
* support npm package as extends target

* update build-config doc

* support file in npm package
* remove sourcemap from TODO

* update build script

* specify webpack config target

* update comment for getServeConfig

* add repository info in package.json

* update command prepare & test

* optimization.compressImage

* update samples
@nighca nighca merged commit 179a1fe into master Aug 27, 2021
@liaoyu liaoyu deleted the v2 branch July 25, 2023 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants