1 Star 1 Fork 0

fudashuai007/redux

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
tsup.config.ts 1.81 KB
一键复制 编辑 原始数据 按行查看 历史
import { defineConfig, Options } from 'tsup'
import * as babel from '@babel/core'
import { Plugin } from 'esbuild'
import { getBuildExtensions } from 'esbuild-extra'
import fs from 'fs'
// Extract error strings, replace them with error codes, and write messages to a file
const mangleErrorsTransform: Plugin = {
name: 'mangle-errors-plugin',
setup(build) {
const { onTransform } = getBuildExtensions(build, 'mangle-errors-plugin')
onTransform({ loaders: ['ts', 'tsx'] }, async args => {
const res = babel.transformSync(args.code, {
parserOpts: {
plugins: ['typescript']
},
plugins: [['./scripts/mangleErrors.cjs', { minify: false }]]
})!
return {
code: res.code!,
map: res.map!
}
})
}
}
export default defineConfig(options => {
const commonOptions: Partial<Options> = {
entry: {
redux: 'src/index.ts'
},
esbuildPlugins: [mangleErrorsTransform],
sourcemap: true,
...options
}
return [
// Standard ESM, embedded `process.env.NODE_ENV` checks
{
...commonOptions,
format: ['esm'],
outExtension: () => ({ js: '.mjs' }),
dts: true,
clean: true,
onSuccess() {
// Support Webpack 4 by pointing `"module"` to a file with a `.js` extension
fs.copyFileSync('dist/redux.mjs', 'dist/redux.legacy-esm.js')
}
},
// Browser-ready ESM, production + minified
{
...commonOptions,
entry: {
'redux.browser': 'src/index.ts'
},
define: {
'process.env.NODE_ENV': JSON.stringify('production')
},
format: ['esm'],
outExtension: () => ({ js: '.mjs' }),
minify: true
},
{
...commonOptions,
format: 'cjs',
outDir: './dist/cjs/',
outExtension: () => ({ js: '.cjs' })
}
]
})
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/fudashuai007/redux.git
git@gitee.com:fudashuai007/redux.git
fudashuai007
redux
redux
master

搜索帮助