我使用webpack + babel作为React + Redux应用程序和Mocha + Karma进行测试.redux测试用例正在正确执行.但是,当我尝试使用react-addons-test-utils进行DOM测试并使用Karma运行它时会出现此错误
未捕获的TypeError:无法将符号值转换为http:// localhost:9876/karma.js中的字符串:339
为了正确调试,我在karma lib文件中放了几个记录器(我知道我不应该这样)并且得到了这个
但是,当我不使用KarmaJS并且只是尝试运行测试时,它看起来很好.这是我的karma.conf
"use strict";
let webpackConfig = require('./webpack.config');
const coverage = process.env.COVERAGE;
webpackConfig.externals = {};
getWebpackLoaders();
module.exports = function(config){
config.set({
basePath: '.',
frameworks:['mocha'],
autoWatchBatchDelay:500,
browsers: ['Chrome'],
customLaunchers: {
Chrome_without_security: {
base: 'Chrome',
flags: ['--disable-web-security']
}
},
preprocessors: {
'./test/**/*.js':['webpack']
},
reporters: getReporters(),
coverageReporter: {
reporters: [
{type: 'lcov', dir: 'coverage/', subdir: '.'},
{type: 'json', dir: 'coverage/', subdir: '.'},
{type: 'text-summary'}
]
},
exclude:['node_modules'],
port:9876,
files: [
'node_modules/react/dist/react-with-addons.js',
'test/test.js' …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用代码拆分的 webpack 4 (4.0.1)。我正在使用动态加载来加载 React 组件。而 React 组件又是从内部 npm 模块导入组件。例如,在我的应用程序中,我有以下路线。
<Route exact path="/" component={Home} />
<Route path="/about" component={About} />
<Route path="/topics" component={Topics} />
Run Code Online (Sandbox Code Playgroud)
在每个Home,About和Topics组件中,我从我的内部 npm 模块(让我们说int-home,int-about等等)导入一个组件。
export { App as default } from 'int-about';
现在有了这个设置,webpack 会吐出对应于每个动态导入的额外供应商包
我的 webpack 配置可能有什么问题?如何确保在我的构建中生成单个供应商包?下面是我的主应用程序的 webpack 配置。
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
module.exports = {
entry :'./src/index.js',
output : {
filename: '[name].js',
chunkFilename: '[name].js',
path: …Run Code Online (Sandbox Code Playgroud)