1
我很難在文件加載器中使用文件加載器進行測試。我收到404錯誤,並且在Chrome中嘗試調試時,這些文件不會顯示在開發工具下的sources選項卡中。文件加載器不能用於jpeg
require("file-loader?name=img/[name].[ext]?!./testdata/sad.jpg");
只是不行。
我webpack.config.js:
module.exports = {
entry : './src/client/index.js',
output : {
filename: 'bundle.js',
path : './dist'
},
resolve : {
extensions: ['.js', '.jsx', '.css', '.scss', '']
},
module : {
loaders: [
{
test : /\.js$/,
exclude: /(node_modules|bower_components)/,
loader : 'babel-loader',
query : {
presets: ['es2015']
}
},
{
test: /\.jpg$/,
loader: 'file-loader'
}
]
},
plugins : []
};
我karma.conf.js:
const _ = require('lodash');
const RewirePlugin = require("rewire-webpack");
let webpackConfig = _.clone(require('./webpack.config.js'), true);
webpackConfig.plugins.push(new RewirePlugin());
module.exports = function (config) {
config.set(
{
basePath: './src/',
frameworks: ['mocha'],
files: [{pattern: '**/*.test.js'}],
exclude: [],
preprocessors: {
'**/*.js': ['webpack']
},
webpack: {
plugins: webpackConfig.plugins,
module : webpackConfig.module,
resolve: webpackConfig.resolve
},
reporters: ['progress', 'mocha'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
browsers: ['Chrome'],
singleRun: true,
concurrency: Infinity
})
};