[英]gulp / rollup / typescript — __decorate is not defined
I have this gulpfile.js
我有这个
gulpfile.js
import gulp from 'gulp';
import { rollup } from 'rollup';
import rollupTypescript from '@rollup/plugin-typescript'
const compileTs = async (src, dest) => {
const bundle = await rollup({
input: src,
plugins: [
rollupTypescript()
]
});
await bundle.write({
file: dest,
format: 'es',
name: 'library',
sourcemap: 'inline'
});
}
export const ts = async _ => await Promise.all([
compileTs('./src/ts/main.ts', './bin/js/bin.js')
]);
within tsconfig.json
(same directory) I have:在
tsconfig.json
(同一目录)中我有:
compilerOptions: {
"target": "ESNEXT",
"module": "ESNext",
"importHelpers": true,
"experimentalDecorators": true
}
within src/ts/main.ts
there is:在
src/ts/main.ts
中有:
const Foo = (fx: Function) => {
console.log(fx);
}
@Foo
class Bar {
}
$ npx gulp ts
creates the desired file. $ npx gulp ts
创建所需的文件。 But when I run it the console tells me:但是当我运行它时,控制台告诉我:
Uncaught ReferenceError: __decorate is not defined
Since all the helpers from tslib
are not included.因为
tslib
中的所有助手都不包括在内。
What can I do to fix that?我能做些什么来解决这个问题? I have tried to use
external: ['tslib']
, but no luck.我曾尝试使用
external: ['tslib']
,但没有运气。
BTW: Just running npx tsc
(plus the outdir set) includes __decorate
顺便说一句:只运行
npx tsc
(加上 outdir 集)包括__decorate
I've run exactly the same situation before.我以前遇到过完全相同的情况。 The issue is likely the option
importHelper
is excluded https://github.com/rollup/plugins/tree/master/packages/typescript#ignored-options .问题可能是选项
importHelper
被排除在外https://github.com/rollup/plugins/tree/master/packages/typescript#ignored-options 。
I did resolve by switching to use rollup-plugin-typescript2
which enables this option by default.我确实通过切换到使用默认启用此选项的
rollup-plugin-typescript2
来解决。
// Install `npm i -D rollup-plugin-typescript2`
import typescript from 'rollup-plugin-typescript2';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.