cpx
cpx copied to clipboard
Question: How to create a transform that change the file extension
First of all, awesome tool!
I am trying to create a transform module that convert all '.tpl' files into '.js'. Could you please provide to me some guidelines or point me out with some documentation/examples?
Thanks in advance.
I'm sorry for this late response.
Currently, we can check filenames inside conversion plugins. For example:
var path = require("path");
var PassThrough = require("stream").PassThrough;
var through = require("through");
module.exports = function convert(filename, args) {
if (path.extname(filename) === ".tpl") {
return through(
function write(chunk) {
this.queue(doSomeConvert(chunk));
},
function end() {
this.queue(null);
}
);
}
return new PassThrough();
};
Hi don't worry we all have to work.
First of all, thank you for your answer. Regarding your code. Does it actually change the file extension or only select those files that are '.tpl' ? Perhaps I'm doing something wrong but it doesn't work for me.
Thanks.
Ah! Unfortunately, this tool does not provide the feature to change the file name in a copy, now. That's an interesting feature.