Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

m0ppers
Copy link

@m0ppers m0ppers commented Oct 19, 2015

…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.

@WearyMonkey
Copy link
Owner

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?

@m0ppers
Copy link
Author

m0ppers commented Oct 22, 2015

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 pugjs/pug-loader#15

@WearyMonkey
Copy link
Owner

Got it thanks. Will do some testing this weekend.

@e-cloud
Copy link

e-cloud commented Jun 14, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants