Import Javascript files as a string?

我的未来我决定 提交于 2021-01-24 10:52:27

问题


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?


回答1:


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'

From the docs:

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



来源:https://stackoverflow.com/questions/44029866/import-javascript-files-as-a-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!