A better split into two versions

Additionally add some typing to the Rollup config files
pull/14/head
Nikita Karamov 2020-07-23 18:39:28 +02:00
parent 8f1d52e281
commit 522f0960d4
No known key found for this signature in database
GPG Key ID: E40DFE6E993540FF
3 changed files with 54 additions and 54 deletions

View File

@ -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({
if (isDev) {
result.push({
name: pkg.name,
format: 'iife',
file: `${outputDir}${pkg.name}.js`,
file: `${baseDir}${pkg.name}.js`,
});
} else {
output.push({
} else {
result.push({
name: pkg.name,
format: 'cjs',
file: `${outputDir}${pkg.name}.cjs`,
file: `${baseDir}${pkg.name}.cjs`,
});
output.push({
result.push({
name: pkg.name,
format: 'esm',
file: `${outputDir}${pkg.name}.mjs`,
file: `${baseDir}${pkg.name}.mjs`,
});
output.push({
result.push({
name: pkg.name,
format: 'iife',
file: `${outputDir}${pkg.name}.noinit.min.js`,
file: `${baseDir}${pkg.name}.min.js`,
plugins: [terser({ output: { comments: false } })],
});
}
}
const config = [{
input: isDev ? './src/autoinit.ts' : './src/shareon.ts',
output,
plugins,
}];
return result;
};
if (!isDev) {
config.push({
const config = [
{
input: './src/autoinit.ts',
output: {
name: pkg.name,
format: 'iife',
file: `${outputDir}${pkg.name}.min.js`,
plugins: [terser({ output: { comments: false } })],
},
output: getOutputs(`${outputDir}`),
plugins,
});
}
/*
* EXPORT
*/
},
{
input: './src/shareon.ts',
output: getOutputs(`${outputDir}noinit/`),
plugins: plugins.slice(0, -1),
},
];
export default config;

View File

@ -1,3 +1,5 @@
import './style.scss';
import initializeShareon from './shareon';
window.onload = () => {

View File

@ -1,5 +1,3 @@
import './style.scss';
interface PublishPreset {
url: string,
title: string,