Skip to content
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

[Question] What's the best way to bundle fonts with CSS? #2790

Closed
ayushmanchhabra opened this issue Jan 3, 2023 · 4 comments
Closed

[Question] What's the best way to bundle fonts with CSS? #2790

ayushmanchhabra opened this issue Jan 3, 2023 · 4 comments

Comments

@ayushmanchhabra
Copy link

ayushmanchhabra commented Jan 3, 2023

Here's a minimal repro illustrating what I've tried to do:
https://github.com/tharatau/idea-maze/tree/main/repro/esbuild/2790

When I run npm start, I get this error:

npm start

> start
> node build.mjs

✘ [ERROR] Cannot import "icomoon.eot" into a CSS file

    src.css:1:8:
      1 │ @import "./icomoon.eot";~~~~~~~~~~~~~~~

/home/ayushmxn/tharatau/idea-maze/repro/esbuild/2787/node_modules/esbuild/lib/main.js:1596
  let error = new Error(`${text}${summary}`);
              ^

Error: Build failed with 1 error:
src.css:1:8: ERROR: Cannot import "icomoon.eot" into a CSS file
    at failureErrorWithLog (/home/ayushmxn/tharatau/idea-maze/repro/esbuild/2787/node_modules/esbuild/lib/main.js:1596:15)
    at /home/ayushmxn/tharatau/idea-maze/repro/esbuild/2787/node_modules/esbuild/lib/main.js:1052:28
    at /home/ayushmxn/tharatau/idea-maze/repro/esbuild/2787/node_modules/esbuild/lib/main.js:997:67
    at buildResponseToResult (/home/ayushmxn/tharatau/idea-maze/repro/esbuild/2787/node_modules/esbuild/lib/main.js:1050:7)
    at /home/ayushmxn/tharatau/idea-maze/repro/esbuild/2787/node_modules/esbuild/lib/main.js:1162:14
    at responseCallbacks.<computed> (/home/ayushmxn/tharatau/idea-maze/repro/esbuild/2787/node_modules/esbuild/lib/main.js:697:9)
    at handleIncomingPacket (/home/ayushmxn/tharatau/idea-maze/repro/esbuild/2787/node_modules/esbuild/lib/main.js:752:9)
    at Socket.readFromStdout (/home/ayushmxn/tharatau/idea-maze/repro/esbuild/2787/node_modules/esbuild/lib/main.js:673:7)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:324:12) {
  errors: [
    {
      detail: undefined,
      id: '',
      location: {
        column: 8,
        file: 'src.css',
        length: 15,
        line: 1,
        lineText: '@import "./icomoon.eot";',
        namespace: '',
        suggestion: ''
      },
      notes: [],
      pluginName: '',
      text: 'Cannot import "icomoon.eot" into a CSS file'
    }
  ],
  warnings: []
}

Node.js v18.12.1
@ayushmanchhabra ayushmanchhabra changed the title [Question] What's the best way to import fonts in CSS? [Question] What's the best way to bundle fonts with CSS? Jan 3, 2023
@hyrious
Copy link

hyrious commented Jan 4, 2023

The best way is using @font-face and url(./icomoon.eot) to link fonts into your css file. See an example in katex:
https://unpkg.com/katex@0.16.4/dist/katex.css

@ayushmanchhabra
Copy link
Author

ayushmanchhabra commented Jan 4, 2023

Reason I asked is because I used a similar approach using an earlier minor version of esbuild and I remember it working for me:

./out/index.css
./out/icomoon-shj2hdbkqibevd.eot

With a similar folder structure^

@evanw
Copy link
Owner

evanw commented Jan 4, 2023

There are two ways to reference another file in CSS: @import and url(). You are trying to use @import but you should have used url(). You can only use @import with other CSS files while you can use url() with many asset types.

@ayushmanchhabra
Copy link
Author

Gotcha! Thanks @hyrious @evanw

evanw added a commit that referenced this issue Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants