How would I set the directive(s) in the webpack loader?
Scrum opened this issue · comments
I posted this in the gitter, but no one responded yet: How would I set the directive(s) in the webpack loader?
Originally posted by @trisys3 in posthtml/posthtml#328 (comment)
For example, in straight PostHTML I can do this:
const posthtml = require('posthtml');
const text = '<?php echo $myVar; ?>';
const {html} = posthtml().process(text, {
sync: true,
directives: [{
name: '?php',
start: '<',
end: '>',
}],
});
console.log(html); // '<?php echo $myVar; ?>';
How do I do this with posthtml-loader
? Without the directives, I just get an empty string.
The options don't seem to be able to include parser options. Also, posthtml-loader
allows for using posthtml.config.js
through the posthtml-load-config
package, but that doesn't seem to allow parser options either.
webpack configs can get pretty convoluted, but I used a loader config with something like:
{
module: {
rules: [{
loader: 'posthtml-loader',
options: {
directives: [{ name: '?php', start: '<', end: '>' }],
},
]},
},
},
and that threw the "Invalid options object" error.
I also tried several other configurations. Wrapping the "directives" in "config" threw the same error, while wrapping it in "config: { ctx }" didn't throw an error but still didn't show the PHP string.
@trisys3 publish v2.0.0
Thanks so much, this is great! I'm sure other people would have requests for different options, and the sync
was mainly for demo purposes, but it's a good start! You can always add more options if others ask, I suppose.
Thanks so much, this is great! I'm sure other people would have requests for different options, and the
sync
was mainly for demo purposes, but it's a good start! You can always add more options if others ask, I suppose.
All options are now being processed
The options are processed, as there's no error anymore, but they don't seem to be used. At least directives
isn't.
Also, I can't seem to re-open, so can you please re-open if you can? Thanks.
Nevermind, please ignore. This seems like an issue with posthtml-expressions
ignoring the directives. I added an issue on that repo, posthtml/posthtml-expressions#97.