Comments (5)
I am sorry but this plugin cannot generate the <style>
tags for you because it doesn't know anything about that. It is not working like Webpack which is bundler. What you can do is to generate a css file for your project using this plugin during the build process.
From what I know, style-loader
is appending the <style>
tags during the runtime. So webpack will compile your css to a javascript file and then when you run this file in browser, it will append style tags to html.
This plugin is intended for server side rendering. Only way how to make something like you want possible is to create a plugin that appends a runtime to javascript that will work similar to style-loader
. So it will compile your css and appends it to javascript. Maybe there is something like that.
Try to look on:
- https://github.com/threepointone/glamor
- https://github.com/smyte/jsxstyle
- https://styled-components.com/
But I think glamor is what you want. It is used by styled-components if I am not mistaken.
from babel-plugin-css-modules-transform.
@michalkvasnicak Thank you so much for the explanation and advice! Like I said, I'm still pretty new to developing packages to be used by other projects. I guess because I am transpiling everything with babel in my postinstall
step I thought perhaps there was a way with this project but that makes sense that it cannot do the same things as webpack. I will look into the links you provided although I might just have to accept that I need to create a separate stylesheet. Thanks!
from babel-plugin-css-modules-transform.
@andynoelker No problem :). You can still provide your css files in package. But you need to configure webpack so it can parse your node_modules
. So only hard thing with this solution is that you need to provide step by step guide for others how to set up their webpack + they need webpack to use your packages. You are basically enforcing others to use webpack.
We are doing something like that at work. We have ui-kit
package which is pulled as is (without any babel transformation) and then we are processing it using webpack in a project. So only thing we had to do was to configure to include this ui-kit
.
from babel-plugin-css-modules-transform.
@michalkvasnicak This is all for my work so we also have the luxury of enforcing our consumer apps to parse this project with webpack in node_modules
and that's the solution I've gone with for now. The other projects you linked to look good but they all seem like variations of using CSS-like sytnax in javascript and I really like using native stylesheets with CSS modules. It's a shame there seems to be no great consensus on how to handle stylesheets with javascript, particularly in the React community. As this is was all in my postinstall
build step, I'm wondering if I could use webpack instead of babel to just transpile the files and use style-loader without bundling? Well anyway, the parsing from node_modules
will just have to work for now. Thank you for all of your help!
from babel-plugin-css-modules-transform.
@andynoelker you could use webpack to do what you want. You just need to import your module so webpack will know that it has to transpile source code of your module.
// node_modules/your-module/index.js
import './style.css';
// app.js
import 'your-module';
I am using webpack for server side and client side. Where on the server side I am just getting class names and on the client side I am extracting styles to css file in production. Style loader is used only during the development process.
For example here are webpack 2 configurations for server side and client side in my utility that I use to quickly bootstrap project. (sorry for self-promo). But it is excluding node_modules
by default from transpiling (but it can be configured to include them).
from babel-plugin-css-modules-transform.
Related Issues (20)
- Relative urls are not resolved in extracted css
- dont work for css-loader@^2 HOT 3
- preprocessor errors and missing files are swallowed
- Rebuild extracted CSS file on original css file change (using parceljs instead of webpack)
- using babel-plugin-css-modules-transform with ssr not working HOT 2
- minimist vulnerability in 1.6.2 HOT 1
- Problems on Windows machines HOT 2
- Doesn't work with @babel/register, works only with @babel/cli
- It is not wroking with aliasing css HOT 1
- Better alternative
- Some local test cases fail
- "in" operator fails upon use of "resolve" option
- transform with less HOT 1
- implicitly registeres node hook HOT 1
- import without assign are not processed
- import named className doesn't work HOT 3
- Empty styles HOT 4
- Unable to require/import images when using this plugin
- babel-plugin-css-modules-transform and css-loader create different class names HOT 3
- Using Node's require to resolve file path does not resolve correct library from node_modules
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 babel-plugin-css-modules-transform.