Skip to content
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

[WIP] build: 构建产物调整, 使用 Bundless 的方式输出, 支持 tree shaking [BREAK CHANGE] #2754

Open
wants to merge 12 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ module.exports = {
tabWidth: 2,
trailingComma: 'all',
printWidth: 80,
arrowParens: 'always',
proseWrap: 'never',
htmlWhitespaceSensitivity: 'css',
embeddedLanguageFormatting: 'auto',
singleAttributePerLine: false,
bracketSpacing: true,
overrides: [
{ files: '.eslintrc', options: { parser: 'json' } },
{ files: '.prettierrc', options: { parser: 'json' } },
Expand All @@ -57,7 +62,7 @@ module.exports = {
],
'import/no-duplicates': [2, { considerQueryString: true }],
'import/no-deprecated': 1,
'import/no-cycle': 1,
'import/no-cycle': 2,
'import/order': [
2,
{
Expand Down
37 changes: 37 additions & 0 deletions .fatherrc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { defineConfig } from 'father';
import path from 'path';

export default (name: string) => {
const alias = {
'@antv/s2-shared': path.resolve(process.cwd(), './src/shared'),
Copy link
Member Author

@lijinke666 lijinke666 Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

增加一个 shared 的子目录, 将 s2-shared 跳过 Bundless 的处理, 直接编译

image

};

return defineConfig({
sourcemap: true,
alias,
define: {
'process.env.NODE_ENV': JSON.stringify('production'),
},
esm: {
output: 'esm',
},
cjs: {
output: 'lib',
},
umd: {
alias: {
'@antv/s2': path.resolve(__dirname, 'packages/s2-core'),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

避免 bundle 时找不到 antv/s2 的问题

},
name,
output: 'dist',
externals: {
'@antv/s2': 'S2',
antd: 'antd',
react: 'React',
'react-dom': 'ReactDOM',
vue: 'Vue',
'ant-design-vue': 'AntDesignVue',
},
},
});
};
3 changes: 3 additions & 0 deletions .github/workflows/auto-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ jobs:
- name: Install dependencies
run: pnpm bootstrap:ci

- name: Build doctor
run: pnpm build:doctor

- name: Build
run: pnpm build

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/compressed-size.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ jobs:
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
pattern: "./packages/{s2-core,s2-react,s2-vue}/dist/**/*.{js,css}"
build-script: "build:umd"
build-script: "build"
clean-script: "clean"
3 changes: 3 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ jobs:
- name: Lint scripts, type, style and docs
run: pnpm lint

- name: Build doctor
run: pnpm build:doctor

- name: Build
run: pnpm build

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ packages/s2-*/temp/
packages/s2-*/coverage/
packages/s2-*/stats.html

# pre bundle
packages/s2-*/src/shared

.swc
2 changes: 1 addition & 1 deletion README.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ A practical visualization library for tabular analysis.

<p>
<a href="https://www.npmjs.com/package/@antv/s2" target="_blank">
<img src="https://img.badgesize.io/https:/unpkg.com/@antv/s2@next/dist/index.min.js?label=gzip%20size&compression=gzip" alt="npm bundle size" />
<img src="https://img.badgesize.io/https:/unpkg.com/@antv/s2@next/dist/s2.min.js?label=gzip%20size&compression=gzip" alt="npm bundle size" />
</a>
<a href="https://github.com/antvis/S2/discussions" target="_blank">
<img src="https://img.shields.io/badge/discussions-on%20github-blue" alt="GitHub discussions"/>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

<p>
<a href="https://www.npmjs.com/package/@antv/s2" target="_blank">
<img src="https://img.badgesize.io/https:/unpkg.com/@antv/s2@next/dist/index.min.js?label=gzip%20size&compression=gzip" alt="npm bundle size" />
<img src="https://img.badgesize.io/https:/unpkg.com/@antv/s2@next/dist/s2.min.js?label=gzip%20size&compression=gzip" alt="npm bundle size" />
</a>
<a href="https://github.com/antvis/S2/discussions" target="_blank">
<img src="https://img.shields.io/badge/discussions-on%20github-blue" alt="GitHub discussions"/>
Expand Down
134 changes: 134 additions & 0 deletions build.config.base.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import { viteCommonjs } from '@originjs/vite-plugin-commonjs';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

和之前的配置没变, 之前这几个包打包配置都是复制的, 重复率有点高, 抽了下, 现在使用 father 打包, 用不到了 (暂时保留, 以免有啥问题)

import peerDepsExternal from 'rollup-plugin-peer-deps-external';
import { visualizer } from 'rollup-plugin-visualizer';

export const getBaseConfig = () => {
const entry = './src/index.ts';

const OUT_DIR_NAME_MAP = {
es: 'esm',
cjs: 'lib',
umd: 'dist',
};

const format = process.env.FORMAT;
const isAnalysisMode = process.env.ANALYSIS;
const isDevMode = process.env.PLAYGROUND;
const outDir = OUT_DIR_NAME_MAP[format];
const isUMD = format === 'umd';
const isESM = format === 'es';

const define = {
'process.env.NODE_ENV': JSON.stringify(
isDevMode ? 'development' : 'production',
),
};

const output = {
dir: outDir,
entryFileNames: `[name]${isUMD ? '.min' : ''}.js`,
assetFileNames: `[name]${isUMD ? '.min' : ''}.[ext]`,
globals: {
vue: 'Vue',
react: 'React',
'react-dom': 'ReactDOM',
'@antv/s2': 'S2',
'@antv/s2-react': 'S2React',
lodash: '_',
},
};

const resolve = {
mainFields: ['src', 'module', 'main'],
alias: [
{
find: 'lodash',
replacement: 'lodash-es',
},
],
};

if (isDevMode) {
// 防止开发模式下直接加载 s2-core 中的主题 less
resolve.alias.push({
find: /^(.*)\/theme\/(.*)\.less$/,
replacement: '$1/theme/$2.less?inline',
});
}

const getViteConfig = (
{ port, libName, plugins } = { port: 3001, plugins: [] },
) => {
return {
server: {
port,
hmr: true,
},

resolve,

define: {
'process.env.NODE_ENV': JSON.stringify(
isDevMode ? 'development' : 'production',
),
},

plugins: [
peerDepsExternal(),
!isDevMode && viteCommonjs(),
isAnalysisMode &&
visualizer({
open: true,
gzipSize: true,
brotliSize: true,
}),
...plugins,
].filter(Boolean),

css: {
preprocessorOptions: {
less: {
javascriptEnabled: true,
},
},
modules: {
/**
* 样式小驼峰转化
* css: goods-list => tsx: goodsList
*/
localsConvention: 'camelCase',
},
},

build: {
target: 'es2015',
minify: isUMD ? 'esbuild' : false,
sourcemap: true,
lib: {
name: libName,
entry,
formats: [format],
},
outDir,
rollupOptions: {
output,
},
},
};
};

return {
entry,
getViteConfig,
define,
format,
resolve,
isAnalysisMode,
outDir,
output,
OUT_DIR_NAME_MAP,
isDevMode,
isUMD,
isESM,
};
};
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"url": "https://github.com/antvis/S2.git"
},
"license": "MIT",
"files": [],
"scripts": {
"preinstall": "npx only-allow pnpm",
"bootstrap": "pnpm install",
Expand Down Expand Up @@ -55,6 +56,7 @@
"build:umd": "pnpm -r --filter './packages/*' --stream build:umd",
"build:size-limit": "pnpm -r --filter './packages/*' --stream build:size-limit",
"build:size-limit-json": "pnpm -r --filter './packages/*' --stream build:size-limit-json",
"build:doctor": "father doctor",
"release": "pnpm -r --filter !@antv/s2-shared --filter !@antv/s2-site --filter !@antv/s2-react-components --workspace-concurrency=1 exec npx --no-install semantic-release",
"release:preview": "pnpm release --dry-run --no-ci",
"release:bump-version": "node ./scripts/bump-version.js",
Expand Down Expand Up @@ -149,6 +151,7 @@
"eslint-plugin-react": "^7.34.2",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-vue": "^9.17.0",
"father": "^4.4.4",
"gh-pages": "^3.2.3",
"glob": "^10.3.10",
"husky": "^8.0.3",
Expand Down
3 changes: 3 additions & 0 deletions packages/s2-core/.fatherrc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import fatherConfig from '../../.fatherrc';

export default fatherConfig('S2');
8 changes: 4 additions & 4 deletions packages/s2-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

<p>
<a href="https://www.npmjs.com/package/@antv/s2" target="_blank">
<img src="https://img.badgesize.io/https:/unpkg.com/@antv/s2@next/dist/index.min.js?label=gzip%20size&compression=gzip" alt="npm bundle size" />
<img src="https://img.badgesize.io/https:/unpkg.com/@antv/s2@next/dist/s2.min.js?label=gzip%20size&compression=gzip" alt="npm bundle size" />
</a>
<a href="https://github.com/antvis/S2/discussions" target="_blank">
<img src="https://img.shields.io/badge/discussions-on%20github-blue" alt="GitHub discussions"/>
Expand Down Expand Up @@ -73,9 +73,9 @@ S2 是 AntV 在多维交叉分析表格领域的解决方案,完全基于数
## 📦 安装

```bash
$ pnpm add @antv/s2
# yarn add @antv/s2
# npm install @antv/s2 --save
$ pnpm add @antv/s2@next
# yarn add @antv/s2@next
# npm install @antv/s2@next --save
```

## 🔨 使用
Expand Down
10 changes: 5 additions & 5 deletions packages/s2-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"dist/*"
],
"main": "lib/index.js",
"unpkg": "dist/index.min.js",
"unpkg": "dist/s2.min.js",
"module": "esm/index.js",
"types": "esm/index.d.ts",
"directories": {
Expand All @@ -41,7 +41,7 @@
"README.md"
],
"scripts": {
"build": "npm-run-all clean --parallel build:umd build:cjs build:esm build:dts",
"build": "father build",
"build:analysis": "cross-env FORMAT=esm ANALYSIS=true rollup -c rollup.config.mjs",
"build:cjs": "cross-env FORMAT=cjs rollup -c rollup.config.mjs",
"build:dts": "run-s dts:*",
Expand Down Expand Up @@ -90,12 +90,12 @@
},
"size-limit": [
{
"path": "./dist/index.min.js",
"path": "./dist/s2.min.js",
"import": "{ createComponent }",
"limit": "200 kB"
"limit": "230 kB"
},
{
"path": "./dist/style.min.css",
"path": "./dist/s2.min.css",
"limit": "5 kB"
}
],
Expand Down
Loading
Loading