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

How to completely omit blocks with unmatched build targets? #111

Open
leolux opened this issue May 24, 2017 · 9 comments
Open

How to completely omit blocks with unmatched build targets? #111

leolux opened this issue May 24, 2017 · 9 comments

Comments

@leolux
Copy link

leolux commented May 24, 2017

Currently every block gets written to the destination file even when the build target does not match the block target. But this results in too many blocks within the destination file (each for every target).

Is there a way to completely exclude/omit blocks based on the build target? Or is it possible to combine or nest "build:remove:dev" with "build:js:dist inline" somehow to achive the desired effect?

@leolux leolux changed the title How to completely omit a blocks with unmatched build targets? How to completely omit blocks with unmatched build targets? May 24, 2017
@dciccale
Copy link
Owner

@leolux
Copy link
Author

leolux commented May 24, 2017

As the documentation says: "Specifying true will strip comments which do not match the current target" In my case this means that the destination file still contains all unprocessed script elements but without comments. Removing the comments is fine but how to remove the block content when the build target is unmatched?

@dciccale
Copy link
Owner

Could you provide a short example of the input -> output you seek?

@dciccale dciccale reopened this May 24, 2017
@leolux
Copy link
Author

leolux commented May 24, 2017

Ok, I got it!
It is possible to have multiple targets seperated by comma. This allows me to remove the block for a certain target. A nice feature would be to have a target which includes the block only on a matched target thus all unmatched targets get removed automatically.

@leolux leolux closed this as completed May 24, 2017
@leolux
Copy link
Author

leolux commented May 24, 2017

To complete with an example:

<!-- build:remove:dist,js:dev inline -->
<script src="my/lib/path/lib.js"></script>
<!-- /build -->

This special comment combines "remove:dist" with "js:dev inline". Running "grunt dev" will replace the script element with the corresponding inline javascript. And running "grunt dist" will write nothing to the destination file.

Im am not sure why this syntax actually works because the documentation only says that you canpass multiple comma-separated targets and but not multiple types. In my example I passed multiple build types with a single target for each type. Is my syntax valid in your eyes?

Update: "grunt dev" does not inline the javascript so the example does not work as intended.

@dciccale
Copy link
Owner

dciccale commented May 24, 2017

hm i see thanks for the feedback. we'll see if this comes up again to make it a feature. not many grunt users anymore though.

however this maybe more useful to include directly in the core parser https://github.com/dciccale/node-htmlprocessor will keep it in mind

@dciccale
Copy link
Owner

Your example seems incomplete

@leolux
Copy link
Author

leolux commented May 24, 2017

I am having problems escaping comments in markdown code. Now it looks fine :-)

@leolux
Copy link
Author

leolux commented May 24, 2017

Update: The example does not work as expected for "grunt dev" because the script does not get inlined. So the syntax given in the example is wrong. Is it even possible to pass multiple types in the comment ("remove" and "js")?

@leolux leolux reopened this May 24, 2017
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

No branches or pull requests

2 participants