From 30b026c5966e20c2f17d93f160c40a69edea29fb Mon Sep 17 00:00:00 2001 From: Chen Fengyuan Date: Sat, 23 Jan 2021 16:25:35 +0800 Subject: [PATCH] build: update config --- rollup.config.js | 51 +++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/rollup.config.js b/rollup.config.js index 238adb9..3e6dfdd 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,9 +1,10 @@ -const babel = require('rollup-plugin-babel'); -const changeCase = require('change-case'); -const commonjs = require('rollup-plugin-commonjs'); -const createBanner = require('create-banner'); -const nodeResolve = require('rollup-plugin-node-resolve'); -const pkg = require('./package'); +import babel from '@rollup/plugin-babel'; +import changeCase from 'change-case'; +import commonjs from '@rollup/plugin-commonjs'; +import createBanner from 'create-banner'; +import nodeResolve from '@rollup/plugin-node-resolve'; +import { terser } from 'rollup-plugin-terser'; +import pkg from './package.json'; const name = changeCase.pascalCase(pkg.name); const banner = createBanner({ @@ -11,44 +12,58 @@ const banner = createBanner({ data: { year: '2014-present', }, + template: 'inline', }); +const globals = { + jquery: 'jQuery', +}; -module.exports = { +export default { input: 'src/index.js', output: [ { banner, name, - file: `dist/${pkg.name}.js`, + globals, + file: pkg.browser, + format: 'umd', + }, + { + banner, + name, + file: pkg.browser.replace(/(\.js)$/, '.min$1'), + globals, format: 'umd', - globals: { - jquery: 'jQuery', - }, + compact: true, + plugins: [ + terser(), + ], }, { banner, - file: `dist/${pkg.name}.common.js`, + file: pkg.main, format: 'cjs', + exports: 'auto', }, { banner, - file: `dist/${pkg.name}.esm.js`, + file: pkg.module, format: 'esm', }, { banner, name, - file: `docs/js/${pkg.name}.js`, + globals, + file: pkg.browser.replace(/^dist/, 'docs/js'), format: 'umd', - globals: { - jquery: 'jQuery', - }, }, ], external: ['jquery'], plugins: [ nodeResolve(), commonjs(), - babel(), + babel({ + babelHelpers: 'bundled', + }), ], };