I am trying to integrate a component library in an angular2/webpack/typescript project.
The library is already transpiled to javascript, however when it is loaded, it looks like webpack is looking for the .ts files instead. Here is the webpack configuration I am using:
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})
]
};
I am running the application in the webpack dev server. Here is the error message:
./~/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
I was able to solve this error by updating the webpack config to exclude sourcemaps from primeng:
module.exports = {
....
module: {
preLoaders: [
...
{
test: /\.js$/,
loader: 'source-map-loader',
exclude: [
helpers.root('node_modules/primeng')
]
}
]
...
}
...
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With