我无法让@rollup/plugin-typescript 与@rollup/plugin-babel 一起工作,而且TS 代码生成的JS 没有被Babel 翻译
我寻找相关问题的解决方案,但它们似乎不起作用(babel 7 not transpiling when used in rollup with typescript plugin)
下面是我的汇总配置
import { terser } from "rollup-plugin-terser";
import pluginTypescript from "@rollup/plugin-typescript";
import pluginCommonjs from "@rollup/plugin-commonjs";
import pluginNodeResolve from "@rollup/plugin-node-resolve";
import { babel } from "@rollup/plugin-babel";
import * as path from "path";
import pkg from "./package.json";
const moduleName = pkg.name.replace(/^@.*\//, "");
const inputFileName = "src/main.ts";
const author = pkg.author;
const banner = `
/**
* @license
* author: ${author}
* ${moduleName}.js v${pkg.version}
* Released under the ${pkg.license} license.
*/
`;
export default [
{
input: inputFileName,
output: [
{
name: moduleName,
file: pkg.browser,
format: "iife",
//sourcemap: "inline",
banner,
},
{
name: moduleName,
file: pkg.browser.replace(".js", ".min.js"),
format: "iife",
sourcemap: "inline",
banner,
plugins: [terser()],
},
],
plugins: [
pluginTypescript(),
pluginCommonjs({
extensions: [".js", ".ts"],
}),
babel({
extensions: [".ts"],
include: path.resolve("src", "**", "*.ts"),
babelHelpers: "bundled",
configFile: path.resolve(__dirname, ".babelrc.js"),
}),
pluginNodeResolve({
browser: true,
}),//
],
}
];
这是我的 Babel 配置
{
"presets": [
[
"@babel/env",
{
"modules": false,
"targets": {
"browsers": "> 1%, last 2 versions, ie > 11"
}
}
]
],
"plugins": [
[
"@babel/plugin-proposal-class-properties"
],
[
"@babel/plugin-transform-runtime",
{
"absoluteRuntime": false,
"corejs": 3,
"helpers": true,
"regenerator": true,
"version": "^7.13.17"
}
]
]
}
我使用的汇总和相关版本
"devDependencies": {
"@babel/cli": "^7.13.16",
"@babel/core": "^7.13.16",
"@babel/helpers": "^7.13.17",
"@babel/plugin-transform-runtime": "^7.13.15",
"@babel/preset-env": "^7.13.15",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^18.0.0",
"@rollup/plugin-node-resolve": "^11.2.1",
"@rollup/plugin-typescript": "^8.2.1",
"@types/jest": "^26.0.22",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
"eslint": "^7.24.0",
"jest": "^26.6.3",
"rollup": "^2.45.2",
"rollup-plugin-terser": "^7.0.2",
"ts-jest": "^26.5.5",
"typescript": "^4.2.4"
},
"dependencies": {
"@amipei/cookie": "0.0.2",
"@babel/runtime": "^7.13.17",
"@babel/runtime-corejs3": "^7.13.17",
"tslib": "^2.2.0"
}
我哪里做错了?请回答我。 Rollup 已经折磨我好几天了