错误[预处理]:无法加载“ webpack”,未注册! 也许您缺少一些插件?
Webpack版本: 4.14.0
Webpack Karma版本: 2.0.4
业力版本: 3.0.0
Linux
module.exports = ( config ) => {
config.set( {
basePath: path.resolve( __dirname ),
browsers: [ 'PhantomJS' ],
files: [ {
pattern: '../../../spec/**/*.spec.js',
watch: true
} ],
preprocessors: {
[ '../../../spec/**/*.spec.js' ]: [ 'webpack' ]
},
reporters: [ 'mocha' ],
plugins: [
'karma-webpack',
'karma-mocha',
'karma-phantomjs-launcher',
'karma-mocha-reporter',
],
webpack: {
mode: 'development',
target: 'web',
module: {
rules: [ {
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
} ]
},
resolve: {
extensions: [ '.js', '.jsx ' ],
modules: [ 'node_modules', 'src' ],
}
},
webpackMiddleware: {
noInfo: true,
stats: {
chunks: false
}
},
} )
}
答案 0 :(得分:0)
希望这会有所帮助!
这是我正在工作的karma.conf.js
'use strict';
var webpackConfig = require('./webpack.test.js');//webpack config for test
process.env.CHROME_BIN = require('puppeteer').executablePath();//Node library for headless Chrome, https://developers.google.com/web/tools/puppeteer/
module.exports = (config) => {
config.set({
basePath: '',
frameworks: ['jasmine'],
plugins: [
'karma-jasmine',
'karma-chrome-launcher',
'karma-webpack',
'karma-typescript-preprocessor'
],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['HeadlessChrome'],
customLaunchers: {
HeadlessChrome: {
base: 'ChromeHeadless',
flags: [
'--no-sandbox',
'--headless',
'--disable-gpu',
'--disable-translate',
'--disable-extensions'
]
}
},
singleRun: process.argv.indexOf("--watch") === -1,
autoWatchBatchDelay: 300,
files: [
'./node_modules/angular/angular.js',
'./node_modules/angular-mocks/angular-mocks.js',
'./src/test.ts'
],
preprocessors: {
'./src/test.ts': ['webpack'],
},
client: {
// This is important as there are a lot of tests that are reliant in the order that they were written.
jasmine: {
random: false
}
},
webpack: webpackConfig,
webpackMiddleware: {
stats: {
/* https://github.com/TypeStrong/ts-loader/commit/eb8bbf8e11779487d3af527f8b70644316075ee8
*/
warningsFilter: /export .* was not found in/
}
}
});
};