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.

Keep "import css" line to the output file?

See original GitHub issue

Rollup Config

export default {
  input: "src/index.js",
  output: {
    file: "dist/index.js",
    format: "cjs"
  },
  plugins: [
    postcss({
      extract: true
    })
  ]
};

src/index.js

import "./index.less";

Expected bundle

require("./index.css") 
  • But the actual result is an empty bundle

Issue Analytics

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

github_iconTop GitHub Comments

6reactions
ShanonJacksoncommented, Mar 8, 2020

The production use is this @Himself65

At the moment most library authors bundle an entire styles.css file which is all the styles needed for all their components; This is not ideal as it imports styles for components the consumer isn’t using into their project.

If the requires(“.css”) statements are left in the output library consumers will automatically import only the critical css that they need as they import the components they want.

To get around this i issue iv’e created a hack work around which works for me in the meantime.

1reaction
ShanonJacksoncommented, Apr 2, 2020

We leave the actual .module.scss files in the output in our usecase but it looks something like this as our own rollup plugin and we turned off rollup-plugin-postcss

export function scss() {
	var styles = {};
	var filter = createFilter(["**/*.scss"]);
	return {
		transform(code, path) {
			if (!filter(path)) {
				return;
			} else {
				/* is scss */
                                // just replaces "@import "src/styles/variables" with the library name reference "@import "~qubic-lib/src/styles/variables"
				if (styles[path] !== code && (styles[path] || code)) {
					styles[path] = code.replace(/src/g, "~qubic-lib/src").replace(/-legacy/g, "");
				}
				return '';
			}
		},
		generateBundle() {
			/* Outputs css files doesn't touch js files */
			return Promise.all(Object.keys(styles).map((key) => {
			  /* Output the files to their directory in dist */
        /* basically fileName.replace("src", "dist")
           writeFileSync Each File
         */
			}))
		},
	}
}

Read more comments on GitHub >

github_iconTop Results From Across the Web

import .css file into .less file - Stack Overflow
If you want to import a CSS file, and don't want LESS to process it, just use the .css extension: @import "lib.css"; The...
Read more >
Including .css files with @import is non-standard behaviour ...
Our recommendation is to not import .css files. Doing so makes you're code non-portable and tightly couples you to a specific implementation. In ......
Read more >
How to include one CSS file in another? - GeeksforGeeks
Yes, It is possible to include one CSS file in another and it can be done multiple times. Also, import multiple CSS files...
Read more >
Sass: @import
Sass extends CSS's @import rule with the ability to import Sass and CSS stylesheets, providing access to mixins, functions, and variables and combining ......
Read more >
CSS, SCSS, and Less support in Visual Studio Code
At this point, if you create and/or modify Less or SASS files, you see the respective CSS files generated and/or changes reflected on...
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