ngtemplate-loader icon indicating copy to clipboard operation
ngtemplate-loader copied to clipboard

Implement proper chained loading using module.exports instead of stri…

Open m0ppers opened this issue 8 years ago • 4 comments

…ng magic

I am trying to use jade templates as partials and I simply couldn't get it to run.

the jade loader is returning a function and I am picking it up, create the final template string by piping it through apply and then I want to pipe the result to ngtemplate.

This is the result:

ERROR in .!./~/apply-loader!./~/jade-loader!./test/src/test.jade
Module parse failed: /Users/mop/projects/ngtemplate-loader/index.js!/Users/mop/projects/ngtemplate-loader/node_modules/apply-loader/index.js!/Users/mop/projects/ngtemplate-loader/node_modules/jade-loader/index.js!/Users/mop/projects/ngtemplate-loader/test/src/test.jade Line 2: Unexpected token var
You may need an appropriate loader to handle this file type.
| var path = '/Users/mop/projects/ngtemplate-loader/test/src/test.jade';
| var html = var jade = require("/Users/mop/projects/ngtemplate-loader/node_modules/jade/lib/runtime.js");
| 
| module.exports = function template(locals) {

After digging into the code I stumpled upon the string magic (/module.exports/) in this module. I am a total newbie to webpack but this doesn't seem to be the correct way to do it.

I had a look here:

https://github.com/mogelbrod/apply-loader/blob/master/index.js

and this seems to be a solid way to properly chain loaders.

m0ppers avatar Oct 19 '15 14:10 m0ppers

Yes I see how that way is better. But I don't see why you are using apply-loader in the test? Doesn't your change make it un-necessary?

WearyMonkey avatar Oct 22 '15 05:10 WearyMonkey

This is related to the jade loader. It will return a function (so you can supply template variables). ng-template however will require a string. To do the conversion the apply loader is needed. Without it the ngtemplate would be the function body of the jade loader which is not really helpful :)

See https://github.com/webpack/jade-loader/issues/15

m0ppers avatar Oct 22 '15 07:10 m0ppers

Got it thanks. Will do some testing this weekend.

WearyMonkey avatar Oct 23 '15 06:10 WearyMonkey

There is not only one use case of yours. In common case, ngtemplate-loader process a string with module.exports = ...... Therefore, you can chain another loader like raw or html before ngtemplate to get it work but not change its source to poor compatibility.

e-cloud avatar Jun 14 '16 08:06 e-cloud