[英]How to ignore raw loader for testing webpack
I have some components with svg's loaded inline using webpack raw loader eg.. 我有一些使用webpack原始加载器内联svg加载的组件,例如..
import React, { Component } from 'react'
import svg from '!raw!../assets/images/logo.svg'
export default class Logo extends Component {
render() {
return (<a href={this.props.url} dangerouslySetInnerHTML={{__html: svg}} />)
}
}
When trying to test these components server side using tape, they fall over. 当尝试使用磁带测试服务器端的这些组件时,它们就会崩溃。 If I have css modules included, it is no problem, I can use css-modules-require-hook but svg's will not work. 如果我有css模块,这没有问题,我可以使用css-modules-require-hook,但svg将无法正常工作。 So I really need a raw loader require hook or something like that. 所以我真的需要一个原始的加载器需要钩子或类似的东西。
require('babel-register');
require('css-modules-require-hook/preset');
/* tests after this can import components with css includes */
I tried using isomorphic-ensure but this did not work. 我尝试使用isomorphic-ensure,但这不起作用。
require('babel-register');
require('css-modules-require-hook/preset');
require('isomorphic-ensure')({
loaders: {
raw: require('raw-loader'),
raw: require('react-svgdom-loader')
},
dirname: __dirname
})
I get the following error: 我收到以下错误:
Cannot find module '!raw!../assets/images/
If you're not using webpack for your tests then you could use the ignore-styles module . 如果您没有使用webpack进行测试,那么您可以使用ignore-styles模块 。
You may have to configure it if you plan to use it with css-modules-require-hook as it will also also ignore CSS files by default . 如果您计划将其与css-modules-require-hook一起使用,则可能必须对其进行配置, 因为默认情况下它也会忽略CSS文件 。 eg: 例如:
require('ignore-styles').register(['.svg'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.