Gulp 未定义合并/汇总/ typescript - __装饰

dgtucam1  于 2022-12-16  发布在  Gulp
关注(0)|答案(1)|浏览(136)

我有这个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')
  ]);

tsconfig.json(相同目录)中,我有:

compilerOptions: {
  "target": "ESNEXT",
  "module": "ESNext",
  "importHelpers": true, 
  "experimentalDecorators": true
}

src/ts/main.ts中存在:

const Foo = (fx: Function) => {
  console.log(fx);
}

@Foo
class Bar {

}

$ npx gulp ts创建了所需的文件,但当我运行它时,控制台告诉我:

Uncaught ReferenceError: __decorate is not defined

因为tslib中的所有助手都不包括在内。
我能做些什么来解决这个问题呢?我试过使用external: ['tslib'],但是没有运气。

  • 顺便说一句:* 仅运行npx tsc(加上outdir集)就包括__decorate
h9vpoimq

h9vpoimq1#

我以前运行过完全相同的情况。问题可能是选项importHelper被排除了https://github.com/rollup/plugins/tree/master/packages/typescript#ignored-options。
我确实通过切换到使用默认情况下启用此选项的rollup-plugin-typescript2来解决问题。

// Install `npm i -D rollup-plugin-typescript2`
import typescript from 'rollup-plugin-typescript2';

相关问题