Comments (2)
I have the same question about the SCSS format.
Source files structure
- src
- components
- button
- index.js
- index.scss
- index.js
- index.scss
Expected transpile files structure
- lib
- components
- button
- index.js
- index.css
- index.js
- index.css
And in lib/components/button/index.js
import './index.css';
rather than import './index.scss.js'
;
from rollup-plugin-styles.
I drafted a plugin to explain my idea, here is the codesandbox.
The file name is index.css
rather than index.scss.js
.
The content is plain CSS rather than JS.
Here is the main code
function scss() {
return {
name: "rollup-scss-to-css-plugin",
transform(code, id) {
if (id.endsWith(".scss")) {
return new Promise((resolve, reject) => {
const opts = {
data: code,
file: id,
includePaths: [path.dirname(id)],
};
sass.render(opts, (error, obj) => {
if (error) {
reject(error);
return;
}
this.getModuleInfo(id).meta.targetCSS = obj.css.toString();
resolve({
moduleSideEffects: "no-treeshake", // I have to use this to keep the chunk
code: "export default {}", // fake code to keep chunk
map: null,
});
});
});
} else {
return Promise.resolve({ code, map: null });
}
},
renderChunk(code, chunk, options, meta) {
if (code.includes(".scss.js")) {
return code.replace(".scss.js", ".css"); // dirty way to replace the code in consumer files
} else if (chunk.fileName.endsWith(".scss.js")) {
options.sourcemap = false; // the sourcemap is not able to be fixed, just sacrifice it
chunk.fileName = chunk.fileName.replace(".scss.js", ".css"); // mutate this to fix the file name
return this.getModuleInfo(chunk.facadeModuleId).meta.targetCSS; // replace the content with the plain css
}
},
};
}
I'm not familiar with Rollup's mechanism, but I believe there must be a better way to achieve this. Anyone who has an idea, please let me know.
from rollup-plugin-styles.
Related Issues (20)
- Unexpected code splitting, possible feature request
- Support Parcel CSS as alternative to cssnano HOT 3
- Support importing style with query string HOT 1
- Scss @charset failing
- Separate css and .min.css files
- Is there a way to pass a style nonce property when the code injects the styles?
- Test fail due to cssnano
- [Feat request] customlize the image inline function
- Is it possible to use globs to import sass files?
- Prevent to add hash to referenced files inside CSS HOT 1
- Support for rollup v3 HOT 15
- CSS Injection into Server Side render (SSR) HOT 3
- [!] (plugin styles) Error: EACCES: permission denied, open '/.config/postcssrc' HOT 1
- Updating styles affects js file hash
- I would like to be able to freely define the export path.
- support lightningcss as an alternative to cssnano
- CSS input, emit raw output to file (no ES parsing)
- scss nesting not working with vue scoped style
- Hello, May I know if this project `rollup-plugin-styles` is still maintained? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rollup-plugin-styles.