chore: the babel of bundler should read the targets config

This commit is contained in:
kkxxkk2019 2023-07-07 14:18:21 +08:00 committed by Weixing Zhang
parent 3645d0107f
commit 5ac0d6ff91
4 changed files with 17 additions and 6 deletions

View File

@ -11,7 +11,7 @@
],
"scripts": {
"rollup": "npm run build",
"build": "npm run clear && rollup -c --configPlugin typescript --bundleConfigAsCjs",
"build": "npm run clear && rollup -c --configPlugin typescript",
"clear": "rimraf lib"
},
"keywords": [

View File

@ -17,7 +17,9 @@ let options = defineConfig([
],
plugins: [
resolve(),
commonjs(),
commonjs({
include: './src/vchart/index.js'
}),
babel({
presets: [['@babel/preset-env']],
babelHelpers: 'bundled'

View File

@ -1,10 +1,15 @@
import type { PluginItem } from '@babel/core';
import type { PluginItem, TransformOptions } from '@babel/core';
export type BabelPlugins = {
presets: PluginItem[];
plugins: PluginItem[];
};
export function getBabelPlugins(packageName: string): BabelPlugins {
export function getBabelPlugins(
packageName: string,
options?: {
envOptions?: TransformOptions;
}
): BabelPlugins {
const plugins = [
require.resolve('@babel/plugin-proposal-export-default-from'),
require.resolve('@babel/plugin-proposal-class-properties'),
@ -21,7 +26,7 @@ export function getBabelPlugins(packageName: string): BabelPlugins {
const presets = [
require.resolve('@babel/preset-react'),
require.resolve('@babel/preset-env'),
[require.resolve('@babel/preset-env'), { targets: 'defaults and not IE 11', ...options?.envOptions }],
require.resolve('@babel/preset-typescript')
];

View File

@ -16,7 +16,11 @@ function packageNameToPath(name: string) {
return name.replace('@', '').replace('/', '_');
}
export async function buildUmd(config: Config, projectRoot: string, rawPackageJson: RawPackageJson, minify: boolean) {
const babelPlugins = getBabelPlugins(rawPackageJson.name);
const babelPlugins = getBabelPlugins(rawPackageJson.name, {
envOptions: {
targets: config.targets
}
});
const entry = path.resolve(
projectRoot,
config.sourceDir,