forked from OpenServer/OpenAuth_views
119 lines
3.2 KiB
JavaScript
119 lines
3.2 KiB
JavaScript
|
const svelte = require("rollup-plugin-svelte");
|
||
|
const typescript = require("@rollup/plugin-typescript");
|
||
|
const { terser } = require("rollup-plugin-terser");
|
||
|
const html = require("@rollup/plugin-html");
|
||
|
const resolve = require("rollup-plugin-node-resolve");
|
||
|
const image = require("@rollup/plugin-image");
|
||
|
const sizes = require("rollup-plugin-sizes");
|
||
|
const visualise = require("rollup-plugin-visualizer");
|
||
|
const postcss = require("rollup-plugin-postcss");
|
||
|
const commonjs = require("@rollup/plugin-commonjs");
|
||
|
const livereload = require("rollup-plugin-livereload");
|
||
|
|
||
|
const { preprocess } = require("./svelte.config");
|
||
|
|
||
|
const VIEWS = ["Home", "Login", "Popup", "User"];
|
||
|
|
||
|
const dev = process.env.NODE_ENV !== "production";
|
||
|
|
||
|
const htmlTemplate = ({ attributes, meta, files, publicPath, title }) => {
|
||
|
const 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]}"`),
|
||
|
""
|
||
|
);
|
||
|
};
|
||
|
const scripts = (files.js || [])
|
||
|
.map(({ fileName }) => {
|
||
|
const attrs = makeHtmlAttributes(attributes.script);
|
||
|
return `<script src="${publicPath}${fileName}"${attrs}></script>`;
|
||
|
})
|
||
|
.join("\n");
|
||
|
|
||
|
const links = (files.css || [])
|
||
|
.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>
|
||
|
<link rel="stylesheet" href="bundle.css"/>
|
||
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto"/>
|
||
|
${links}
|
||
|
</head>
|
||
|
<body>
|
||
|
${scripts}
|
||
|
</body>
|
||
|
</html>`;
|
||
|
};
|
||
|
|
||
|
export default VIEWS.map((view) => ({
|
||
|
input: `src/pages/${view}/main.ts`,
|
||
|
output: [
|
||
|
dev
|
||
|
? {
|
||
|
file: `build/${view}/bundle.js`,
|
||
|
format: "iife",
|
||
|
sourcemap: true,
|
||
|
name: view,
|
||
|
}
|
||
|
: {
|
||
|
file: `build/${view}/bundle.min.js`,
|
||
|
format: "iife",
|
||
|
name: view,
|
||
|
plugins: [terser()],
|
||
|
},
|
||
|
],
|
||
|
plugins: [
|
||
|
commonjs(),
|
||
|
svelte({
|
||
|
emitCss: true,
|
||
|
preprocess,
|
||
|
}),
|
||
|
typescript({ sourceMap: dev, inlineSources: dev }),
|
||
|
html({
|
||
|
attributes: {
|
||
|
html: { lang: "en" },
|
||
|
},
|
||
|
meta: [
|
||
|
{
|
||
|
name: "viewport",
|
||
|
content: "width=device-width",
|
||
|
},
|
||
|
],
|
||
|
template: htmlTemplate,
|
||
|
}),
|
||
|
resolve({ browser: true, dedupe: ["svelte"] }),
|
||
|
image(),
|
||
|
sizes(),
|
||
|
visualise({
|
||
|
filename: `build/stats/${view}.html`,
|
||
|
title: `Rullup bundle for ${view}`,
|
||
|
}),
|
||
|
postcss({
|
||
|
extract: `bundle.css`, //TODO: Check if it should be enabled
|
||
|
// inject: true,
|
||
|
}),
|
||
|
// dev && livereload(),
|
||
|
],
|
||
|
}));
|