chore: update for node 20 LTS
This commit is contained in:
parent
5d2a45ef81
commit
5c1e528304
55
package.json
55
package.json
@ -12,7 +12,7 @@
|
|||||||
"bugs": "https://git.cerxes.net/rollup-apps/plugin-html/issues",
|
"bugs": "https://git.cerxes.net/rollup-apps/plugin-html/issues",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=20"
|
||||||
},
|
},
|
||||||
"main": "dist/es/index.js",
|
"main": "dist/es/index.js",
|
||||||
"module": "./dist/es/index.js",
|
"module": "./dist/es/index.js",
|
||||||
@ -30,8 +30,8 @@
|
|||||||
"ci:coverage": "nyc pnpm test && nyc report --reporter=text-lcov > coverage.lcov",
|
"ci:coverage": "nyc pnpm test && nyc report --reporter=text-lcov > coverage.lcov",
|
||||||
"ci:lint": "pnpm build && pnpm lint-staged",
|
"ci:lint": "pnpm build && pnpm lint-staged",
|
||||||
"ci:test": "pnpm test -- --verbose",
|
"ci:test": "pnpm test -- --verbose",
|
||||||
"test": "ava",
|
"test": "NODE_OPTIONS='--import tsx' ava",
|
||||||
"save-test": "ava --update-snapshots"
|
"save-test": "NODE_OPTIONS='--import tsx' ava --update-snapshots"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
@ -55,33 +55,33 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@rollup/pluginutils": "^5.0.1",
|
"@rollup/pluginutils": "^5.0.5",
|
||||||
"parse5": "^7.1.2",
|
"magic-string": "^0.30.5",
|
||||||
"magic-string": "^0.30.0"
|
"parse5": "^7.1.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^18.15.11",
|
"@babel/core": "^7.23.3",
|
||||||
"@rollup/plugin-typescript": "^11.1.0",
|
"@babel/plugin-syntax-import-assertions": "^7.23.3",
|
||||||
"postcss": "^8.4.22",
|
"@babel/preset-typescript": "^7.23.3",
|
||||||
"rollup": "^3.20.3",
|
"@rollup/plugin-babel": "^6.0.4",
|
||||||
"rollup-plugin-postcss": "^4.0.2",
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
||||||
"typescript": "^5.0.4",
|
"@rollup/plugin-typescript": "^11.1.5",
|
||||||
"del-cli": "^5.0.0",
|
"@rollup/plugin-url": "^8.0.2",
|
||||||
"tslib": "^2.5.0",
|
"@types/node": "^18.18.12",
|
||||||
"ava": "^5.2.0",
|
"ava": "^5.3.1",
|
||||||
"ts-node": "^10.9.1",
|
"chalk": "^5.3.0",
|
||||||
"@babel/core": "^7.21.4",
|
"del-cli": "^5.1.0",
|
||||||
"@babel/plugin-syntax-import-assertions": "^7.20.0",
|
"handlebars": "^4.7.8",
|
||||||
"@rollup/plugin-babel": "^6.0.3",
|
"lint-staged": "^13.3.0",
|
||||||
"@rollup/plugin-node-resolve": "^15.0.2",
|
|
||||||
"rollup-plugin-delete": "^2.0.0",
|
|
||||||
"@babel/preset-typescript": "^7.21.4",
|
|
||||||
"nyc": "^15.1.0",
|
"nyc": "^15.1.0",
|
||||||
"lint-staged": "^13.2.1",
|
"postcss": "^8.4.31",
|
||||||
"handlebars": "^4.7.7",
|
"rollup": "^3.29.4",
|
||||||
"@rollup/plugin-url": "^8.0.1",
|
"rollup-plugin-delete": "^2.0.0",
|
||||||
"chalk": "^5.2.0",
|
"rollup-plugin-livereload": "^2.0.5",
|
||||||
"rollup-plugin-livereload": "^2.0.5"
|
"rollup-plugin-postcss": "^4.0.2",
|
||||||
|
"tslib": "^2.6.2",
|
||||||
|
"tsx": "^4.4.0",
|
||||||
|
"typescript": "^5.3.2"
|
||||||
},
|
},
|
||||||
"types": "./types/index.d.ts",
|
"types": "./types/index.d.ts",
|
||||||
"ava": {
|
"ava": {
|
||||||
@ -98,7 +98,6 @@
|
|||||||
"js": true
|
"js": true
|
||||||
},
|
},
|
||||||
"nodeArguments": [
|
"nodeArguments": [
|
||||||
"--loader=ts-node/esm",
|
|
||||||
"--experimental-vm-modules"
|
"--experimental-vm-modules"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
1705
pnpm-lock.yaml
generated
1705
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1,64 +0,0 @@
|
|||||||
This method provides the ability to reference external css/js files for the generated html, and supports adjusting the file loading sequence.
|
|
||||||
|
|
||||||
when using it:
|
|
||||||
|
|
||||||
```js
|
|
||||||
import html from '@rollup/plugin-html';
|
|
||||||
import templateExternalFiles from '@rollup/plugin-html/recipes/external-files';
|
|
||||||
import postcss from 'rollup-plugin-postcss';
|
|
||||||
|
|
||||||
export default [
|
|
||||||
{
|
|
||||||
input: ['demo/demo.ts'],
|
|
||||||
output: [{ file: 'dist/demo.js' }],
|
|
||||||
plugins: [
|
|
||||||
postcss({
|
|
||||||
extract: 'demo.css',
|
|
||||||
minimize: false,
|
|
||||||
use: ['sass'],
|
|
||||||
extensions: ['.scss', '.css']
|
|
||||||
}),
|
|
||||||
html({
|
|
||||||
title: 'sdk demo page',
|
|
||||||
publicPath: './',
|
|
||||||
fileName: 'demo.html',
|
|
||||||
attributes: { html: { lang: 'zh-cn' } },
|
|
||||||
template: templateExternalFiles([
|
|
||||||
{ type: 'js', file: 'example1.js', pos: 'before' },
|
|
||||||
{ type: 'js', file: 'example2.js', pos: 'before' },
|
|
||||||
{ type: 'js', file: 'example3.js' },
|
|
||||||
{ type: 'js', file: 'example4.js', pos: 'before' },
|
|
||||||
{ type: 'css', file: 'example1.css', pos: 'before' },
|
|
||||||
{ type: 'css', file: 'example2.css', pos: 'before' },
|
|
||||||
{ type: 'css', file: 'example3.css' },
|
|
||||||
{ type: 'css', file: 'example4.css', pos: 'before' }
|
|
||||||
])
|
|
||||||
})
|
|
||||||
]
|
|
||||||
}
|
|
||||||
];
|
|
||||||
```
|
|
||||||
|
|
||||||
The content of the generated html file:
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="zh-cn">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8" />
|
|
||||||
<title>sdk demo page</title>
|
|
||||||
<link href="./example1.css" rel="stylesheet" />
|
|
||||||
<link href="./example2.css" rel="stylesheet" />
|
|
||||||
<link href="./example4.css" rel="stylesheet" />
|
|
||||||
<link href="./demo.css" rel="stylesheet" />
|
|
||||||
<link href="./example3.css" rel="stylesheet" />
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<script src="./example1.js"></script>
|
|
||||||
<script src="./example2.js"></script>
|
|
||||||
<script src="./example4.js"></script>
|
|
||||||
<script src="./demo.js"></script>
|
|
||||||
<script src="./example3.js"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
@ -1,76 +0,0 @@
|
|||||||
/**
|
|
||||||
* Provides the ability to reference external css/js files for the generated html
|
|
||||||
* Method source once issues: https://github.com/rollup/plugins/issues/755
|
|
||||||
* @param {Array} externals List of external files.
|
|
||||||
* The format is: [{ type: 'js', file: '//xxxx1.js', pos: 'before' }, { type: 'css', file: '//xxxx1.css' }]
|
|
||||||
*
|
|
||||||
* @return {Function} The templae method required by plugin-html
|
|
||||||
*/
|
|
||||||
export default function htmlTemplate(externals) {
|
|
||||||
return ({ attributes, files, meta, publicPath, title }) => {
|
|
||||||
let scripts = [...(files.js || [])];
|
|
||||||
let links = [...(files.css || [])];
|
|
||||||
|
|
||||||
// externals = [{ type: 'js', file: '//xxxx1.js', pos: 'before' }, { type: 'css', file: '//xxxx1.css' }]
|
|
||||||
if (Array.isArray(externals)) {
|
|
||||||
const beforeLinks = [];
|
|
||||||
const beforeScripts = [];
|
|
||||||
externals.forEach((node) => {
|
|
||||||
let fileList;
|
|
||||||
const isCssFile = node.type === 'css';
|
|
||||||
if (node.pos === 'before') {
|
|
||||||
fileList = isCssFile ? beforeLinks : beforeScripts;
|
|
||||||
} else {
|
|
||||||
fileList = isCssFile ? links : scripts;
|
|
||||||
}
|
|
||||||
fileList.push({ fileName: node.file });
|
|
||||||
});
|
|
||||||
scripts = beforeScripts.concat(scripts);
|
|
||||||
links = beforeLinks.concat(links);
|
|
||||||
}
|
|
||||||
|
|
||||||
scripts = scripts
|
|
||||||
.map(({ fileName }) => {
|
|
||||||
const attrs = makeHtmlAttributes(attributes.script);
|
|
||||||
return `<script src="${publicPath}${fileName}"${attrs}></script>`;
|
|
||||||
})
|
|
||||||
.join('\n');
|
|
||||||
|
|
||||||
links = links
|
|
||||||
.map(({ fileName }) => {
|
|
||||||
const attrs = makeHtmlAttributes(attributes.link);
|
|
||||||
return `<link href="${publicPath}${fileName}" rel="stylesheet"${attrs}>`;
|
|
||||||
})
|
|
||||||
.join('\n');
|
|
||||||
|
|
||||||
const metas = meta
|
|
||||||
.map((input) => {
|
|
||||||
const attrs = makeHtmlAttributes(input);
|
|
||||||
return `<meta${attrs}>`;
|
|
||||||
})
|
|
||||||
.join('\n');
|
|
||||||
|
|
||||||
return `
|
|
||||||
<!doctype html>
|
|
||||||
<html${makeHtmlAttributes(attributes.html)}>
|
|
||||||
<head>
|
|
||||||
${metas}
|
|
||||||
<title>${title}</title>
|
|
||||||
${links}
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
${scripts}
|
|
||||||
</body>
|
|
||||||
</html>`;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function makeHtmlAttributes(attributes) {
|
|
||||||
if (!attributes) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
const keys = Object.keys(attributes);
|
|
||||||
// eslint-disable-next-line no-param-reassign
|
|
||||||
return keys.reduce((result, key) => (result += ` ${key}="${attributes[key]}"`), '');
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user