Comments (4)
@mathiasbynens did he part :) We can easily do what you ask for ourselves:
install node-glob in your project (e.g. npm i glob --save-dev
)
then in your gruntfile.js
:
var glob = require('glob');
// ...
template: {
some_target: {
// options: { ... },
get files () {
var result = {};
glob.sync('app/**/*.js.tpl').forEach(function (file) {
this[file.replace(/\.tpl$/, '')] = file;
}, result);
return result;
}
}
}
from grunt-template.
Oh interesting I was not aware this was possible. Is there any documentation that says we are allowed to use a function in place of the 'files' object? Thanks for the help though.
from grunt-template.
This is a getter, not a function per se.
It is implemented as a function, but exposed a regular property value. So as far as grunt is concerned, { get files () { return ['value']; } }
is the same as { files: ['value'] }
: It sees the file
property as an Array
in either case.
This getter/setter syntax was popular before Object.defineProperty became all the rage (and the standard :-). The latter does offer much more flexibility, but get/set still looks cleaner when your don't need any fancy feature. Let's not even talk about defineGetter :-P
from grunt-template.
Ah I see, I have used getters and setters in C# before but didn't realize they were actually a legacy construct of JS (rather I thought they were ES6+ features). Guess you learn something everyday :) Thanks
from grunt-template.
Related Issues (9)
- No error when template can't be found HOT 2
- templating with target does not work HOT 3
- custom delimiters not working on js files? HOT 9
- permit named named variable option
- [Question] Target all files in a directory HOT 1
- Task vs. Target specific options [doesn't work] HOT 4
- How to create multiple templates at once?
- Specify destination file permissions
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grunt-template.