gpt4 book ai didi

angular - Webpack Angular2 无法从小部件库中找到 .ts 文件

转载 作者:太空狗 更新时间:2023-10-29 17:43:33 26 4
gpt4 key购买 nike

我正在尝试将组件库集成到 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 开发服务器中运行应用程序。这是错误消息:

./~/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

最佳答案

我能够通过更新 webpack 配置以从 primeng 中排除 sourcemaps 来解决这个错误:

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

关于angular - Webpack Angular2 无法从小部件库中找到 .ts 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36111827/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com