-
Notifications
You must be signed in to change notification settings - Fork 199
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
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
af0ea45
build: esm 模块按目录打包, 使用 bundless 的方式支持 tree shaking
lijinke666 bb31640
build: 修复打包尺寸校验失败
lijinke666 72b91b2
build: 自动打开分析工具
lijinke666 3f8687e
Merge remote-tracking branch 'origin/next' into build-esm-bundless
lijinke666 9a5820b
refactor: 解决所有循环依赖问题
lijinke666 338e40f
build: 使用 bundless
lijinke666 deb3514
docs: 新增变更文档
lijinke666 2f03e1a
chore: 修复 size-limit 错误
lijinke666 4e02f6c
chore: 移除别名配置
lijinke666 d2197f7
build: 预编译 s2-shared, 解决 bundless 的问题
lijinke666 b565b05
Merge remote-tracking branch 'origin/next' into build-esm-bundless
lijinke666 fe6b0ce
build: 修复 react-components 和 vue 打包失败
lijinke666 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
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'), | ||
}; | ||
|
||
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'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 避免 bundle 时找不到 |
||
}, | ||
name, | ||
output: 'dist', | ||
externals: { | ||
'@antv/s2': 'S2', | ||
antd: 'antd', | ||
react: 'React', | ||
'react-dom': 'ReactDOM', | ||
vue: 'Vue', | ||
'ant-design-vue': 'AntDesignVue', | ||
}, | ||
}, | ||
}); | ||
}; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,7 @@ packages/s2-*/temp/ | |
packages/s2-*/coverage/ | ||
packages/s2-*/stats.html | ||
|
||
# pre bundle | ||
packages/s2-*/src/shared | ||
|
||
.swc |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import { viteCommonjs } from '@originjs/vite-plugin-commonjs'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
}; | ||
}; |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import fatherConfig from '../../.fatherrc'; | ||
|
||
export default fatherConfig('S2'); |
This file contains 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
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
增加一个
shared
的子目录, 将s2-shared
跳过 Bundless 的处理, 直接编译