Stencil: Expose rollup config for custom plugins

Created on 2 Feb 2018  路  10Comments  路  Source: ionic-team/stencil

I'd love to be able to use, say, a rollup replacement plugin for string replace. Can we somehow expose the rollup config to users to add whatever they fancy?

Most helpful comment

There you go. A minimal example of a plugin converting postcss files to css files using cssnext plugin:

{
  name: 'postcss-loader',
  transform(sourceText, importee) {
    if (importee.indexOf('.pcss') !== -1) {
      const promise = new Promise((resolve) => {
        require('postcss')([
          require('postcss-cssnext')()
        ])
          .process(sourceText, {
            from: importee
          })
          .then((data) => {
            resolve(data.css);
          })
      });

      return promise;
    } else {
      return Promise.resolve({
        code: sourceText
      });
    }
  }
}

All 10 comments

You already have this option. Just declare an array named "plugins" in the config file. Each item from the array is a plugin. You can find the interface here: https://github.com/ionic-team/stencil/blob/master/src/declarations/plugin.ts

Would be great have some doc's on that 馃憤

There you go. A minimal example of a plugin converting postcss files to css files using cssnext plugin:

{
  name: 'postcss-loader',
  transform(sourceText, importee) {
    if (importee.indexOf('.pcss') !== -1) {
      const promise = new Promise((resolve) => {
        require('postcss')([
          require('postcss-cssnext')()
        ])
          .process(sourceText, {
            from: importee
          })
          .then((data) => {
            resolve(data.css);
          })
      });

      return promise;
    } else {
      return Promise.resolve({
        code: sourceText
      });
    }
  }
}

Ah, yes 馃槄I don't believe this exposes Rollup though. It'd be nice to be able to use the existing rollup plugins

Okay, it seems like the plugins list only transforms sass files at this point

Hello @mlynch,

Please have a look here: https://github.com/bfmatei/stencil-boilerplate/tree/develop

Hints:

  1. Look in stencil.config.js for the plugins array
  2. Look in the plugins folder for the PostCSS plugin definition (I wrote it yesterday)

@bfmatei yes, I see it. The plugins are only called for Sass files right now. I need to run a transform on tsx files, and I want to use existing rollup plugins.

Sorry mate, i missed the part with style files only (hint: it triggers for postcss files for example, not just sass). I just checked with ts and tsx files and you are right :).

Hi, why would this be closed without a resolution or a reason for closing?

@nirlanka - it was closed via pull request. Click on the link right above your comment. That is a reference automatically created by GitHub when it auto-closes an issue that is linked in a specific way with a pull request.

Was this page helpful?
0 / 5 - 0 ratings