最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Requirejs "text!" plugin alternative to webpack - Stack Overflow

programmeradmin0浏览0评论

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?

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?

Share Improve this question asked Aug 11, 2015 at 17:23 Dmitry YaremenkoDmitry Yaremenko 2,58022 silver badges31 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

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

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

As the other answer mentions, use https://www.npmjs./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'
    }
}
发布评论

评论列表(0)

  1. 暂无评论