From 522f0960d42349a517225958ff13b0bd98125b81 Mon Sep 17 00:00:00 2001 From: Nikita Karamov Date: Thu, 23 Jul 2020 18:39:28 +0200 Subject: [PATCH] A better split into two versions Additionally add some typing to the Rollup config files --- rollup.config.js | 104 +++++++++++++++++++++++------------------------ src/autoinit.ts | 2 + src/shareon.ts | 2 - 3 files changed, 54 insertions(+), 54 deletions(-) diff --git a/rollup.config.js b/rollup.config.js index 820a800..253060e 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -14,13 +14,14 @@ const outputDir = isDev ? './dev/' : './dist/'; const bannerText = `${pkg.name} v${pkg.version} by Nikita Karamov\n${pkg.homepage}`; -/* - * PLUGINS +/** + * Plugins to build the project + * + * @type {Plugin[]} */ - -const plugins = []; - -plugins.push(typescript()); +const plugins = [ + typescript(), +]; if (!isDev) { plugins.push(strip({ @@ -51,58 +52,57 @@ plugins.push(postcss({ ], })); -/* - * OUTPUTS +/** + * @typedef {import('rollup').OutputOptions} OutputOptions */ -const output = []; +/** + * + * @param {string} baseDir base directory for the output files + * @return {OutputOptions[]} array of outputs + */ +const getOutputs = (baseDir) => { + const result = []; -if (isDev) { - output.push({ - name: pkg.name, - format: 'iife', - file: `${outputDir}${pkg.name}.js`, - }); -} else { - output.push({ - name: pkg.name, - format: 'cjs', - file: `${outputDir}${pkg.name}.cjs`, - }); - output.push({ - name: pkg.name, - format: 'esm', - file: `${outputDir}${pkg.name}.mjs`, - }); - output.push({ - name: pkg.name, - format: 'iife', - file: `${outputDir}${pkg.name}.noinit.min.js`, - plugins: [terser({ output: { comments: false } })], - }); -} - -const config = [{ - input: isDev ? './src/autoinit.ts' : './src/shareon.ts', - output, - plugins, -}]; - -if (!isDev) { - config.push({ - input: './src/autoinit.ts', - output: { + if (isDev) { + result.push({ name: pkg.name, format: 'iife', - file: `${outputDir}${pkg.name}.min.js`, + file: `${baseDir}${pkg.name}.js`, + }); + } else { + result.push({ + name: pkg.name, + format: 'cjs', + file: `${baseDir}${pkg.name}.cjs`, + }); + result.push({ + name: pkg.name, + format: 'esm', + file: `${baseDir}${pkg.name}.mjs`, + }); + result.push({ + name: pkg.name, + format: 'iife', + file: `${baseDir}${pkg.name}.min.js`, plugins: [terser({ output: { comments: false } })], - }, - plugins, - }); -} + }); + } -/* - * EXPORT - */ + return result; +}; + +const config = [ + { + input: './src/autoinit.ts', + output: getOutputs(`${outputDir}`), + plugins, + }, + { + input: './src/shareon.ts', + output: getOutputs(`${outputDir}noinit/`), + plugins: plugins.slice(0, -1), + }, +]; export default config; diff --git a/src/autoinit.ts b/src/autoinit.ts index 86d28f0..a44dece 100644 --- a/src/autoinit.ts +++ b/src/autoinit.ts @@ -1,3 +1,5 @@ +import './style.scss'; + import initializeShareon from './shareon'; window.onload = () => { diff --git a/src/shareon.ts b/src/shareon.ts index fd7f9e2..79e27a0 100644 --- a/src/shareon.ts +++ b/src/shareon.ts @@ -1,5 +1,3 @@ -import './style.scss'; - interface PublishPreset { url: string, title: string,