UNPKG

@bootcamp-project/rollupjs-config

Version:

Ready-to-use Rollup Configuration with TypeScript, Svelte, Tailwind CSS support by default, for AMD, UMD, CJS, ESM

108 lines (92 loc) 3.91 kB
'use strict'; // MIT License // Copyright (c) 2021 Bootcamp-Project contributors <contributors@bootcamp-project.com> // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. import svelte from 'rollup-plugin-svelte'; import typescript from '@rollup/plugin-typescript'; import resolve from '@rollup/plugin-node-resolve'; import commonjs from '@rollup/plugin-commonjs'; import livereload from 'rollup-plugin-livereload'; import del from 'rollup-plugin-delete' import { terser } from 'rollup-plugin-terser'; import css from 'rollup-plugin-css-only'; import pkg from './package.json'; const production = !process.env.ROLLUP_WATCH; const name = pkg.name.replace(/^(@\S+\/)?(svelte-)?(\S+)/, '$3').replace(/^\w/, m => m.toUpperCase()).replace(/-\w/g, m => m[1].toUpperCase()); const LIB = pkg.library const APP = pkg.application const BUNDLE = pkg.bundle const UMD = pkg.main const CJS = pkg.node const ESM = pkg.module const IIFE = pkg.main.replace('.js', '.min.js') function serve() { let server; function toExit() { if (server) server.kill(0) } return { writeBundle() { if (server) return; server = require('child_process').spawn('yarn', ['run', 'start', '--', '--dev'], { stdio: ['ignore', 'inherit', 'inherit'], shell: true }); process.on('SIGTERM', toExit); process.on('exit', toExit); } }; } const plugins = [ svelte({ include: 'src/**/*.svelte', // enable run-time checks when not in production compilerOptions: { dev: !production }, ...require('./svelte.config') }), // 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'] }), commonjs(), typescript({ sourceMap: !production }), // In dev mode, call `yarn run start` once the bundle has been generated !production && serve(), // Watch the `demo` directory and refresh the browser on changes when not in production !production && livereload({ watch: 'demo' }), // If we're building for production (npm run build instead of npm run dev), minify production && terser() ] const watch = { clearScreen: false } export default [{ input: APP, output: { file: BUNDLE, sourcemap: !production, format: 'umd', name }, plugins: [ del({ targets: 'demo/build/*' }), ...plugins ], watch: watch, }, { input: LIB, output: [ { file: UMD, sourcemap: !production, format: 'umd', name }, { file: CJS, sourcemap: !production, format: 'cjs', name }, { file: ESM, sourcemap: !production, format: 'es', name }, { file: IIFE, sourcemap: !production, format: 'iife', name } ], plugins: [ del({ targets: 'dist/*' }), ...plugins ] }];