bluepnume
bluepnume

Reputation: 17128

webpack - how to stop the loader running twice?

All of my text imports in a big project are in the form:

var template = require('text!./foo.html');

I'd like to set webpack to automatically use text-loader, so I added the following to my config:

{ test: /\.html$/, loader: 'text-loader' }

Only problem is now my templates are being run through the loader twice, and I'm getting something like this in my bundle...

module.exports = 'module.exports = "<section class=\\"foobar\\" ...

How can I set the loader to only run once without removing all of the text! callouts from every one of my files? This isn't an option as I'm trying to migrate incrementally...

Upvotes: 1

Views: 1350

Answers (1)

Abhinav Singi
Abhinav Singi

Reputation: 3399

require('text!./foo.html') applies text-loader to the foo.html
{ test: /\.html$/, loader: 'text-loader' } applies text-loader to every html

Hence,your loader is applied twice.

You should remove text-loader from either of two and it will work fine

Upvotes: 3

Related Questions