Webpack Angular2无法从窗口小部件库中找到.ts文件

时间:2016-03-20 08:54:46

标签: angular webpack

我正在尝试在angular2 / webpack / typescript项目中集成组件库。

该库已经被转换为javascript,但是当它被加载时,看起来webpack正在寻找.ts文件。 这是我正在使用的webpack配置:

module.exports = {
  ......
  entry: {

    'polyfills': './src/polyfills.ts',
    'vendor': './src/vendor.ts',
    'main': './src/main.ts'
  },
  resolve: {
    extensions: ['', '.ts', '.js']
  },
  .....
  module: {
    preLoaders: [
        {test: /\.js$/, loader: 'source-map-loader', exclude: [helpers.root('node_modules/rxjs')]}
    ],
    loaders: [
      {test: /\.ts$/, loader: 'awesome-typescript-loader', exclude: [/\.(spec|e2e)\.ts$/]} ,
      {test: /\.json$/, loader: 'json-loader'},
      {test: /\.css$/, loader: 'raw-loader'},
      {test: /\.html$/, loader: 'raw-loader', exclude: [helpers.root('src/index.html')]}
    ]
  },

  plugins: [
    new ForkCheckerPlugin(),
    new webpack.optimize.OccurenceOrderPlugin(true),
    new webpack.optimize.CommonsChunkPlugin({name: ['main', 'vendor', 'polyfills'], minChunks: Infinity}),
    new CopyWebpackPlugin([{from: 'src/assets', to: 'assets'}]),
    new HtmlWebpackPlugin({template: 'src/index.html', chunksSortMode: 'none'}),
    new webpack.DefinePlugin({'ENV': JSON.stringify(METADATA.ENV), 'HMR': HMR})
  ]  
};

我正在webpack dev服务器上运行该应用程序。 以下是错误消息:

./~/primeng/components/selectbutton/selectbutton.js
Cannot find source file 'selectbutton.ts': Error: Cannot resolve 'file' or 'directory' ./selectbutton.ts in C:\data\14-03\angular2-webpack-starter\node_modules\primeng\components\selectbutton

1 个答案:

答案 0 :(得分:11)

我能够通过更新webpack配置来解决此错误,以从primeng中排除源映射:

module.exports = {
  ....
  module: {
    preLoaders: [
      ...
      {
        test: /\.js$/,
        loader: 'source-map-loader',
        exclude: [
          helpers.root('node_modules/primeng')
        ]
      }
    ]
    ...
  }
  ...
};