CCNA_Learning/rollup.config.js
2019-09-11 15:07:12 +02:00

95 lines
2.4 KiB
JavaScript

// import * as rollup from "rollup";
import svelteplg from 'rollup-plugin-svelte';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import typescript from "rollup-plugin-typescript2";
import rjson from "rollup-plugin-json";
import * as fs from "fs";
import {
terser
} from 'rollup-plugin-terser';
const production = process.argv.indexOf("-d") < 0;
console.log(`Runnig in ${production ? "production" : "development"} mode!`);
let plg = [];
if (production) {
plg.push(terser())
}
if (!fs.existsSync("build"))
fs.mkdirSync("build");
fs.copyFileSync("src/index.html", "build/index.html");
export default {
input: `./src/main.ts`,
output: {
sourcemap: true,
format: 'iife',
name: 'app',
file: `build/bundle.js`
},
watch: {
clearScreen: false
},
plugins: [
cssStringPlugin({
include: [
"@hibas123/theme/out/base.css",
"@hibas123/theme/out/light.css",
"@hibas123/theme/out/dark.css"
]
}),
// svgSveltePlugin(),
resolve({
browser: true
}),
typescript({
tsconfig: "./src/tsconfig.json"
}),
svelteplg({
// enable run-time checks when not in production
dev: !production,
extensions: [".svg", ".svelte"],
css: css => {
css.write(`build/bundle.css`);
}
}),
commonjs({
namedExports: {
"node_modules/js-sha256/src/sha256.js": ["sha256"],
"node_modules/aes-js/index.js": ["ModeOfOperation"]
}
}),
rjson(),
...plg
]
};
import * as path from "path";
function cssStringPlugin({
include
}) {
return {
name: 'css-to-string', // this name will show up in warnings and errors
resolveId(source) {
if (include.indexOf(source) >= 0)
return source;
return null; // other ids should be handled as usually
},
load(id) {
if (include.indexOf(id) >= 0) {
const p = "./node_modules/" + id;
let r = `export default ${JSON.stringify(fs.readFileSync(p).toString("utf-8")).replace("'", "\'")}`;
return r;
}
return null;
}
};
}