151 lines
3.7 KiB
JavaScript
151 lines
3.7 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
const { execSync } = require("child_process");
|
|
import svelte from 'rollup-plugin-svelte';
|
|
import commonjs from '@rollup/plugin-commonjs';
|
|
import resolve from '@rollup/plugin-node-resolve';
|
|
import livereload from 'rollup-plugin-livereload';
|
|
import { terser } from 'rollup-plugin-terser';
|
|
import sveltePreprocess from 'svelte-preprocess';
|
|
import css from 'rollup-plugin-css-only';
|
|
import svg from 'rollup-plugin-svg';
|
|
|
|
const production = !process.env.ROLLUP_WATCH;
|
|
|
|
const buildVersion = execSync("git rev-parse --short HEAD").toString();
|
|
fs.writeFileSync('build-info.js', 'export default ' + JSON.stringify({
|
|
buildDate: (new Date()).toISOString().substr(0, 19).replace('T', ' ') + ' UTC',
|
|
buildVersion
|
|
}))
|
|
|
|
function serve() {
|
|
let server;
|
|
|
|
function toExit() {
|
|
if (server) server.kill(0);
|
|
}
|
|
|
|
return {
|
|
writeBundle() {
|
|
if (server) return;
|
|
server = require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], {
|
|
stdio: ['ignore', 'inherit', 'inherit'],
|
|
shell: true
|
|
});
|
|
|
|
process.on('SIGTERM', toExit);
|
|
process.on('exit', toExit);
|
|
}
|
|
};
|
|
}
|
|
|
|
export default [
|
|
{
|
|
input: 'src/main.js',
|
|
output: {
|
|
sourcemap: true,
|
|
format: 'iife',
|
|
name: 'app',
|
|
file: 'public/build/bundle.js',
|
|
},
|
|
plugins: [
|
|
svelte({
|
|
preprocess: sveltePreprocess({sourceMap: !production}),
|
|
compilerOptions: {
|
|
// enable run-time checks when not in production
|
|
dev: !production,
|
|
},
|
|
}),
|
|
// we'll extract any component CSS out into
|
|
// a separate file - better for performance
|
|
css({output: 'bundle.css'}),
|
|
|
|
svg(),
|
|
|
|
// 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(),
|
|
|
|
// In dev mode, call `npm run start` once
|
|
// the bundle has been generated
|
|
!production && serve(),
|
|
|
|
// Watch the `public` directory and refresh the
|
|
// browser on changes when not in production
|
|
!production && livereload('public'),
|
|
|
|
// If we're building for production (npm run build
|
|
// instead of npm run dev), minify
|
|
production && terser(),
|
|
|
|
{
|
|
name: 'copy-comlink',
|
|
generateBundle() {
|
|
const buildDir = './public/build'
|
|
if (!fs.existsSync(buildDir)){
|
|
fs.mkdirSync(buildDir);
|
|
}
|
|
|
|
fs.copyFileSync(
|
|
path.resolve('./node_modules/comlink/dist/umd/comlink.min.js'),
|
|
path.resolve('./public/build/comlink.min.js'),
|
|
);
|
|
},
|
|
},
|
|
],
|
|
watch: {
|
|
clearScreen: false,
|
|
},
|
|
},
|
|
|
|
{
|
|
input: 'src/workers/stats-worker.js',
|
|
output: {
|
|
sourcemap: true,
|
|
format: 'iife',
|
|
name: 'app',
|
|
file: 'public/build/stats-worker.js',
|
|
},
|
|
plugins: [
|
|
// 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(),
|
|
|
|
// If we're building for production (npm run build
|
|
// instead of npm run dev), minify
|
|
production && terser(),
|
|
{
|
|
name: 'copy-test-worker',
|
|
load() {
|
|
this.addWatchFile(path.resolve('./src/workers/stats-worker.js'));
|
|
},
|
|
generateBundle() {
|
|
const buildDir = './public/build'
|
|
if (!fs.existsSync(buildDir)){
|
|
fs.mkdirSync(buildDir);
|
|
}
|
|
|
|
fs.copyFileSync(
|
|
path.resolve('./src/workers/stats-worker.js'),
|
|
path.resolve('./public/build/stats-worker.js'),
|
|
);
|
|
},
|
|
},
|
|
],
|
|
},
|
|
];
|