notlmn / rollup-plugin-transform-tagged-template

Apply transformations on static contents of tagged template string literals
https://npmjs.com/package/rollup-plugin-transform-tagged-template
MIT License
5 stars 4 forks source link

Pass current tag name to transformer function #2

Open radium-v opened 4 years ago

radium-v commented 4 years ago

For scenarios where multiple types of tags are passed with tagsToProcess, it would be great if the transformer function also passed along the tag name. This would allow for transformers to decide which strategy to use based on the tag:

tagsToProcess: [ "handleHTML", "handleCSS" ],
transformer(data, tag) {
    switch(tag) {
        case "handleHTML":
            // process html
            break;
        case "handleCSS":
            // process CSS
        ...
notlmn commented 4 years ago

I was hoping people would use multiple instances of transformTaggedTemplate in their rollup config to achieve this.

// rollup.config.js
    plugins: [
        transformTaggedTemplate({
            tagsToProcess: ['css', 'scss'],
            transformer(data) {...}
        }),
        transformTaggedTemplate({
            tagsToProcess: ['html', 'htm'],
            transformer(data) {...}
        })
    ],

But considering that we already take in an array of tags, this sounds possible too. Open to other ideas too.