github.com/Theta-Dev/Talon@v0.0.0-20211018130634-ff179e19fa9a/ui/menu/rollup.config.js (about)

     1  /*
     2  This configuration was taken from stefanonepa's project template
     3  Copyright (c) 2021 stefanonepa, MIT License
     4  https://github.com/stefanonepa/svelte-component-ts
     5   */
     6  
     7  import svelte from "rollup-plugin-svelte"
     8  import commonjs from "@rollup/plugin-commonjs"
     9  import resolve from "@rollup/plugin-node-resolve"
    10  import livereload from "rollup-plugin-livereload"
    11  import {terser} from "rollup-plugin-terser"
    12  import sveltePreprocess from "svelte-preprocess"
    13  import typescript from "@rollup/plugin-typescript"
    14  import replace from "@rollup/plugin-replace"
    15  import babel from "@rollup/plugin-babel"
    16  
    17  import css from ".rollup/css-only"
    18  import {serve} from ".rollup/serve"
    19  import includeSass from ".rollup/includeSass"
    20  import htmlMinifier from ".rollup/htmlMinifier"
    21  
    22  const production = !process.env.ROLLUP_WATCH
    23  const version = process.env.VERSION || "INDEV"
    24  
    25  const bundleName = "talon"
    26  const bundleFile = `${bundleName}.js`
    27  const bundleDir = production ? "dist" : "public"
    28  
    29  const appFile = "src/App.svelte"
    30  const styleFile = "src/style/main.sass"
    31  const extensions = [".svelte", ".ts", ".js", ".mjs"]
    32  
    33  function includeCss(styles, bundle) {
    34  	const match = production ? `.shadowRoot.innerHTML="` : `.shadowRoot.innerHTML = "`
    35  
    36  	const currentBundle = bundle[bundleFile]
    37  	currentBundle.code = currentBundle.code.replace(
    38  		match,
    39  		`${match}<style>${styles}</style>`
    40  	)
    41  }
    42  
    43  export default {
    44  	input: "src/index.ts",
    45  	output: [
    46  		{
    47  			sourcemap: !production,
    48  			format: "iife",
    49  			name: bundleName,
    50  			file: `${bundleDir}/${bundleFile}`,
    51  			plugins: [production && terser()],
    52  		},
    53  	],
    54  	plugins: [
    55  		htmlMinifier({
    56  			include: "*.svelte",
    57  			options: {
    58  				stripCarriageReturns: true,
    59  				trimLines: true,
    60  				trimElements: true,
    61  				normalizeWhiteSpace: true,
    62  				stripComments: false,
    63  			},
    64  		}),
    65  
    66  		svelte({
    67  			preprocess: sveltePreprocess({sourceMap: !production}),
    68  			compilerOptions: {
    69  				dev: !production,
    70  				customElement: true,
    71  				tag: "talon-sidebar",
    72  				preserveWhitespace: false,
    73  			},
    74  			emitCss: false,
    75  			include: appFile,
    76  		}),
    77  
    78  		svelte({
    79  			preprocess: sveltePreprocess({sourceMap: !production}),
    80  			compilerOptions: {
    81  				dev: !production,
    82  				preserveWhitespace: false,
    83  			},
    84  			emitCss: true,
    85  			exclude: appFile,
    86  		}),
    87  
    88  		css({
    89  			output(styles, styleNodes, bundle) {
    90  				includeCss(styles, bundle)
    91  			},
    92  		}),
    93  
    94  		includeSass({
    95  			file: styleFile,
    96  			outputStyle: "compressed",
    97  			output: includeCss,
    98  		}),
    99  
   100  		resolve({
   101  			browser: true,
   102  			dedupe: ["svelte"],
   103  			extensions,
   104  		}),
   105  		commonjs(),
   106  		typescript({
   107  			sourceMap: !production,
   108  			inlineSources: !production,
   109  		}),
   110  
   111  		!production && serve(),
   112  
   113  		!production && livereload(bundleDir),
   114  
   115  		// add transition into shadow dom
   116  		replace({
   117  			".ownerDocument": ".getRootNode()",
   118  			delimiters: ["", ""],
   119  			preventAssignment: true,
   120  		}),
   121  		replace({
   122  			".head.appendChild": ".appendChild",
   123  			delimiters: ["", ""],
   124  			preventAssignment: true,
   125  		}),
   126  
   127  		// replace version placeholder
   128  		replace({
   129  			__VERSION__: version,
   130  			preventAssignment: true,
   131  		}),
   132  
   133  		babel({
   134  			extensions,
   135  			exclude: "node_modules/**",
   136  			plugins: ["@babel/plugin-proposal-class-properties"],
   137  			presets: [
   138  				[
   139  					"@babel/preset-env",
   140  					{
   141  						modules: false,
   142  						targets: {
   143  							esmodules: true,
   144  						},
   145  					},
   146  				],
   147  				"@babel/preset-typescript",
   148  			],
   149  			babelHelpers: "bundled",
   150  		}),
   151  	],
   152  	watch: {
   153  		chokidar: true,
   154  		clearScreen: false,
   155  	},
   156  	external: ["./src/style/test.css"],
   157  }