Requirejs “text!” plugin alternative to webpack

匿名 (未验证) 提交于 2019-12-03 01:38:01

问题:

How to make this work in webpack?

var templateHtml = require("text!templates/main.html"); console.log(templateHtml); // outputs string content of the "main.html" file 

I need to migrate from requirejs + require-text plugin to webpack with minimum code changes so I need that loader in webpack... Have any suggestions?

回答1:

Should use 'text-loader': https://www.npmjs.com/package/text-loader

My mistake was that I used both text! notation in require and loaders config with "text-loader".



回答2:

As the other answer mentions, use https://www.npmjs.com/package/text-loader. With Webpack 2.2, I also needed to add the following to the root of the Webpack config object:

resolveLoader: {     alias: {         // Support for require('text!file.json').         'text': 'full/path/to/node_modules/text-loader'     } } 


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