-
-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove Emotion and add inline css #127
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 43c841d:
|
Thanks for this PR. However, using |
Yeah I can see the compiled code uses a dependency from node_modules in the compiled code which it shouldn't, i will take another look at this ;) |
But what do you think of letting the code inject at styletag with the styles next to the component it self? |
I find it awkward to be honest, I have never seen this before. Please see https://dev.to/stereobooster/what-is-the-best-way-to-distribute-styles-with-npm-package-m5f |
Yeah i agree it a bit awkward also why id added the option to disable it, the article you are linking to also suggest some other css-in-js libs which has alot smaller size fx, https://bundlephobia.com/result?p=linaria@1.3.3 Which we could implement instead of emotion, but that leads to some other complications with SSR, but yeah exposing a css file to import proberly is the best solution even tho it gives some more work to the user of the package. Ps the sandbox works now |
I didn't know linaria. If it works I'd be happy to use it in this library! |
Truth be told i have never heard of linaria before that article |
@@ -8,10 +8,16 @@ const config: Config = { | |||
format: ['cjs', 'umd', 'umd-min', 'esm'], | |||
moduleName: 'ReactEasyCrop', | |||
sourceMap: true, | |||
extractCSS: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you explain a bit what these 2 new options are doing please ? 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default the built tool bili extract css imports to its own files and output then in the dist folder, this disabled that feature,
After disabling it, the bili rollup configuration is set to automaticly inject the style tag in the head of the dom, this postcss config disables that, we needed to disabled that feature else the rollup script would end up inside the bundle
This is the script that started to get bundled and the reason why the sandbox didnt works this first time: https://github.com/egoist/rollup-plugin-postcss#inject
examples/src/index.tsx
Outdated
@@ -60,6 +60,7 @@ class App extends React.Component<{}, State> { | |||
render() { | |||
return ( | |||
<div className="App"> | |||
<style>{styles}</style> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have to change the example? I think we should aim to keep the previous version working.
If I understand correctly, this change is not needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We actually dont have to change this, main reason was that i needed to change the webpack config to inline the css, and so this would fail because it also got inline, but i can create 2 different webpack rules for the src and example so we can keep the current behavoir and dont need to change the example ;)
Just tried the sandbox and it looks good to me, really cool stuff. I need more time to test this carefully and really understand the implications :). I mainly want to read the build output :) |
That totally understandable, let me know if you want me to change anything ;) |
@stefanoruth I've checked it locally and I like the approach. However, I would change one thing: I would inject the style tag in the This can be done in const styleTag = document.createElement('style')
styleTag.setAttribute('type', 'text/css')
styleTag.innerHTML = cssStyles
document.head.appendChild(styleTag) Also I don't think we need the What do you think? |
Move it to head now with the code you posted, also removed the |
The more I think about it the more I agree :) I quickly tried tweaking the config yesterday to also export the css as a plain file but didn't find a way so far. One possible approach would be to copy the src one to the dist folder with a simple bash command. However, do you think we should create another export file without the inline CSS? This might be a too advanced optimisation for now so we could only start with just providing the CSS file and document how to use it manually. |
Hmm i have a few options right now that i am considering: Option A: Only export a css file and document how to use it by importing it. (This is definitely a breaking change) Option B: Keeping the inline plus exporting a css file with documentation, but adding a prop to disable the inline (Could not be a breaking change, but could be used as a step towards Option A or permanent) (Exporting could as you suggested just be bash copy/paste) Option C: Only having the inline styles + a prop to disable it, and letting people just copy paste the styles from the src folder into their project. I am most for Option A but that being a breaking change might leave option b as the better choice. |
Thanks for detailing the options :) I'm more in favour of option B for 2 reasons:
|
Added option b now: -Copied the css and rename the file to what ever format bili build system normally would have called a compiled css file.
Missing: some documentation of the prop and how to import the css file |
src/index.tsx
Outdated
@@ -46,6 +46,7 @@ type Props = { | |||
restrictPosition: boolean | |||
initialCroppedAreaPixels?: Area | |||
mediaProps: React.ImgHTMLAttributes<HTMLElement> | React.VideoHTMLAttributes<HTMLElement> | |||
disableDefaultStyles?: boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest: disableAutomaticFileInjection
Changed the name of the props + add some documentation to the readme file, it seems like my code editor change some more of the structure of the file, let me know it you want me to try and revert the formatting |
I'm sorry but I did a mistake when suggesting the name 😬. I wanted to say One thing I thought about yesterday evening is if injecting at the end of the head is not breaking the support of custom classnames passed via props. I need to check. |
Ill update it :), thats fair enough ;) |
Thank you really much! I'm going to publish this as version 3.0.0 as soon as NPM is back: https://status.npmjs.org 😅 |
@allcontributors please add @stefanoruth for code and ideas |
I've put up a pull request to add @stefanoruth! 🎉 |
Release published: https://github.com/ricardo-ch/react-easy-crop/releases/tag/v3.0.0 🎉 |
This i my proposal at the moment to remove emotion, i would very much like to hear what you think about it. :)
It inlines the needed css inside the bundle, and i have added an option to disable the inline css, so people can add it to their own css file, and bundle it the way they want it.
I havent added any test to the new helper function let me know if you want that too,
I would also like to take a look at the tslib, but havent done anything about it yet (not sure if it can make bundle smaller or not yet)
In case of merging you are more than welcome to squash all the commits