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

feat(rollup-plugin-html): resolves assets in styles #2664

Merged
merged 6 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions docs/docs/building/rollup-plugin-html.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,45 @@ export default {
};
```

#### Including assets referenced from css

If your css files reference other assets via `url`, like for example:

```css
body {
background-image: url('images/star.gif');
}

/* or */
@font-face {
src: url('fonts/font-bold.woff2') format('woff2');
/* ...etc */
}
```

You can enable the `bundleAssetsFromCss` option:

```js
rollupPluginHTML({
bundleAssetsFromCss: true,
// ...etc
});
```

And those assets will get output to the `assets/` dir, and the source css file will get updated with the output locations of those assets, e.g.:

```css
body {
background-image: url('assets/star-P4TYRBwL.gif');
}

/* or */
@font-face {
src: url('assets/font-bold-f0mNRiTD.woff2') format('woff2');
/* ...etc */
}
```

### Handling absolute paths

If your HTML file contains any absolute paths they will be resolved against the current working directory. You can set a different root directory in the config. Input paths will be resolved relative to this root directory as well.
Expand Down
220 changes: 209 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/rollup-plugin-html/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"@web/parse5-utils": "^2.1.0",
"glob": "^10.0.0",
"html-minifier-terser": "^7.1.0",
"lightningcss": "^1.24.0",
"parse5": "^6.0.1"
},
"devDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions packages/rollup-plugin-html/src/RollupPluginHTMLOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export interface RollupPluginHTMLOptions {
absolutePathPrefix?: string;
/** When set to true, will insert meta tags for CSP and add script-src values for inline scripts by sha256-hashing the contents */
strictCSPInlineScripts?: boolean;
/** Bundle assets reference from CSS via `url` */
bundleAssetsFromCss?: boolean;
}

export interface GeneratedBundle {
Expand Down
Loading
Loading