使用RollUp捆绑打字稿 - 无法处理编译器选项

时间:2017-04-19 17:44:16

标签: javascript typescript bundler rollupjs

我试图捆绑我的打字稿文件RollUp(https://rollupjs.org/
我使用了这个配置文件:

rollup.config.js:

import alias from 'rollup-plugin-alias';
import resolve from 'rollup-plugin-node-resolve';
import typescript from 'rollup-plugin-typescript';
import angular from 'rollup-plugin-angular';

export default {
    entry: '../main.ts',
    format: 'iife',
    dest: 'dist/bundle.es2015.js',
    sourceMap: true,
    plugins: [
        angular(),
        typescript(),
        alias({ rxjs: __dirname + '/node_modules/rxjs-es' }),
        resolve({
            jsnext: true,
            main: true,
            browser: true
        })
    ],
    external: [
        '@angular/core',
        '@angular/common',
        '@angular/compiler',
        '@angular/core',
        '@angular/http',
        '@angular/platform-browser',
        '@angular/platform-browser-dynamic',
        '@angular/router',
        '@angular/router-deprecated'
    ],
    globals: {
        '@angular/common': 'vendor._angular_common',
        '@angular/compiler': 'vendor._angular_compiler',
        '@angular/core': 'vendor._angular_core',
        '@angular/http': 'vendor._angular_http',
        '@angular/platform-browser': 'vendor._angular_platformBrowser',
        '@angular/platform-browser-dynamic': 'vendor._angular_platformBrowserDynamic',
        '@angular/router': 'vendor._angular_router',
        '@angular/forms': 'vendor._angular_forms'
    }
}

vendor.js:

import * as _angular_common from '@angular/common';
import * as _angular_compiler from '@angular/compiler';
import * as _angular_core from '@angular/core';
import * as _angular_http from '@angular/http';
import * as _angular_platformBrowser from '@angular/platform-browser';
import * as _angular_platformBrowserDynamic from '@angular/platform-browser-dynamic';
import * as _angular_router from '@angular/router';
import * as _angular_forms from '@angular/forms';

export default {
    _angular_common,
    _angular_compiler,
    _angular_core,
    _angular_http,
    _angular_platformBrowser,
    _angular_platformBrowserDynamic,
    _angular_router,
    _angular_forms
};

但我一直收到这个错误:

rollup-plugin-typescript: Argument for '--target' option must be 'ES3', 'ES5', or 'ES2015'.
rollup-plugin-typescript: Unknown compiler option 'lib'.
rollup-plugin-typescript: Couldn't process compiler options

我做错了什么? (我是新来的,所以如果我没有写一些必要的信息 - 请告诉我)

编辑:

这是我的tsconfig.json:

{
  "compilerOptions": {
    "target": "es2017",
    "module": "commonjs",
    "moduleResolution": "node",
    "outDir": ".\\Compiled-JS\\Apps\\Client",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [ "es2015", "dom" ],
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true
  }
}

2 个答案:

答案 0 :(得分:13)

您可能需要使用rollup-plugin-typescript2

Rollup-plugin-typescript似乎默认支持1.8.9,这也可能是问题的一部分。

答案 1 :(得分:2)

我找到了解决方案,而没有切换到rollup-plugin-typescript-2

要解决这个问题(请记住Denis Tsoi的答案中所述的问题),您需要做的就是通过rollup-plugin-typescript传递您自己的本地TypeScript版本,如下所示:

import ts from 'rollup-plugin-typescript';
import typescript from 'typescript'


const config = {
  plugins: [
    ts({
      typescript
    })
  ]
};

export default config;

原始解决方案可以在这里找到:

https://github.com/rollup/rollup-plugin-typescript/issues/114#issuecomment-399100699