mirror of
https://github.com/tenrok/OverlayScrollbars.git
synced 2026-06-17 16:20:35 +03:00
improve rollup build
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
const fs = require('fs');
|
||||
|
||||
module.exports = (files) => ({
|
||||
buildStart() {
|
||||
if (files) {
|
||||
files.forEach((file) => {
|
||||
if (fs.existsSync(file)) {
|
||||
this.addWatchFile(file);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
const { extname } = require('path');
|
||||
const { transform } = require('esbuild');
|
||||
const { createFilter } = require('@rollup/pluginutils');
|
||||
|
||||
const defaultLoader = {
|
||||
'.js': 'js',
|
||||
'.jsx': 'jsx',
|
||||
'.ts': 'ts',
|
||||
'.tsx': 'tsx',
|
||||
};
|
||||
|
||||
module.exports = ({ include, exclude, ...esbuildOptions } = {}) => {
|
||||
const extensions = Object.keys(defaultLoader);
|
||||
const INCLUDE_REGEXP = new RegExp(`\\.(${extensions.map((ext) => ext.slice(1)).join('|')})$`);
|
||||
const EXCLUDE_REGEXP = /node_modules/;
|
||||
const filter = createFilter(include || INCLUDE_REGEXP, exclude || EXCLUDE_REGEXP);
|
||||
|
||||
return {
|
||||
name: 'esbuild',
|
||||
async transform(code, id) {
|
||||
if (!filter(id)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const ext = extname(id);
|
||||
const loader = defaultLoader[ext];
|
||||
|
||||
if (!loader) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const result = await transform(code, {
|
||||
sourcefile: id,
|
||||
loader,
|
||||
...esbuildOptions,
|
||||
});
|
||||
|
||||
return (
|
||||
result.code && {
|
||||
code: result.code,
|
||||
map: result.map || null,
|
||||
}
|
||||
);
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,102 @@
|
||||
const rollupPluginHtml = require('@rollup/plugin-html');
|
||||
|
||||
const makeHtmlAttributes = (attributes) => {
|
||||
if (!attributes) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const keys = Object.keys(attributes);
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
// eslint-disable-next-line no-return-assign
|
||||
return keys.reduce((result, key) => (result += ` ${key}="${attributes[key]}"`), '');
|
||||
};
|
||||
|
||||
const genHtmlTemplateFunc = (contentOrContentFn) => ({
|
||||
attributes,
|
||||
files,
|
||||
meta,
|
||||
publicPath,
|
||||
title,
|
||||
}) => {
|
||||
const scripts = (files.js || [])
|
||||
.map(
|
||||
({ fileName }) =>
|
||||
`<script src="${publicPath}${fileName}"${makeHtmlAttributes(attributes.script)}></script>`
|
||||
)
|
||||
.join('\n');
|
||||
|
||||
const links = (files.css || [])
|
||||
.map(
|
||||
({ fileName }) =>
|
||||
`<link href="${publicPath}${fileName}" rel="stylesheet"${makeHtmlAttributes(
|
||||
attributes.link
|
||||
)}>`
|
||||
)
|
||||
.join('\n');
|
||||
|
||||
const metas = meta.map((input) => `<meta${makeHtmlAttributes(input)}>`).join('\n');
|
||||
|
||||
return `<!doctype html>
|
||||
<html${makeHtmlAttributes(attributes.html)}>
|
||||
<head>
|
||||
${metas}
|
||||
<title>${title}</title>
|
||||
<style>
|
||||
html,
|
||||
body {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
body {
|
||||
padding: 10px;
|
||||
}
|
||||
*::before,
|
||||
*::after {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
* {
|
||||
box-sizing: inherit;
|
||||
}
|
||||
#testResult {
|
||||
display: none;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
right: 0;
|
||||
padding: 5px;
|
||||
background: white;
|
||||
}
|
||||
#testResult.passed {
|
||||
display: block;
|
||||
background: lime;
|
||||
}
|
||||
#testResult.passed::before {
|
||||
content: 'passed';
|
||||
}
|
||||
#testResult.failed {
|
||||
display: block;
|
||||
background: red;
|
||||
}
|
||||
#testResult.failed::before {
|
||||
content: 'failed';
|
||||
}
|
||||
</style>
|
||||
${links}
|
||||
</head>
|
||||
<body>
|
||||
${(typeof contentOrContentFn === 'function' ? contentOrContentFn() : contentOrContentFn) || ''}
|
||||
${scripts}
|
||||
<div id="testResult"></div>
|
||||
</body>
|
||||
</html>`;
|
||||
};
|
||||
|
||||
module.exports = (title, fileName, getHtmlContent) =>
|
||||
rollupPluginHtml({
|
||||
title,
|
||||
fileName,
|
||||
template: genHtmlTemplateFunc(getHtmlContent),
|
||||
meta: [{ charset: 'utf-8' }, { 'http-equiv': 'X-UA-Compatible', content: 'IE=edge' }],
|
||||
});
|
||||
@@ -0,0 +1,33 @@
|
||||
const { createFilter } = require('@rollup/pluginutils');
|
||||
const istanbul = require('istanbul-lib-instrument');
|
||||
|
||||
module.exports = (options = {}) => {
|
||||
const filter = createFilter(options.include, options.exclude);
|
||||
|
||||
return {
|
||||
name: 'istanbul',
|
||||
transform(code, id) {
|
||||
if (!filter(id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const instrumenter = istanbul.createInstrumenter({
|
||||
esModules: true,
|
||||
compact: true,
|
||||
produceSourceMap: true,
|
||||
autoWrap: true,
|
||||
preserveComments: true,
|
||||
...options.instrumenterConfig,
|
||||
});
|
||||
|
||||
const combinedSourceMap = this.getCombinedSourcemap();
|
||||
const instrumentedCode = instrumenter.instrumentSync(code, id, {
|
||||
...combinedSourceMap,
|
||||
version: String(combinedSourceMap.version),
|
||||
});
|
||||
const sourceMap = instrumenter.lastSourceMap();
|
||||
|
||||
return { code: instrumentedCode, map: { ...sourceMap, version: Number(sourceMap.version) } };
|
||||
},
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user