refactor cjs + mjs

This commit is contained in:
Georges KABBOUCHI
2021-10-15 15:32:52 +03:00
parent 0b31b5640b
commit 7e572e9ad9
4 changed files with 33 additions and 13 deletions
+7
View File
@@ -0,0 +1,7 @@
'use strict'
if (process.env.NODE_ENV === 'production') {
module.exports = require('./dist/vue-tippy.cjs.prod.js')
} else {
module.exports = require('./dist/vue-tippy.cjs.js')
}
+1
View File
@@ -0,0 +1 @@
export * from './index.js'
+21 -5
View File
@@ -1,18 +1,34 @@
{
"name": "vue-tippy",
"version": "6.0.0-alpha.34",
"main": "dist/vue-tippy.cjs.js",
"browser": "dist/vue-tippy.esm.js",
"unpkg": "dist/vue-tippy.global.js",
"jsdelivr": "dist/vue-tippy.global.js",
"main": "index.js",
"module": "dist/vue-tippy.esm-bundler.js",
"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"
},
"require": "./index.js"
},
"./package.json": "./package.json",
"./index.mjs": "./index.mjs",
"./dist/*": "./dist/*"
},
"sideEffects": false,
"license": "MIT",
"files": [
"dist/*.js",
"dist/*.mjs",
"dist/*.cjs",
"dist/vue-tippy.d.ts",
"index.js",
"index.mjs",
"vetur/*.json",
"LICENSE",
"README.md"
],
"scripts": {
@@ -59,4 +75,4 @@
"tags": "vetur/tags.json",
"attributes": "vetur/attributes.json"
}
}
}
+4 -8
View File
@@ -20,22 +20,18 @@ let hasTSChecked = false
const outputConfigs = {
// each file name has the format: `dist/${name}.${format}.js`
// format being a key of this object
'esm-bundler': {
mjs: {
file: pkg.module,
format: `es`,
},
cjs: {
file: pkg.main,
file: pkg.module.replace('esm-bundler', 'cjs'),
format: `cjs`,
},
global: {
file: pkg.unpkg,
format: `iife`,
},
esm: {
file: pkg.browser,
format: `es`,
},
}
const allFormats = Object.keys(outputConfigs)
@@ -68,11 +64,11 @@ function createConfig(format, output, plugins = []) {
output.globals = { 'vue': 'Vue' }
output.exports = 'named'
const isProductionBuild = /\.prod\.js$/.test(output.file)
const isProductionBuild = output.file.endsWith('.prod.js')
const isGlobalBuild = format === 'global'
const isRawESMBuild = format === 'esm'
const isNodeBuild = format === 'cjs'
const isBundlerESMBuild = /esm-bundler/.test(format)
const isBundlerESMBuild = format === 'esm' || format === 'mjs'
if (isGlobalBuild) output.name = 'VueTippy'