2021-03-26 10:56:32 +01:00
|
|
|
import path from "path";
|
2021-06-01 16:03:07 +02:00
|
|
|
import fs from "fs";
|
2021-03-26 10:56:32 +01:00
|
|
|
import svelte from "rollup-plugin-svelte";
|
|
|
|
import cssOnlyRollupPlugin from "rollup-plugin-css-only";
|
|
|
|
import resolve from "@rollup/plugin-node-resolve";
|
|
|
|
import commonjs from "@rollup/plugin-commonjs";
|
|
|
|
import {terser} from "rollup-plugin-terser";
|
|
|
|
import livereloadRollupPlugin from "rollup-plugin-livereload";
|
2021-06-01 16:03:07 +02:00
|
|
|
import scssPlugin from "rollup-plugin-scss";
|
2021-03-26 10:56:32 +01:00
|
|
|
|
|
|
|
const production = process.env.ENV === 'production';
|
|
|
|
const buildDir = process.env.BUILD_DIR;
|
|
|
|
const publicDir = process.env.PUBLIC_DIR;
|
|
|
|
const input = process.env.INPUT.split(':');
|
|
|
|
|
2021-04-27 15:00:43 +02:00
|
|
|
export default commandLineArgs => ({
|
|
|
|
input: input,
|
|
|
|
output: {
|
|
|
|
format: 'es',
|
2021-06-01 16:03:07 +02:00
|
|
|
sourcemap: true,
|
2021-04-27 15:00:43 +02:00
|
|
|
dir: path.join(publicDir, 'js'),
|
|
|
|
entryFileNames: (chunkInfo) => {
|
|
|
|
const name = chunkInfo.facadeModuleId ?
|
|
|
|
path.relative(buildDir, chunkInfo.facadeModuleId) :
|
|
|
|
chunkInfo.name;
|
|
|
|
return name + '.js';
|
2021-03-26 10:56:32 +01:00
|
|
|
},
|
2021-05-04 17:04:14 +02:00
|
|
|
chunkFileNames: '[name].js',
|
2021-04-27 15:00:43 +02:00
|
|
|
},
|
|
|
|
plugins: [
|
2021-06-01 16:03:07 +02:00
|
|
|
scssPlugin({
|
|
|
|
output: function (styles, styleNodes) {
|
|
|
|
if (!fs.existsSync(path.join(publicDir, 'css'))) {
|
|
|
|
fs.mkdirSync(path.join(publicDir, 'css'));
|
|
|
|
}
|
|
|
|
fs.writeFileSync(path.join(publicDir, 'css', 'bundle.css'), styles);
|
|
|
|
for (const node of Object.keys(styleNodes)) {
|
|
|
|
if (node.endsWith('.scss')) {
|
|
|
|
fs.writeFileSync(path.join(publicDir, 'css', path.basename(node, '.scss') + '.css'), styleNodes[node]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
|
2021-04-27 15:00:43 +02:00
|
|
|
svelte({
|
|
|
|
compilerOptions: {
|
|
|
|
dev: !production,
|
|
|
|
hydratable: true,
|
|
|
|
},
|
|
|
|
}),
|
2021-03-26 10:56:32 +01:00
|
|
|
|
2021-04-27 15:00:43 +02:00
|
|
|
// Extract css into separate files
|
|
|
|
cssOnlyRollupPlugin({output: 'bundle.css'}),
|
2021-03-26 10:56:32 +01:00
|
|
|
|
2021-04-27 15:00:43 +02:00
|
|
|
// If you have external dependencies installed from
|
|
|
|
// npm, you'll most likely need these plugins. In
|
|
|
|
// some cases you'll need additional configuration -
|
|
|
|
// consult the documentation for details:
|
|
|
|
// https://github.com/rollup/plugins/tree/master/packages/commonjs
|
|
|
|
resolve({
|
|
|
|
browser: true,
|
|
|
|
dedupe: ['svelte'],
|
|
|
|
}),
|
|
|
|
commonjs(),
|
2021-03-26 10:56:32 +01:00
|
|
|
|
2021-04-27 15:00:43 +02:00
|
|
|
// Live reload in dev
|
2021-05-11 15:08:10 +02:00
|
|
|
!production && !!commandLineArgs.watch && livereloadRollupPlugin(publicDir),
|
2021-03-26 10:56:32 +01:00
|
|
|
|
2021-04-27 15:00:43 +02:00
|
|
|
// Minify in production
|
|
|
|
production && terser(),
|
|
|
|
],
|
|
|
|
watch: {
|
|
|
|
clearScreen: false,
|
|
|
|
},
|
|
|
|
});
|