-
Notifications
You must be signed in to change notification settings - Fork 12k
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
Jade support in webpack releases #1886
Comments
So you guys closed #996 and #968 in favor of #40, then closed #40 with no specific ending, then closed the efforts in #1433 and #626 because you changed to webpack and here we are with no answers. Sorry, I'm not trying to be annoying, specially when I see a lot of hate on recent issues with bugs regarding latest TS/Angular/CLI combinations. I can understand error because we are humans, I can understand time because we need to sleep and have to live, but I do hate purposeful indifference, just because its not your problem. I'm open to work myself on the CLI on a new PR, but I do need guidance, and that really starts at least with a single answer in a timelapse of 10 days. Nevertheless, thank you for your efforts. |
This is my current "solution": gulpfile.js:
.vscode/settings.json:
This actually works but it's obviously only a temporary solution.. |
My team is using |
Any news on how to add pug to cli? I opened a thread on Stockoverflow aswell, hoping for some result |
Opened a PR to see how this goes. |
Heya @ShadowManu, we're not trying to be indifferent and I'm sorry that the jade support has fallen to the wayside. I can't say jade/pug support is a big on our radars right now to be honest. If you can get a PR to work I'm happy to review it, but bear in mind that it needs to have tests and documentation. See https://github.com/angular/angular-cli#development-hints-for-hacking-on-angular-cli for a way to start working with a local copy of the CLI. The command that runs the e2e suite is You should test that the the correct html is generated, and that base jade/pug functionality (like imports) works. Regarding documentation, something akin to https://github.com/angular/angular-cli#css-preprocessor-integration should be enough. Ideally we'd also support initializing a project with pug like we do with sass ( |
Thanks man. I'll be looking at the tests and a proper similar documentation as soon as I have time. |
Any updates @ShadowManu ? |
@ShadowManu please, you can look too the support to (lost-grid and/or jeet.gs) and rupture in stylus too? |
@kingsdevelopment @filipesilva I've worked a little with some time I had on this, but got blocked on how to make the tests pass (specially on the time they take). I'll have a second try tomorrow. @nvrossett not that I have knowledge of it. And probably should be on a different PR/issue. |
I just wanted to throw my support behind @tycho01 's pug-plugin-ng and pug-ng-html-loader. I used them to use pug with the Angular Class seed, and it really cleans up the syntax and makes development with Angular2 and pug very pleasant. I recommend checking it out: https://github.com/tycho01/pug-plugin-ng (pug-ng-html-loader is just a fork of pug-html-loader which allows pug-plugin-ng to work) |
@TaylorDennisLee: thanks. note that for Webpack 2 it should work without the additional loader as well now, see the readme. Edit: note that original pug syntax is not harmed/disabled; the plugin just patches the lexer to ensure this cleaner more natural (perspective: HTML) option is parsed correctly as well. |
@tycho01 Okay, so now pug-plugin-ng should work with pug-html-loader, as long as you are using Webpack 2? Also, do you still have to do template: require('./myComp.pug') instead of: templateUrl: 'myComp.pug' Thanks, Taylor |
@TaylorDennisLee: yeah; if you're experiencing issues feel free to file them. |
@tycho01 can you please provide small guide how to add this loader to angular cli. I'm getting:
|
@mbonski: I may have use for further info (where/how you set it, first line of the pug file, whether it worked without it). Could you post an issue with those here? |
I'd be interested to see how to do this with just temporary script that runs right before "ng serve" or "ng build" and also what in the angular-cli source code a change would naturally go. @tycho01 do you have a link for how they handled the Sass issue? |
@TaylorDennisLee you might consider using a Gulp task for Pug compilation then, preferably along with one of the watchy kind. That's what I've been using, failing a better solution thus far. That could look something like this: let gulp = require('gulp'),
gulpWatch = require('gulp-watch'),
runSequence = require('run-sequence'),
pug = require('gulp-pug'),
pug_plugin_ng = require('pug-plugin-ng');
let pug_opts = { doctype: 'html', plugins: [pug_plugin_ng], pretty: true };
let toSrc = gulp.dest((file) => file.base);
gulp.task('pug', () =>
gulp.src('src/**/*.pug')
.pipe(pug(pug_opts))
.pipe(toSrc)
);
gulp.task('watch', [], () => {
runSequence(
['pug'],
() => {
gulpWatch('src/**/*.pug', () => gulp.start('pug'));
}
);
}); As to changes, I linked ShadowManu's and mine in mbonski's issue thread. On the Sass point, I didn't know yet :), but the magic appears to be located here. If I'm reading that correctly, than it should be automatically adding support for any extension already recognized by webpack. So I may have been wrong there earlier! |
@TaylorDennisLee @tycho01 why not simply using |
@ShadowManu: Yeah, under normal circumstances I suppose that would've been the straight-forward way. One complication I faced personally with my plugin was (1) adding configuration, and (2) having to ensure I could add Pug plugins as well (-> functions, therefore can't survive JSON serialization, so couldn't be passed through a CLI). I never really wanted to use a plugin, but that's how it ended up. I'd definitely rather not resort to Gulp either. I just did manage that with help from @TaylorDennisLee though, so to answer @mbonski's earlier question of a guide on how to get this to work before it's merged:
(Now as to the real frontier, ditching pug gulp tasks in Ionic...) |
Has anyone gotten variable interpolation to work with webpack1 and pug-ng-html-loader? For some reason its not being able to access my variables Edit: Just figured out I was basically writing the angular templates using pug and rendering it so instead of using pug variables I should be using angular variables like such |
I found a way to use AngularCLI with Pug using pug-html-loader. After generate new projects using ng new. { test: /.(pug|jade)$/, loader: 'pug-html-loader' }, Use .jade template in component. @component({ I'v made a demo template here https://github.com/CrystalzWind/AngularCLI-Pug |
Equivalent option to @CrystalzWind 's example is to use pug-loader with apply-loader.
and piping the output of the pug-loader through the apply loader which simply executes the template function.
Which works with |
Extending on the workaround presented by @CrystalzWind and @donmahallem, looking at Edit: ScallyGames/angular-cli@f3cfdb8 shows how such a change might look like (it works but I am fully aware that this is not suited for PR yet). |
I'm sorry to be the bearer of bad news, but jade/pug support will not make it to 1.0. It's an medium/big feature that we can't spare the time to make sure it work properly. I know it looks like it would only be a small change in loaders but that's just not been the case with similar features like sass support. We're looking at it for 2.0 instead, either as base functionality or as one of the main usecases for addons. |
Thanks for the update. If we could help out in the testing department, I'd be glad to. |
@filipesilva one of the things that would need some consideration for proper pug support would be how to handle the angular syntax with pug since pug has problems with it (would we want to trade equivalence to pug for syntax convenience). For reference see tycho01/pug-plugin-ng |
On that, fixing Pug to play nice with Angular amounted to one small addition if it'd made it into Pug core (-> consider '[' and '(' after whitespace as valid indication a new property has started). |
They could, yes. We'd still like to make it a first class citizen one day. |
@MarkPieszak this was my current solution to this problem. |
hope some day can support pug in angular-cli |
@mbonski
The only difference is You may also need to add the following into
This also works for any other loader in the webpack universe |
So far I got it working with ng eject BUT this does not work with tests which again does desire an appropiate loader. @Anthonyzou Your workaround does work for JIT but I don't seem to get it running with AOT.
Following the advice of the error and some sites regarding aot I tried: @component({ But it still errors with basicly the same message. Any ideas? |
@donmahallem I actually have no idea, actually. This is adapted from a graphql angular2 example where they manually require a graphql file and it works with AOT. It must also depend on how the loader is built. |
Heya all, this isn't a feature that we're looking at adding in the 1.x timeframe, but rather something that would happen as a third party addon using the upcoming addon system for v2+. |
Guys, I made a pull request to allow tweaking webpack config with a file in the project root. For now, you can use the cli at https://github.com/cashfarm/angular-advanced-cli (branch 1.2.x) Install
Then your components can use pug
But your index has to stay in html. |
Any update? |
Going along with some of the recommendations above, I created a little script that can be ran to automatically insert the pug rule into the node_modules folder. @pexak This can be used as a temporary solution until it can be available natively. Note this could need to be updated & changed if the CLI changes the location or formatting of this file. It's naively searching for npm i --D apply-loader pug-loader pug-rule-insert.jsNow you can just create a simple js file with the code below (put it at your root project level). const fs = require('fs');
const commonCliConfig = 'node_modules/@angular/cli/models/webpack-configs/common.js';
const pug_rule = `\n{ test: /\.pug$/, loader: "apply-loader!pug-loader?self" },`;
fs.readFile(commonCliConfig, (err, data) => {
if (err) { throw err; }
const configText = data.toString();
if (configText.indexOf(pug_rule) > -1) {
return;
}
console.log('-- Inserting .pug webpack rule -- ');
const position = configText.indexOf('rules: [') + 8;
const output = [configText.slice(0, position), pug_rule, configText.slice(position)].join('');
const file = fs.openSync(commonCliConfig, 'r+');
fs.writeFile(file, output);
fs.close(file);
}); Running itRun it simply with:
Needed this for a client, hope this helps! Works with |
Tnks @MarkPieszak |
@MarkPieszak thank you. I used pug-html-loader and html-loader instead, it is working fine, including the include ./pug-file const pug_rule = `\n{ test: /.pug$/, loader: [ 'html-loader', { loader: "pug-html-loader", options: { doctype: 'html', pretty: true } } ], },`; |
@MarkPieszak @clovisj @chenzhiguang If you do so, your AOT builds will fail silently (at least on my machine, as of today) This one was f***ng hard to find. see #8904 |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Sorry for not providing template information but I only have my phone available (and there's no critical info either).
Is there some in-the-works support for jade? The related issues/PR 's were closed but no real solution was provided. What can be done to have support for this?
The text was updated successfully, but these errors were encountered: