How to use css from node_modules? #2120
Unanswered
pschyska
asked this question in
Troubleshooting
Replies: 1 comment
-
I just stumbled over this as well. My current workaround is to do
This is quite some overkill (especially if you try to webpack this for production), but it salvages at least the broken CSS. Fonts etc. are of course still broken. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to use
@patternfly/react-core
with snowpack, which includes css and assets that I need to include.Just importing the css doesn't work
In dev, snowpack doesn't install any referenced assets, and I didn't find a way to make it. The css references some images and a lot of font files via
url("./assets/...
. The files are all present innode_modules/@patternfly/react-core/dist/styles/assets/
, but are neither installed to .cache/snowpack/development:... and in build none of the files end up in build/.
I think this use case is common enough that it should "just work" and it's a bug that the install step doesn't install dist/styles/assets/ etc. pp. Just copying the package to .cache/build/web_modules as-is would do it probably, and the bundler downstream (optimize/esbuild for now in my case) would do the right thing with the assets (rebasing, inlining or whatever). The way it is now the bundler has no chance to resolve
./assets
, because the imported file has already been rebased to build/web_modules/@patternfly/react-core/dist/styles/base.css without pulling through the referenced resources.I went through multiple iterations of trying to get it to work somehow but didn't find a way.
When I mount /assets like this:
It seems to work in dev, but break for build. /assets is not copied into /build, and then the esbuild step fails because the .css still references ./assets which would be somewhere in /build. I think this is another bug, if a mounted directory is specified, the contents should surely end up in build/ somewhere? I can't imagine a use-case where you wouldn't want that.
I tried to use import aliases, but these don't seem to take effect for
url()
. I tried to do things myself with postcss, but didn't get it to work either.Even importing the file directly in src/index.css as
../node_modules/@patternfly/react-core/dist/styles/base.css
doesn't work!Snowpack tries to find it in two nonsensical locations:
... but not in the path I gave it: /home/p/projects/effective-javascript/src/../node_modules/@patternfly/react-core/dist/styles/base.css
I tried to understand what
webDependencies
,install
, orinstallOptions
exactly do, but couldn't from the documentation.Making a symlink in public/ to
../node_modules/@patternfly/react-core/dist/styles
(the "brute-force" solution...) only works in dev, however when building esbuild throws hundreds of errors like this:While the file does in fact exist, in public/styles/assets/..., and also in build/:
(Is this maybe related to the change in cwd behaviour of esbuild that popped up lately @FredKSchott ?)
So not even copying everything into public/ seems to work? What am I doing wrong?
Beta Was this translation helpful? Give feedback.
All reactions