Skip to content
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

How would I set the directive(s) in the webpack loader? #124

Closed
Scrum opened this issue Aug 20, 2020 · 7 comments
Closed

How would I set the directive(s) in the webpack loader? #124

Scrum opened this issue Aug 20, 2020 · 7 comments

Comments

@Scrum
Copy link
Member

Scrum commented Aug 20, 2020

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)

@trisys3
Copy link

trisys3 commented Aug 20, 2020

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.

Scrum added a commit that referenced this issue Aug 21, 2020
@Scrum Scrum modified the milestones: 1.0.3, 1.1.0 Aug 21, 2020
@Scrum Scrum closed this as completed in fd79d32 Aug 21, 2020
@Scrum
Copy link
Member Author

Scrum commented Aug 21, 2020

@trisys3 publish v2.0.0

@trisys3
Copy link

trisys3 commented Aug 21, 2020

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.

@Scrum
Copy link
Member Author

Scrum commented Aug 21, 2020

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

@trisys3
Copy link

trisys3 commented Aug 27, 2020

The options are processed, as there's no error anymore, but they don't seem to be used. At least directives isn't.

@trisys3
Copy link

trisys3 commented Aug 27, 2020

Also, I can't seem to re-open, so can you please re-open if you can? Thanks.

@trisys3
Copy link

trisys3 commented Aug 27, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants