我有一个Angular1.6应用程序,它使用Webpack捆绑和Karma进行单元测试。我的单元测试当前失败,出现以下错误:
ERROR in ./src/app/core/nav.template.html
Module not found: Error: Can't resolve './\"/img/avatars/avatar10.jpg\"' in '/home/brian/Projects/frontend/src/app/core'
@ ./src/app/core/nav.template.html 1:624-676
@ ./src/app/core/nav.component.js
@ ./src/app \.js$
@ ./webpack.karma.context.js
我认为这意味着测试无法“读取”JPG文件。当我浏览页面时,我可以正确地看到图像,所以我在那里正确设置它,但不是在我的因果配置中。以下是我webpack.conf
的相关部分:
module.exports = {
module: {
. . .
rules: [
{
test: /\.(jpe?g|png|gif|svg)$/i,
loaders: [
'file-loader?hash=sha512&digest=hex&name=[hash].[ext]',
'image-webpack-loader?bypassOnDebug&optimizationLevel=7&interlaced=false'
]
}
]
}
};
我的karma.conf
module.exports = function(config) {
config.set({
basePath: '',
frameworks: [
'jasmine',
'es6-shim'
],
files: [
'webpack.karma.context.js',
'node_modules/jquery/dist/jquery.js'
],
exclude: [],
preprocessors: {
'webpack.karma.context.js': ['webpack', 'sourcemap']
},
webpackMiddleware: {
stats: 'errors-only'
},
webpack: {
devtool: 'inline-source-map',
module: {
rules: [
{
test: /\.(jpe?g)$/i,
loaders: [
'file-loader?hash=sha512&digest=hex&name=[hash].[ext]',
'image-webpack-loader?bypassOnDebug&optimizationLevel=7&interlaced=false'
]
}
]
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
'window.$': 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
moment: 'moment',
jstree: 'jstree'
})
]
}
});
};