我正试图在我的业力测试中使用DLLReferencePlugin
而我并不完全确定如何使其工作。
我已将vendors.js
和vendors-manifest.json
放入src/static/
dll是使用libraryTarget=var
生成的,它可以在我的开发和生产webpack构建中运行。我的dev / production build使用一个html文件,其脚本标记指向根路径中的“vendors.js”。 dev / production build将静态文件夹中的所有文件复制到目标文件夹。因此脚本标签可以找到vendors.js
。
然而,在运行测试时,我收到了PhantomJS的错误:ReferenceError: Can't find variable: vendors
。我想知道它是否找不到vendors.js
脚本标签?
如果它来自DLL插件,如何在我的karma配置中使用vendors.js
?
我是业力新手,所以任何指导都会受到高度赞赏。
我尝试过很多没有结果的事情,包括将require('vendors.js')
放在我的测试条目文件中,设置供应商的外部是真的,使用解析别名,但因为我对业力知之甚少就像我在黑暗中拍摄一样。因此,我们将非常感谢任何帮助。
我的业力配置如下。这来自我使用的starter kit。我的测试文件也与该入门套件相同。如果您需要任何其他信息以帮助,请与我们联系。谢谢!
const karmaConfig = {
basePath : '../', // project root in relation to bin/karma.js
files : [
{
pattern : `./test-bundler.js`,
watched : false,
served : true,
included : true
}
],
singleRun : !argv.watch,
frameworks : ['mocha'],
reporters : ['mocha'],
preprocessors : {
[`/test-bundler.js`] : ['webpack']
},
browsers : ['PhantomJS'],
webpack : {
devtool : 'cheap-module-source-map',
resolve : Object.assign({}, webpackConfig.resolve, {
alias : Object.assign({}, webpackConfig.resolve.alias, {
sinon : 'sinon/pkg/sinon.js'
})
}),
plugins : webpackConfig.plugins,
module : {
noParse : [
/\/sinon\.js/
],
loaders : webpackConfig.module.loaders.concat([
{
test : /sinon(\\|\/)pkg(\\|\/)sinon\.js/,
loader : 'imports?define=>false,require=>false'
}
])
},
// Enzyme fix, see:
// https://github.com/airbnb/enzyme/issues/47
externals : Object.assign({}, webpackConfig.externals, {
'react/addons' : true,
'react/lib/ExecutionEnvironment' : true,
'react/lib/ReactContext' : 'window'
})
},
webpackMiddleware : {
noInfo : true
},
coverageReporter : {
reporters : config.coverage_reporters
}
}
if (config.globals.__COVERAGE__) {
karmaConfig.reporters.push('coverage')
karmaConfig.webpack.module.preLoaders = [{
test : /\.(js|jsx)$/,
include : new RegExp(config.dir_client),
loader : 'babel',
query : Object.assign({}, config.compiler_babel, {
plugins : (config.compiler_babel.plugins || []).concat('istanbul')
})
}]
}
答案 0 :(得分:3)
回答我自己的问题.Jeeze所需要的只是阅读一些文档...
我把它放在我的业力配置的文件条目中:
files: [{
pattern : `./src/static/vendors.js/`,
watched : false,
served : true
},
...]