将 Javascript 文件作为字符串导入? [英] Import Javascript files as a string?

查看:32
本文介绍了将 Javascript 文件作为字符串导入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够简单地从'file.js 导入一个导入文件,然后让file 成为file.js 中的内容字符串.我玩弄过原始加载器,但它没有给我相同的内容(而是以不同的格式加载它).有什么建议吗?

I want to be able to simply do an import file from 'file.js and then have file be a string of the contents within file.js. I've toyed around with raw-loader but it doesn't give me the same contents (instead it loads it in a different format). Any suggestions?

推荐答案

它没有给我相同的内容(而是以不同的格式加载它)

it doesn't give me the same contents (instead it loads it in a different format)

这似乎意味着您的配置中有其他加载器应用于该文件.您可以通过在导入语句中添加 ! 前缀来强制只使用导入语句中的加载器:

That seems to mean that there are other loaders from your config applied to the file. You can enforce that only the loader in the import statement is used by prefixing it with a !:

import file from '!raw-loader!file.js'

来自文档:

通过在整个规则前面加上 ! 前缀,可以覆盖配置中的任何加载器.

It's possible to overwrite any loaders in the configuration by prefixing the entire rule with !.

这篇关于将 Javascript 文件作为字符串导入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆