Skip to content

Commit 407ef56

Browse files
committed
fix: fix output version
1 parent e9f3a4d commit 407ef56

File tree

7 files changed

+89
-41
lines changed

7 files changed

+89
-41
lines changed

.babelrc

Lines changed: 0 additions & 34 deletions
This file was deleted.

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# output
22
es/
33
lib/
4+
es2/
5+
lib2/
6+
es3/
7+
lib3/
48
*.d.ts

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,7 @@ dist
106106
# build output
107107
es/
108108
lib/
109+
es2/
110+
lib2/
111+
es3/
112+
lib3/

babel.config.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// eslint-disable-next-line
2+
const { isVue2, isVue3 } = require('vue-demi')
3+
4+
module.exports = {
5+
presets: [
6+
[
7+
'@vue/babel-preset-app',
8+
{
9+
modules: false,
10+
corejs: 3,
11+
jsx: false,
12+
absoluteRuntime: false,
13+
targets: {
14+
browsers: 'last 2 versions, IE >= 11',
15+
},
16+
},
17+
],
18+
'@babel/preset-typescript',
19+
isVue2 && '@vue/babel-preset-jsx',
20+
].filter(Boolean),
21+
plugins: [isVue3 && '@vue/babel-plugin-jsx'].filter(Boolean),
22+
env: {
23+
commonjs: {
24+
presets: [
25+
[
26+
'@vue/babel-preset-app',
27+
{
28+
modules: 'commonjs',
29+
corejs: 3,
30+
jsx: false,
31+
absoluteRuntime: false,
32+
targets: {
33+
browsers: 'last 2 versions, IE >= 11',
34+
},
35+
},
36+
],
37+
'@babel/preset-typescript',
38+
isVue2 && '@vue/babel-preset-jsx',
39+
].filter(Boolean),
40+
plugins: [isVue3 && '@vue/babel-plugin-jsx'].filter(Boolean),
41+
},
42+
},
43+
}

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
"files": [
1212
"lib",
1313
"es",
14+
"lib2",
15+
"es2",
1416
"*.d.ts"
1517
],
1618
"publishConfig": {
@@ -20,19 +22,24 @@
2022
"dev": "vitepress dev docs",
2123
"lint": "eslint . --ext=.ts,.tsx",
2224
"lint:fix": "eslint . --ext=.ts,.tsx --fix",
23-
"test": "npm run test2 && npm run test3",
25+
"test": "npm run test3",
2426
"test2": "vue-demi-switch 2 vue2 && jest",
2527
"test3": "vue-demi-switch 3 && jest",
2628
"prebuild": "npm test",
27-
"build": "npm run build:es & npm run build:commonjs & npm run build:types",
28-
"build:es": "babel src -d es --extensions .ts,.tsx --delete-dir-on-start",
29-
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src -d lib --extensions .ts,.tsx --delete-dir-on-start",
30-
"build:types": "tsc & tsc --declarationDir ./es",
29+
"build": "npm run build:vue3 && npm run build:vue2",
30+
"build:vue3": "npm run build:es & npm run build:commonjs & npm run build:types",
31+
"build:vue2": "npm run build:es2 & npm run build:commonjs2",
32+
"build:es": "vue-demi-switch 3 && babel src -d es --extensions .ts,.tsx --delete-dir-on-start",
33+
"build:commonjs": "cross-env BABEL_ENV=commonjs vue-demi-switch 3 && babel src -d lib --extensions .ts,.tsx --delete-dir-on-start",
34+
"build:es2": "vue-demi-switch 2 vue2 && babel src -d es2 --extensions .ts,.tsx --delete-dir-on-start",
35+
"build:commonjs2": "cross-env BABEL_ENV=commonjs vue-demi-switch 2 vue2 && babel src -d lib2 --extensions .ts,.tsx --delete-dir-on-start",
36+
"build:types": "vue-demi-switch 3 && tsc & tsc --declarationDir ./es",
3137
"build:docs": "vitepress build docs",
3238
"preversion": "npm run build",
3339
"version": "conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md",
3440
"postversion": "npm publish",
35-
"sync": "ts-node --project tsconfig.sync.json ./scripts/sync.ts"
41+
"sync": "ts-node --project tsconfig.sync.json ./scripts/sync.ts",
42+
"postinstall": "node ./scripts/postinstall.js"
3643
},
3744
"repository": {
3845
"type": "git",
@@ -122,4 +129,4 @@
122129
"optional": true
123130
}
124131
}
125-
}
132+
}

scripts/postinstall.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* eslint-disable @typescript-eslint/no-var-requires */
2+
const { isVue2, isVue3 } = require('vue-demi')
3+
const fs = require('fs')
4+
const path = require('path')
5+
const pkg = require('../package.json')
6+
7+
if (isVue2) {
8+
console.log('[G2Plot-Vue] Switch main field for Vue 2')
9+
pkg.main = 'lib2/index.js'
10+
pkg.module = 'es2/index.js'
11+
} else if (isVue3) {
12+
console.log('[G2Plot-Vue] Switch main field for Vue 3')
13+
pkg.main = 'lib/index.js'
14+
pkg.module = 'es/index.js'
15+
}
16+
17+
fs.writeFileSync(
18+
path.resolve(__dirname, '../package.json'),
19+
JSON.stringify(pkg, null, 2),
20+
{
21+
encoding: 'utf-8',
22+
}
23+
)

0 commit comments

Comments
 (0)