chore: change bundler config

This commit is contained in:
Rui-Sun 2023-07-07 11:57:03 +08:00
parent 35441b6ad6
commit 78d8ba8e81
3 changed files with 7 additions and 46 deletions

View File

@ -4,10 +4,9 @@ export type BabelPlugins = {
presets: PluginItem[];
plugins: PluginItem[];
};
export function getBabelPlugins(packageName: string, es5 = true): BabelPlugins {
export function getBabelPlugins(packageName: string): BabelPlugins {
const plugins = [
require.resolve('@babel/plugin-proposal-export-default-from'),
// require.resolve('@babel/plugin-transform-runtime'),
require.resolve('@babel/plugin-proposal-class-properties'),
[
require.resolve('babel-plugin-import'),
@ -20,20 +19,12 @@ export function getBabelPlugins(packageName: string, es5 = true): BabelPlugins {
]
];
if (es5) {
plugins.push(require.resolve('@babel/plugin-transform-runtime'));
}
const presets = [
require.resolve('@babel/preset-react'),
// require.resolve('@babel/preset-env'),
require.resolve('@babel/preset-typescript')
require.resolve('@babel/preset-typescript'),
[require.resolve('@babel/preset-env'), { targets: 'defaults and not IE 11' }]
];
if (es5) {
presets.push(require.resolve('@babel/preset-env'));
}
return {
presets,
plugins

View File

@ -33,8 +33,7 @@ export function getRollupOptions(
entry: string,
rawPackageJson: RawPackageJson,
babelPlugins: BabelPlugins,
config: Config,
es5 = true
config: Config
): RollupOptions {
return {
input: entry,
@ -43,7 +42,7 @@ export function getRollupOptions(
plugins: [
resolve(),
commonjs(),
babel({ ...babelPlugins, babelHelpers: es5 ? 'runtime' : 'bundled' }),
babel({ ...babelPlugins, babelHelpers: 'bundled' }),
replace({ ...config.envs, preventAssignment: true }),
typescript({
tsconfig: path.resolve(projectRoot, config.tsconfig),

View File

@ -32,8 +32,8 @@ export async function buildUmd(config: Config, projectRoot: string, rawPackageJs
format: 'umd',
name: config.name || packageNameToPath(rawPackageJson.name),
file: minify
? `${dest}/${config.umdOutputFilename || packageNameToPath(rawPackageJson.name)}.es5.min.js`
: `${dest}/${config.umdOutputFilename || packageNameToPath(rawPackageJson.name)}.es5.js`,
? `${dest}/${config.umdOutputFilename || packageNameToPath(rawPackageJson.name)}.min.js`
: `${dest}/${config.umdOutputFilename || packageNameToPath(rawPackageJson.name)}.js`,
exports: 'named',
globals: { react: 'React', ...config.globals }
}
@ -42,33 +42,4 @@ export async function buildUmd(config: Config, projectRoot: string, rawPackageJs
if (bundle) {
await bundle.close();
}
// build es6
const babelPluginsEs6 = getBabelPlugins(rawPackageJson.name, false);
const rollupOptionsEs6 = getRollupOptions(
projectRoot,
entry,
rawPackageJson,
babelPluginsEs6,
{ ...config, minify },
false
);
DebugConfig('RollupOptionsEs6', JSON.stringify(rollupOptionsEs6));
const bundleEs6 = await rollup(rollupOptionsEs6);
await generateOutputs(bundleEs6, [
{
format: 'umd',
name: config.name || packageNameToPath(rawPackageJson.name),
file: minify
? `${dest}/${config.umdOutputFilename || packageNameToPath(rawPackageJson.name)}.min.js`
: `${dest}/${config.umdOutputFilename || packageNameToPath(rawPackageJson.name)}.js`,
exports: 'named',
globals: { react: 'React' }
}
]);
if (bundleEs6) {
await bundleEs6.close();
}
}