egoist/rollup-plugin-postcss

Option to output CSS instead of JS

Open

#185 opened on 2019年8月5日

GitHub で見る
 (6 comments) (3 reactions) (0 assignees)JavaScript (689 stars) (209 forks)user submission
bugenhancementgood first prhelp wanted

説明

:wave: Hello! Thanks for publishing this useful package 😄

I'm the author of another CSS plugin for rollup, rollup-plugin-lit-css, which is a simple plugin for importing css files into javascript as lit-element css tagged template literals.

I'd like for my users to have the option to pass their CSS through postcss before loading into JS, and have the postcss rollup plugin output a string of CSS without adding js syntax.

Input

app.js

import style from './styles.css'
console.log(style)

styles.css

main {
  background: red;
  &.nested { background: blue; }
}

rollup.config.js

import postcss from 'rollup-plugin-postcss'
import litcss from 'rollup-plugin-lit-css'

export default {
  input: 'app.js',
  output: {
    format: 'es',
    file: 'bundle.js',
  },
  plugins: [
    postcss({
      output: 'css',
      inject: false,
      plugins: [
        require('postcss-preset-env')({stage: 0})
      ]
    }),
    litcss(),
  ],
}

Expected bundle.js

import { css } from 'lit-element';

var style = css`main {
  background: red
}
main.nested { background: blue; }
`;

console.log(style);

Actual bundle.js

import { css } from 'lit-element';

var style = css`var css = "main {\n  background: red\n}\nmain.nested { background: blue; }\n";
export default css;`;

console.log(style);

If this option is already available, I wasn't able to find it in the docs or the source. From a brief tour of the source, it looks like the plugin always exports JS.

Thanks again for publishing this.

コントリビューターガイド