text: import svelte from 'rollup-plugin-svelte';
  import resolve from '@rollup/plugin-node-resolve';
  import livereload from 'rollup-plugin-livereload';
  import { terser } from 'rollup-plugin-terser';
  import css from 'rollup-plugin-css-only';
  import sveltePreprocess from 'svelte-preprocess';
  import typescript from '@rollup/plugin-typescript';
  
  const production = !process.env.ROLLUP_WATCH;
  
  const cssHash = ({ hash, css, name, filename }) => {
  	// console.log({ filename, name });
  	return `d${hash(filename)}`;
  };
  
  function serve() {
  	let server;
  
  	function toExit() {
  		if (server) server.kill(0);
  	}
  
  	return {
  		writeBundle() {
  			if (server) return;
  			server = require('child_process').spawn(
  				'yarn',
  				['preview', '--', '--dev'],
  				{
  					stdio: ['ignore', 'inherit', 'inherit'],
  					shell: true,
  				}
  			);
  
  			process.on('SIGTERM', toExit);
  			process.on('exit', toExit);
  		},
  	};
  }
  
  /**
   * @type {import('rollup').RollupOptions}
   */
  export default [
  	// Module Mode, allows for lazy loading
  	// if browser doesnt support modules, this will fail to load
  	{
  		input: 'src/index.ts',
  		output: {
  			sourcemap: !production,
  			format: 'es',
  			dir: 'public/build/',
  			entryFileNames: 'index.js',
  			chunkFileNames: '[hash].js',
  		},
  		preserveEntrySignatures: true,
  		plugins: [
  			svelte({
  				preprocess: sveltePreprocess({
  					sourceMap: !production,
  					scss: {
  						prependData: "@import 'src/_common_vars.scss';\n\n",
  					},
  					typescript: {
  						
  					}
  				}),
  				compilerOptions: {
  					// enable run-time checks when not in production
  					dev: !production,
  
  					// custom HASH
  					cssHash,
  				},
  			}),
  			// we'll extract any component CSS out into
  			// a separate file - better for performance
  			css({ output: 'bundle.css' }),
  
  			// 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'],
  			}),
  			typescript({ sourceMap: !production, inlineSources: !production }),
  
  			,
  			// 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({
  					format: {
  						comments: false,
  					},
  					compress: {
  						booleans_as_integers: true,
  						passes: 2,
  						unsafe_math: true,
  					},
  				}),
  		],
  		watch: {
  			clearScreen: false,
  		},
  	},
  	// iife
  	// if the browser doesn't support modules (fuck IE), this will be loaded
  	// if the browser does support modules, this will be ignored thanks to the `nomodule` attribute of its script tag
  	// doesnt support lazy loading
  	{
  		input: 'src/index.ts',
  		output: {
  			file: 'public/build/nomodule.js',
  			format: 'iife',
  			inlineDynamicImports: true,
  
  			exports: 'auto',
  			sourcemap: !production,
  		},
  
  		plugins: [
  			svelte({
  				preprocess: sveltePreprocess({
  					sourceMap: !production,
  					scss: {
  						prependData: "@import 'src/_common_vars.scss';\n\n",
  					},
  				}),
  				compilerOptions: {
  					// enable run-time checks when not in production
  					dev: !production,
  					cssHash,
  				},
  			}),
  			// we'll extract any component CSS out into
  			// a separate file - better for performance
  			css({ output: false }),
  
  			// 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'],
  			}),
  			typescript({ sourceMap: !production, inlineSources: !production }),
  
  			// 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({
  					format: {
  						comments: false,
  						safari10: true,
  					},
  					compress: {
  						booleans_as_integers: true,
  						passes: 2,
  						unsafe_math: true,
  					},
  					mangle: {
  						safari10: true,
  					},
  				}),
  		],
  		watch: {
  			clearScreen: false,
  		},
  	},
  ];