试图在我的基于webpack的包中包含typescript

时间:2017-06-20 10:53:22

标签: typescript webpack

即使我设置了loader: 'ts'我也看到了这个错误:

 50% 4/6 build modulesModuleParseError: Module parse failed: /home/rob/git/repo/src/app/container.entry.ts Unexpected token (16:70)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (16:70)

webpack.common.js

'use strict';
var webpack = require('webpack');
var path = require('path');

module.exports = {
  entry: {
    app: [
      './src/main.ts'
    ],
    container: [
            './src/app/container.entry.ts'
    ],
    containerPrereqs: [
            'angular'
    ]
  },

  resolve: {
    root: [ path.join(__dirname, 'node_modules')],
    extensions: ['', '.ts', '.js']
  },

  module: {
    rules: [{
        test: /\.ts$/,
        loader: 'ts'
      },
      {
        test: /\.html$/,
        loader: 'html-loader'
      },
      {
        test: /\.css$/,
        loaders: ['to-string-loader', 'css-loader']
      }
    ]
  }
};

来自package.json的片段:

"dependencies": {
    "angular": "1.6.1",
    "ts-loader": "^0.8.1",
    "typescript": "2.3.3",
    "css-loader": "^0.28.4",
    "html-loader": "^0.4.3",
    "to-string-loader": "^1.1.5",
    "webpack": "^1.12.14"
},

1 个答案:

答案 0 :(得分:1)

根据您需要使用的ts-loader README

{
    test: /\.ts$/,
    loader: 'ts-loader'
},

您似乎错过了“ -loader ”部分

去过那里,完成了:)