Webpack模块构建失败:某些ts语法

时间:2017-05-16 05:39:03

标签: angularjs typescript webpack

我正在使用webpack,angularjs和typescript构建一个小应用程序。我的项目正在构建和运行,直到我使用某些es6功能,然后它就会中断。我检查了一些不同的问题并调整了我的文件,但我没有取得任何成功。它不允许我定义类属性,“声明var foo;”或其他一些奇怪的角落案例。萨斯正在建设中。

webpack.config.ts

    let path = require('path');
    module.exports = {
      cache: true,
      entry: {
        main: './client/app/app.module.ts'
      },
      output: {
        path: __dirname + '/../client/dist/',
        filename: '[name].js',
        chunkFilename: '[chunkhash].js'
      },
      module: {
        loaders: [{
          test: /\.ts(x?)$/,
          exclude: /node_modules/,
          loaders: ['ts-loader']
        },
        {
        test: /\.scss$/,
        loaders: ['style-loader', 'css-loader', 'sass-loader']
        }]
      },
      plugins: [
      ],
      devtool: "source-map",
      resolve: {
        // Add `.ts` and `.tsx` as a resolvable extension.
        extensions: ['.ts', '.tsx']
      },
    };

tsconfig.json

            {
                "compilerOptions": {
                    "target": "es5",
                    "module": "commonjs",
                    "sourceMap": false,
                    "noImplicitAny": false,
                    "watch": true
                }
            }

layout.controller.ts

    import * as angular from 'angular';

    class LayoutController{
      private test:number;
      constructor() {

      }
    }

    LayoutController.$inject = [
    ];

    export default LayoutController;

错误

    [0] ERROR in ./client/app/layout/layout.controller.ts
    [0] Module build failed: SyntaxError:C:/Users/user/Documents/Projects/Portfolio/client/app/layout/layout.controller.ts: Unexpected token (4:10)
    [0]
    [0]   2 |
    [0]   3 | class LayoutController{
    [0] > 4 |   private test:number;
    [0]     |           ^
    [0]   5 |   constructor() {
    [0]   6 |
    [0]   7 |   }
    [0]
    [0]  @ ./client/app/layout/layout.module.ts 11:14-44
    [0]  @ ./client/app/app.module.ts

0 个答案:

没有答案