Skip to content

fix(less): Add less compile target files as options. #1236

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

Closed
wants to merge 6 commits into from

Conversation

nmorenor
Copy link

Right now the LESSPlugin will compile all the .less files trying,
althogh the less compiler is silently failing and sending just a stacktrace.
This change allow you to send a 'compile-targets' array with the list of .less
files that should be compiled.
The issue is that some .less files are trying to use a not available variable
at the scope of the file, the less files could contain a set of files with all
the imports. If we tell the compiler to just compile these files we get the desired
behaviour, your dist directory get the css files.

There could be improvements over this change, like displaying a better less compiler
message so that you know why your files did not compile. Another improvment is the fact
that the less @import inside the node_modules are not resolved by the less compiler,
perhaps we could add a special variable that is replaced on this files at compile time
to resolve the path of the node_modules.

nmorenor added 2 commits June 28, 2016 14:12
Right now the LESSPlugin will compile all the .less files trying,
althogh the less compiler is silently failing and sending just a stacktrace.
This change allow you to send a 'compile-targets' array with the list of .less
files that should be compiled.
The issue is that some .less files are trying to use a not available variable
at the scope of the file, the less files could contain a set of files with all
the imports. If we tell the compiler to just compile these files we get the desired
behaviour, your dist directory get the css files.

There could be improvements over this change, like displaying a better less compiler
message so that you know why your files did not compile. Another improvment is the fact
that the less @import inside the node_modules are not resolved by the less compiler,
perhaps we could add a special variable that is replaced on this files at compile time
to resolve the path of the node_modules.
Right now the LESSPlugin will compile all the .less files trying,
althogh the less compiler is silently failing and sending just a stacktrace.
This change allow you to send a 'compile-targets' array with the list of .less
files that should be compiled.
The issue is that some .less files are trying to use a not available variable
at the scope of the file, the less files could contain a set of files with all
the imports. If we tell the compiler to just compile these files we get the desired
behaviour, your dist directory get the css files.

There could be improvements over this change, like displaying a better less compiler
message so that you know why your files did not compile. Another improvment is the fact
that the less @import inside the node_modules are not resolved by the less compiler,
perhaps we could add a special variable that is replaced on this files at compile time
to resolve the path of the node_modules.
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@nmorenor
Copy link
Author

I signed it as part of Genuitec’s CLA

@nmorenor
Copy link
Author

nmorenor commented Jun 28, 2016

This could be an example on how you'll specify the compile-targets

module.exports = function(defaults) { return new Angular2App(defaults, { vendorNpmFiles: [ 'systemjs/dist/system-polyfills.js', 'systemjs/dist/system.src.js', 'zone.js/dist/**/*.+(js|js.map)', 'es6-shim/es6-shim.js', 'reflect-metadata/**/*.+(ts|js|js.map)', 'rxjs/**/*.+(js|js.map)', '@angular/**/*.+(js|js.map)' ], lessCompiler: { 'paths': ['src/app/less', 'node_modules/bootstrap-less' ], 'compile-targets' : [ 'src/app/less/main.less' ] } }); };

As a side note:
By having the paths: node_modules/bootstrap-less allow you to import less files from inside this module, having an import like @import "bootstrap/variables.less";

@nmorenor
Copy link
Author

After a second thought, maybe the change should be the other way around. Since Angular 2 is component based and you can have a css per component, perhaps the lessCompiler option should be to set the paths to exclude.

lessCompiler: { 'paths': ['src/app/less', 'node_modules/bootstrap-less' ], 'exclude-targets' : [ 'src/app/less/**/*.+(less)'] } }); }

That will allow you to have all your less files under src/app and allow you to use .less files for your components, compiling them using imports like, @import "variables.less", making less to look for imports in one of the 'paths' parameter, in this case src/app/less/variables.less

nmorenor added 3 commits June 28, 2016 22:22
Send and exclude less regex file pattern to exclude the compilation of files.

This change allow you to have all your less files under src/app.
This reverts commit 0831ce1
@nmorenor
Copy link
Author

nmorenor commented Jul 1, 2016

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes and removed cla: no labels Jul 1, 2016
@nmorenor nmorenor closed this Jul 4, 2016
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants