当我运行karma时,我得到以下警告:
配置中的模式警告尚未设置'mode‘选项,对于此值,webpack将回退到'production’。将“mode”选项设置为“开发”或“生产”,以启用每个环境的默认值。您也可以将其设置为“none”以禁用任何默认行为。了解更多信息:https://webpack.js.org/concepts/mode/
我试着按照上面的链接将mode: 'development'
添加到我的webpack-test.config.js
文件中,但不仅没有什么不同,Intellij IDEA抱怨道:
模式webpack:不允许使用属性‘
’
我的单元测试无论如何都会运行,但我想摆脱这个警告。任何帮助都是非常感谢的。
这是我的webpack-test.config.js
文件:
const path = require('path');
const webpack = require('webpack');
const ROOT = path.resolve( __dirname, 'src' );
module.exports = {
mode: 'production',
context: ROOT,
resolve: {
extensions: ['.ts', '.js'],
modules: [
ROOT,
'node_modules'
]
},
module: {
rules: [
// PRE-LOADERS
{
enforce: 'pre',
test: /\.js$/,
use: 'source-map-loader'
},
// LOADERS
{
test: /\.ts$/,
exclude: [ /node_modules/ ],
use: 'ts-loader'
}
]
},
devtool: 'cheap-module-source-map',
devServer: {}
};
我的karma.conf.js
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('karma-webpack')
],
client:{
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
files: [
'spec.bundle.js'
],
preprocessors: {
'spec.bundle.js': ['webpack']
},
webpack: require('./webpack-test.config')
});
};
和spec.bundle.js
const testsContext = require.context("./", true, /\.spec\.ts$/);
testsContext.keys().forEach(testsContext);
我将通过以下方式启动karma:
karma start ./karma.conf.js
发布于 2018-05-17 12:56:58
我通过反复试验偶然发现了这一点,并替换为:
webpack: require('./webpack-test.config')
...in karma.conf.js
具有:
webpack: {
mode: 'development'
}
...and警告消失了。不仅如此,我发现我真的不需要我的webpack-test.config
,也不需要我加载的两个支持它的npm模块:source-map-loader
和ts-loader
。
如果真的有人想既指定mode: 'development'
又指定特定的webpack配置文件,我不确定他们会怎么做。我尝试了几个选项,但找不到任何可行的方法。这篇文章没有很好的文档:
发布于 2018-06-29 05:27:41
您不应该要求在您的配置文件中包含webpack包。不确定这是否会导致Intellij感到困惑,但mode
肯定是webpack的有效属性。
https://webpack.js.org/concepts/mode/
我还注意到,在karma.conf.js
文件中,webpack: require('./webpack-test.config')
行缺少配置文件的.js
扩展名。这可能是为什么你的配置设置没有在你的业力测试中反映出来的原因。
https://stackoverflow.com/questions/50382893
复制相似问题