Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	packages/html/src/index.ts
#	packages/html/types/index.d.ts
  • Loading branch information
shellscape committed Dec 15, 2024
2 parents 78a92f5 + 8670bdb commit 0258081
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 28 deletions.
8 changes: 8 additions & 0 deletions packages/html/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @rollup/plugin-html ChangeLog

## v1.0.5

_2024-12-15_

### Bugfixes

- fix: types for plugin (#1264)

## v1.0.4

_2024-09-22_
Expand Down
14 changes: 7 additions & 7 deletions packages/html/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ Once run successfully, an HTML file should be written to the bundle output desti

## Options

### `addScriptsToHead`

Type: `Boolean`<br>
Default: `false`

Place scripts in the `<head>` tag instead of `<body>`.

### `attributes`

Type: `Object`<br>
Expand Down Expand Up @@ -121,13 +128,6 @@ Default: `'Rollup Bundle'`

Specifies the HTML document title.

### `scriptsOnHead`

Type: `Boolean`<br>
Default: `false`

Place scripts in head instead body.

## Exports

### `makeHtmlAttributes(attributes)`
Expand Down
2 changes: 1 addition & 1 deletion packages/html/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rollup/plugin-html",
"version": "1.0.4",
"version": "1.0.5",
"publishConfig": {
"access": "public"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/html/recipes/external-files/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @return {Function} The template method required by plugin-html
*/
export default function htmlTemplate(externals) {
return ({ attributes, files, meta, publicPath, title, scriptsOnHead }) => {
return ({ attributes, files, meta, publicPath, title, addScriptsToHead }) => {
let scripts = [...(files.js || [])];
let links = [...(files.css || [])];

Expand Down Expand Up @@ -43,7 +43,7 @@ export default function htmlTemplate(externals) {
})
.join('\n');

if (scriptsOnHead === true) {
if (addScriptsToHead === true) {
links += scripts;
scripts = '';
}
Expand Down
22 changes: 12 additions & 10 deletions packages/html/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const defaultTemplate = async ({
meta,
publicPath,
title,
scriptsOnHead
addScriptsToHead
}: RollupHtmlTemplateOptions) => {
let scripts = (files.js || [])
.map(({ fileName }) => {
Expand All @@ -48,7 +48,7 @@ const defaultTemplate = async ({
})
.join('\n');

if (scriptsOnHead === true) {
if (addScriptsToHead === true) {
links += scripts;
scripts = '';
}
Expand Down Expand Up @@ -76,7 +76,7 @@ const defaultTemplate = async ({

const supportedFormats = ['es', 'esm', 'iife', 'umd'];

const defaults = {
const defaults: Required<RollupHtmlOptions> = {
attributes: {
link: null,
html: { lang: 'en' },
Expand All @@ -87,15 +87,17 @@ const defaults = {
publicPath: '',
template: defaultTemplate,
title: 'Rollup Bundle',
scriptsOnHead: false
addScriptsToHead: false
};

export default function html(opts: RollupHtmlOptions = {}): Plugin {
const { attributes, fileName, meta, publicPath, template, title, scriptsOnHead } = Object.assign(
{},
defaults,
opts
);
// const { attributes, fileName, meta, publicPath, template, title, addScriptsToHead } = Object.assign(
// {},
// defaults,
// opts
// );
const { attributes, fileName, meta, publicPath, template, title }: Required<RollupHtmlOptions> =
Object.assign({}, defaults, opts);

return {
name: 'html',
Expand Down Expand Up @@ -125,7 +127,7 @@ export default function html(opts: RollupHtmlOptions = {}): Plugin {
meta,
publicPath,
title,
scriptsOnHead
addScriptsToHead
});

const htmlFile: EmittedAsset = {
Expand Down
2 changes: 1 addition & 1 deletion packages/html/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ test.serial('scripts on head', async (t) => {
attributes: {
script: { defer: true }
},
scriptsOnHead: true
addScriptsToHead: true
})
]
});
Expand Down
14 changes: 7 additions & 7 deletions packages/html/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import type { Plugin, OutputChunk, OutputAsset, OutputBundle } from 'rollup';

export interface RollupHtmlTemplateOptions {
title: string;
addScriptsToHead?: boolean;
attributes: Record<string, any>;
publicPath: string;
meta: Record<string, any>[];
bundle: OutputBundle;
files: Record<string, (OutputChunk | OutputAsset)[]>;
scriptsOnHead?: boolean;
meta: Record<string, any>[];
publicPath: string;
title: string;
}

export interface RollupHtmlOptions {
title?: string;
addScriptsToHead?: boolean;
attributes?: Record<string, any>;
fileName?: string;
meta?: Record<string, any>[];
publicPath?: string;
template?: (templateoptions: RollupHtmlTemplateOptions) => string;
scriptsOnHead?: boolean;
template?: (templateoptions: RollupHtmlTemplateOptions) => string | Promise<string>;
title?: string;
}

export function makeHtmlAttributes(attributes: Record<string, string>): string;
Expand Down

0 comments on commit 0258081

Please sign in to comment.