From 6a98ac4892ee42fd517c594078d23f71264e4bba Mon Sep 17 00:00:00 2001 From: Georges KABBOUCHI Date: Tue, 26 Oct 2021 18:07:42 +0300 Subject: [PATCH] v6.0.0-alpha.36 --- index.cjs | 7 +++ index.js | 4 +- index.mjs | 1 - package.json | 24 ++++++---- rollup.config.js | 114 +++++++++++++++++++++++++++++------------------ 5 files changed, 96 insertions(+), 54 deletions(-) create mode 100644 index.cjs delete mode 100644 index.mjs diff --git a/index.cjs b/index.cjs new file mode 100644 index 0000000..9e63287 --- /dev/null +++ b/index.cjs @@ -0,0 +1,7 @@ +'use strict' + +if (process.env.NODE_ENV === 'production') { + module.exports = require('./dist/vue-tippy.prod.cjs') +} else { + module.exports = require('./dist/vue-tippy.cjs') +} \ No newline at end of file diff --git a/index.js b/index.js index 5074f0d..bfc22de 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ 'use strict' if (process.env.NODE_ENV === 'production') { - module.exports = require('./dist/vue-tippy.cjs.prod.js') + module.exports = require('./dist/vue-tippy.prod.cjs') } else { - module.exports = require('./dist/vue-tippy.cjs.js') + module.exports = require('./dist/vue-tippy.cjs') } \ No newline at end of file diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 8b43612..0000000 --- a/index.mjs +++ /dev/null @@ -1 +0,0 @@ -export * from './index.js' \ No newline at end of file diff --git a/package.json b/package.json index 1950d24..f772b9f 100644 --- a/package.json +++ b/package.json @@ -1,21 +1,29 @@ { "name": "vue-tippy", - "version": "6.0.0-alpha.35", + "version": "6.0.0-alpha.36", "main": "index.js", - "module": "dist/vue-tippy.esm-bundler.js", + "module": "dist/vue-tippy.mjs", "unpkg": "dist/vue-tippy.iife.js", "jsdelivr": "dist/vue-tippy.iife.js", "types": "dist/vue-tippy.d.ts", "exports": { ".": { - "import": { - "node": "./index.mjs", - "default": "./dist/vue-tippy.esm-bundler.js" + "browser": "./dist/vue-tippy.esm-browser.js", + "node": { + "import": { + "production": "./dist/vue-tippy.prod.cjs", + "development": "./dist/vue-tippy.mjs", + "default": "./dist/vue-tippy.mjs" + }, + "require": { + "production": "./dist/vue-tippy.prod.cjs", + "development": "./dist/vue-tippy.cjs", + "default": "./index.js" + } }, - "require": "./index.js" + "import": "./dist/vue-tippy.mjs" }, "./package.json": "./package.json", - "./index.mjs": "./index.mjs", "./dist/*": "./dist/*" }, "sideEffects": false, @@ -26,7 +34,7 @@ "dist/*.cjs", "dist/vue-tippy.d.ts", "index.js", - "index.mjs", + "index.cjs", "vetur/*.json", "LICENSE", "README.md" diff --git a/rollup.config.js b/rollup.config.js index bbcf2c0..bf590ad 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -3,14 +3,27 @@ import ts from 'rollup-plugin-typescript2' import replace from '@rollup/plugin-replace' import resolve from '@rollup/plugin-node-resolve' import commonjs from '@rollup/plugin-commonjs' -import postcss from 'rollup-plugin-postcss' +import pascalcase from 'pascalcase' const pkg = require('./package.json') const name = pkg.name +function getAuthors(pkg) { + const { contributors, author } = pkg + + const authors = new Set() + if (contributors && contributors) + contributors.forEach((contributor) => { + authors.add(contributor.name) + }) + if (author) authors.add(author.name) + + return Array.from(authors).join(', ') +} + const banner = `/*! * ${pkg.name} v${pkg.version} - * (c) ${new Date().getFullYear()} Georges KABBOUCHI + * (c) ${new Date().getFullYear()} ${getAuthors(pkg)} * @license MIT */` @@ -25,66 +38,71 @@ const outputConfigs = { format: `es`, }, cjs: { - file: pkg.module.replace('esm-bundler', 'cjs'), + file: pkg.module.replace('mjs', 'cjs'), format: `cjs`, }, global: { file: pkg.unpkg, format: `iife`, }, + browser: { + file: 'dist/vue-tippy.esm-browser.js', + format: `es`, + }, } -const allFormats = Object.keys(outputConfigs) -// in vue-router there are not that many -const packageFormats = allFormats -const packageConfigs = packageFormats.map(format => +const packageBuilds = Object.keys(outputConfigs) +const packageConfigs = packageBuilds.map((format) => createConfig(format, outputConfigs[format]) ) // only add the production ready if we are bundling the options -packageFormats.forEach(format => { - if (format === 'cjs') { - packageConfigs.push(createProductionConfig(format)) - } else if (format === 'global') { - packageConfigs.push(createMinifiedConfig(format)) +packageBuilds.forEach((buildName) => { + if (buildName === 'cjs') { + packageConfigs.push(createProductionConfig(buildName)) + } else if (buildName === 'global') { + packageConfigs.push(createMinifiedConfig(buildName)) } }) export default packageConfigs -function createConfig(format, output, plugins = []) { +function createConfig(buildName, output, plugins = []) { if (!output) { - console.log(require('chalk').yellow(`invalid format: "${format}"`)) + console.log(require('chalk').yellow(`invalid format: "${buildName}"`)) process.exit(1) } output.sourcemap = !!process.env.SOURCE_MAP output.banner = banner output.externalLiveBindings = false - output.globals = { 'vue': 'Vue' } - output.exports = 'named' + output.globals = { + 'vue-demi': 'VueDemi', + vue: 'Vue', + '@vue/composition-api': 'vueCompositionApi', + } - const isProductionBuild = output.file.endsWith('.prod.js') - const isGlobalBuild = format === 'global' - const isRawESMBuild = format === 'esm' - const isNodeBuild = format === 'cjs' - const isBundlerESMBuild = format === 'esm' || format === 'mjs' + const isProductionBuild = /\.prod\.[cmj]s$/.test(output.file) + const isGlobalBuild = buildName === 'global' + const isRawESMBuild = buildName === 'browser' + const isNodeBuild = buildName === 'cjs' + const isBundlerESMBuild = buildName === 'browser' || buildName === 'mjs' - if (isGlobalBuild) output.name = 'VueTippy' + if (isGlobalBuild) output.name = pascalcase(pkg.name) const shouldEmitDeclarations = !hasTSChecked const tsPlugin = ts({ check: !hasTSChecked, - tsconfig: path.resolve(__dirname, 'tsconfig.json'), - cacheRoot: path.resolve(__dirname, 'node_modules/.rts2_cache'), + tsconfig: path.resolve(__dirname, './tsconfig.json'), + cacheRoot: path.resolve(__dirname, './node_modules/.rts2_cache'), tsconfigOverride: { compilerOptions: { sourceMap: output.sourcemap, declaration: shouldEmitDeclarations, declarationMap: shouldEmitDeclarations, }, - exclude: [], + exclude: ['packages/*/__tests__', 'packages/*/test-dts'], }, }) // we only need to check TS and generate declarations once for each build. @@ -92,7 +110,10 @@ function createConfig(format, output, plugins = []) { // during a single build. hasTSChecked = true - const external = ['vue'] + const external = ['vue-demi', 'vue', '@vue/composition-api'] + if (!isGlobalBuild) { + external.push('@vue/devtools-api') + } const nodePlugins = [resolve(), commonjs()] @@ -113,7 +134,6 @@ function createConfig(format, output, plugins = []) { ), ...nodePlugins, ...plugins, - postcss(), ], output, // onwarn: (msg, warn) => { @@ -134,35 +154,43 @@ function createReplacePlugin( const replacements = { __COMMIT__: `"${process.env.COMMIT}"`, __VERSION__: `"${pkg.version}"`, - __DEV__: isBundlerESMBuild - ? // preserve to be handled by bundlers - `(process.env.NODE_ENV !== 'production')` - : // hard coded dev/prod builds - !isProduction, + __DEV__: + isBundlerESMBuild || (isNodeBuild && !isProduction) + ? // preserve to be handled by bundlers + `(process.env.NODE_ENV !== 'production')` + : // hard coded dev/prod builds + JSON.stringify(!isProduction), // this is only used during tests - __TEST__: isBundlerESMBuild ? `(process.env.NODE_ENV === 'test')` : false, + __TEST__: + isBundlerESMBuild || isNodeBuild + ? `(process.env.NODE_ENV === 'test')` + : 'false', // If the build is expected to run directly in the browser (global / esm builds) - __BROWSER__: isBrowserBuild, + __BROWSER__: JSON.stringify(isBrowserBuild), // is targeting bundlers? - __BUNDLER__: isBundlerESMBuild, - __GLOBAL__: isGlobalBuild, + __BUNDLER__: JSON.stringify(isBundlerESMBuild), + __GLOBAL__: JSON.stringify(isGlobalBuild), // is targeting Node (SSR)? - __NODE_JS__: isNodeBuild, - 'process.env.NODE_ENV': JSON.stringify('production'), + __NODE_JS__: JSON.stringify(isNodeBuild), } // allow inline overrides like //__RUNTIME_COMPILE__=true yarn build - Object.keys(replacements).forEach(key => { + Object.keys(replacements).forEach((key) => { if (key in process.env) { replacements[key] = process.env[key] } }) - return replace(replacements) + return replace({ + preventAssignment: true, + values: replacements, + }) } function createProductionConfig(format) { + const extension = format === 'cjs' ? 'cjs' : 'js' + const descriptor = format === 'cjs' ? '' : `.${format}` return createConfig(format, { - file: `dist/${name}.${format}.prod.js`, + file: `dist/${name}${descriptor}.prod.${extension}`, format: outputConfigs[format].format, }) } @@ -172,7 +200,7 @@ function createMinifiedConfig(format) { return createConfig( format, { - file: `dist/${name}.${format}.prod.js`, + file: `dist/${name}.${format === 'global' ? 'iife' : format}.prod.js`, format: outputConfigs[format].format, }, [ @@ -185,4 +213,4 @@ function createMinifiedConfig(format) { }), ] ) -} +} \ No newline at end of file