[英]wallaby.js with jQuery
We are using wallaby.js in an Angular 4 project with typescript and there are some parts using jQuery. 我们在带有Typescript的Angular 4项目中使用wallaby.js,其中有些部分使用jQuery。 Wallaby.js is throwing a ReferenceError:
Wallaby.js引发ReferenceError:
ReferenceError: $ is not defined
Any ideas how to fix this? 任何想法如何解决这一问题?
Some Sample code: 一些示例代码:
import { Injectable } from '@angular/core';
declare var $: any;
@Injectable({
providedIn: 'root'
})
export class FroalaService {
constructor() { }
public initFroala(): void {
$.FroalaEditor.DefineIcon('insertnonbreakingspace', {NAME: 'arrows-h'});
$.FroalaEditor.RegisterCommand('insertnonbreakingspace', {
title: 'Non-Breaking Space',
focus: true,
undo: true,
refreshAfterCallback: true,
callback: function () {
this.html.insert('<span style="white-space: nowrap;"> </span>');
}
});
$.FroalaEditor.RegisterShortcut(32, 'insertnonbreakingspace', null, 'Space', false, false);
}
}
The solution for a basic jQuery implemention is to add jQuery to externals in wallaby.js: 基本jQuery实现的解决方案是在wallaby.js中向外部添加jQuery:
var webpackPostprocessor = wallabyWebpack({
entryPatterns: [
'src/wallabyTest.js',
'src/**/*spec.js'
],
module: {
rules: [
...
]
},
resolve: {
extensions: ['.js', '.ts'],
modules: [
...
]
},
node: {
...
},
externals: { jQuery: "jQuery" }
});
...and to add jquery.js to files: ...并将jquery.js添加到文件中:
return {
files: [
{pattern: "node_modules/jquery/dist/jquery.js", instrument: false},
{pattern: 'src/**/*.+(ts|css|less|scss|sass|styl|html|json|svg)', load: false},
{pattern: 'src/**/*.d.ts', ignore: true},
{pattern: 'src/**/*spec.ts', ignore: true}
],
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.