question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

add an option to not to inline assets in library mode when format is 'es'

See original GitHub issue

Clear and concise description of the problem

Currently when using library mode, all the assets (images, videos…) are inlined using base64. When those assets are big, it takes a long for vite to build, and the browser also takes a long time to parse the javascript.

Suggested solution

When the library format is ‘es’, we can add an option to make vite emit those files, and import those files in javascript using new URL(import.meta.url, '...'), e.g.

import foo from './image.png';

const bar = foo; // new URL(import.meta.url, './assets/image.2d8efhg.png')

Alternative

No response

Additional context

No response

Validations

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:39
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

24reactions
artemtamcommented, Feb 16, 2022

Are there any updates on that? It seems like a very common use-case for libraries – barely anyone wants fonts to be inlined in CSS.

6reactions
g10commented, May 19, 2022

…this works for css…

assets in public folder

public/fonts/Font.otf

in css, ./ dot prefix the path

@font-face {
  src: url("./fonts/Font.otf") format("opentype");
}

in vite.config, build lib with es format

  build: {
    lib: {
      formats: ["es"],
      …
    },
   outDir: "./lib",
   …

the public folder content is copied to lib and paths in css are preserved → no inline assets

package.json

  …
  "files": [
    "lib/*",
    …
  ],
  "exports": {
    ".": {
      "import": "./lib/index.es.js"
    },
    "./style.css": "./lib/style.css"
    …
  },

Read more comments on GitHub >

github_iconTop Results From Across the Web

Build Options
Note: the polyfill does not apply to Library Mode. ... assetsInlineLimit will be ignored and assets will always be inlined, regardless of file...
Read more >
API - ESBuild
If no input files are provided then a single input file is read from stdin. The build API can take the following options:...
Read more >
css-loader | webpack - JS.ORG
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >
Options · Babel
would allow plugins and presets to decide that, since ES modules are supported, ... The filename is optional, but not all of Babel's...
Read more >
Use the Hero web part
If the videos are set up in Hero webpart they will play inline while you can ... If you are not already in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found