riot / compiler

Riot.js compiler
MIT License
64 stars 29 forks source link

Supplying custom parsers through the compiler.compile opts #86

Closed akmoulai closed 8 years ago

akmoulai commented 8 years ago

After searching a quite a bit, the only way I found to pass custom CSS parsers was to use riot.parsers.css.myCustomCSSParser which is fine if you have access to the riot's instance.

However, I'm in a situation where we use esnunes/riotjs-loader and I have no way to modify riot's instance. The only thing I can pass through with webpack is the options for the compiler.compile function (done through the query object in webpack).

Do you think you could make supplying new custom parsers definitions through the opts?

Something like:

{
  parsers: {
    css: {
      myCustomCSSParser: function (tagName, css) {
          ...
      },
      ...
    },
    js: {
      myCustomJSParser: function (tagName, css) {
          ...
      },
      ...
    },
  }
}

There may be other useful use cases (I'm new to Riot).

@GianlucaGuarini @aMarCruz Thanks for considering !

Edit: the need for this is to add postcss autoprefixer to SCSS styles defined in the tags. All of that with webpack!

aMarCruz commented 8 years ago

@akmoulai sorry, not in v2. I'm working in a complete rewrite for v3 which will support this and other features. Currently, the compiler API is convoluted and inconsistent, I hope v3 will be more simple and versatile.

akmoulai commented 8 years ago

@aMarCruz Thanks for your feedback, closing the issue... Please let me know if you would consider a PR!

GianlucaGuarini commented 8 years ago

@aMarCruz btw this feature should be already implemented https://github.com/riot/compiler/commit/124e620ea513ad84700af5a9469c378ee922e1cf and the option name is called parserOptions

UPDATE: nevermind parsetOptions does something else sorry for the confusion

akmoulai commented 8 years ago

@GianlucaGuarini I'd really like to set my parsers through parserOptions, but after going through the code it didn't look like a possibility :(

It'd be really easy to add this feature by merging whatever parsers that are supplied (as an object) into riot.parsers.