Snowpack won't include referenced font files in CSS #1573
Replies: 10 comments 19 replies
-
You're right! We have find support for importing individual CSS files ( Someone shared an npm package a while back that let you scan the imports of a CSS file. I think the enhancement here would be to scan every imported CSS file for imports & url references, and then include them in the website build. |
Beta Was this translation helpful? Give feedback.
-
What also seems to work for us, although it is a bit hacky, is mounting the files directly from node_modules, e.g.: mount: {
public: {url: '/', static: true},
src: {url: '/dist'},
'node_modules/@fontsource/roboto/files': '/files',
}, This is just for dev mode though, they still need to be packaged during build. Is there a way to do something similar during build? |
Beta Was this translation helpful? Give feedback.
-
@FredKSchott Talked about using Problem is that |
Beta Was this translation helpful? Give feedback.
-
@FredKSchott how do we get this turned into a prioritized issue to get it added? This is a pretty crucial missing feature. I am willing to do a PR myself if someone can point me in the right direction... Can you share the name of the package you mentioned that allows scanning the imports of a CSS file? |
Beta Was this translation helpful? Give feedback.
-
That "snowpack-plugin-relative-css-urls" plugin looks promising, but I can't figure out why it's not working for me. Is it working for anybody else? With snowpack 3, in build mode I'm still getting:
I'm using https://github.com/fontsource/fontsource, aka "Self-host Open Source fonts in neatly bundled NPM packages."
I had hoped the plugin would resolve these relative paths, but they are still relative in |
Beta Was this translation helpful? Give feedback.
-
Same issue for element-plus UI framework. |
Beta Was this translation helpful? Give feedback.
-
Sorry that you all are running into this issue! You're right, npm packages are built into JS and while we have support for CSS inside of those packages, it looks like url references aren't being followed. esinstall (our package bundler) should really support this, if anyone has some links for the best way to support font files in Rollup that would be great. Otherwise, your best bet is moving the package into a |
Beta Was this translation helpful? Give feedback.
-
This is an abomination but I've been able to get Fontsource imports working (#1573 (reply in thread)) using @snowpack/plugin-run-script. The goal is to create a directory structure inside In // Path to where Snowpack thinks the files should be found
const dirPath = "files"
// Template path to where the required files are actually found
const fontPath = "node_modules/@fontsource/roboto/files/roboto-all-$weight-normal.$ext"
module.exports = {
plugins: [
[
"@snowpack/plugin-run-script",
{
name: "Copy Fontsource fonts (snowpackjs/snowpack#1573)",
cmd: [
`mkdir -p build/${dirPath}`,
...[
fontPath.replace("$weight", "400").replace("$ext", "woff"),
fontPath.replace("$weight", "400").replace("$ext", "woff2"),
fontPath.replace("$weight", "700").replace("$ext", "woff"),
fontPath.replace("$weight", "700").replace("$ext", "woff2")
].map(filePath => `cp ${filePath} build/${dirPath}`)
].join(" && ")
}
],
// other plugins
],
// other config
} You will obviously need to construct another After doing this you don't need to change your CSS imports - I am pretty sure the files need to be copied into Provided that EDIT: This doesn't work on CI - no idea why. I'm going back to Webpack |
Beta Was this translation helpful? Give feedback.
-
+1 on prioritizing getting this working |
Beta Was this translation helpful? Give feedback.
-
nothing new on this point for make our code more accurate .. Silence ... same for the problem on sourcemaps ... |
Beta Was this translation helpful? Give feedback.
-
I noticed when trying to host material-icons from respective npm package, along with any other package that uses font files, Snowpack does not include these files referenced in CSS.
For example:
From the code above,
MaterialIcons-Regular.eot
andMaterialIcons-Regular.ttf
aren't included in either production build, or dev build. I saw a very similar issue referenced in #389. I set up postcss as mentioned, but had no success with it. Any help, advice, or guidance would be greatly appreciated!Beta Was this translation helpful? Give feedback.
All reactions