question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Option to output CSS instead of JS

See original GitHub issue

👋 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.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:6

github_iconTop GitHub Comments

2reactions
bennypowerscommented, Mar 8, 2020

acc’d to readme, inject is meant to add a script to index.html containing these javascript objects.

In my case, i’d simply like to transpile the css using post css, so I can import it as a js module using other tools

2reactions
Himself65commented, Mar 8, 2020

nice idea, but I’m thinking to use inject: Function to achieve this

related #199

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can I use webpack to generate CSS and JS separately?
If you do reference the CSS files from your js, you can easily bundle the CSS into a separate file with the Extract...
Read more >
The Many Ways to Include CSS in JavaScript Applications
When this happens, most CSS-in-JS frameworks will output the associated CSS of only the components that are rendered on the page at any ......
Read more >
The HTML Option element - MDN Web Docs - Mozilla
<option>: The HTML Option element · Try it · Attributes · Styling with CSS · Examples · Technical summary · Specifications · Browser...
Read more >
rollup-plugin-scss - npm
Rollup multiple .scss, .sass and .css imports. ... rollup.config.js import scss from 'rollup-plugin-scss' export default { input: 'input.js' ...
Read more >
How to set up style loader and css loader with webpack, to ...
Including your CSS stylesheet in your Javascript file · Install some webpack loaders to make use of your CSS stylesheet import · Update...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found