Skip to content

Commit 52c75a1

Browse files
committed
vue 3 build
first version running with vue 3
1 parent f5ea95d commit 52c75a1

28 files changed

+5240
-7188
lines changed

.eslintignore

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

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.gitignore

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
.DS_Store
2-
node_modules
3-
/dist
4-
/docs
2+
node_modules/
3+
/dist/
54

65
# local env files
76
.env.local
@@ -20,5 +19,3 @@ yarn-error.log*
2019
*.njsproj
2120
*.sln
2221
*.sw*
23-
24-
.rpt2_cache

.npmrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 Tyler Krupicka
3+
Copyright (c) 2021 Tyler Krupicka, Volker Nauruhn
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
# Vue JSON Component
1+
# Vue3 JSON Component
22

3-
[![npm version](https://badge.fury.io/js/vue-json-component.svg)](https://badge.fury.io/js/vue-json-component) [![TypeScript](https://badges.frapsoft.com/typescript/code/typescript.svg?v=101)](https://github.com/ellerbrock/typescript-badges/) ![npm bundle size](https://img.shields.io/bundlephobia/min/vue-json-component.svg) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
3+
---
4+
**NOTE**
45

5-
[Demo](http://tylerkrupicka.com/vue-json-component/)
6+
This is primary a fork of [vue-json-component](https://github.com/tylerkrupicka/vue-json-component) which was created to achieve quick Vue 3 support.
7+
---
8+
9+
[![npm version](https://badge.fury.io/js/vue3-json-component.svg)](https://badge.fury.io/js/vue3-json-component) [![TypeScript](https://badges.frapsoft.com/typescript/code/typescript.svg?v=101)](https://github.com/ellerbrock/typescript-badges/) ![npm bundle size](https://img.shields.io/bundlephobia/min/vue3-json-component.svg) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
10+
11+
[Demo](http://tylerkrupicka.com/vue3-json-component/)
612

713
A collapsable tree view for JSON. This package has some similarites with [vue-json-tree-view](https://github.com/michaelfitzhavey/vue-json-tree-view) so I'll address the differences below. I'm not contributing this back to that package because it would require breaking API changes, and the code is entirely different. **Contributions welcome!**
814

@@ -13,7 +19,7 @@ A collapsable tree view for JSON. This package has some similarites with [vue-js
1319
This package has a few major improvements over predecessors: builds, styles, and customization. For builds, this package ships CommonJS, Module, and UNPKG builds with no dependencies. [vue-json-tree-view](https://github.com/michaelfitzhavey/vue-json-tree-view) bundles in lots of dependencies -- including lodash. I also export global Vue imports, local Vue imports, and TypeScript declarations. The code itself is about as small as it can be while being easy to follow.
1420

1521
- [vue-json-tree-view (84KB)](https://bundlephobia.com/result?p=vue-json-tree-view@2.1.4)
16-
- [vue-json-component (9KB)](https://bundlephobia.com/result?p=vue-json-component@0.3.0)
22+
- [vue3-json-component (9KB)](https://bundlephobia.com/result?p=vue3-json-component@0.3.0)
1723

1824
The styles in this package are all scoped, with key colors still being customizable. There are no extra margins or overflow rules and text properties are all inherited from the page. This makes the view much easier to integrate anywhere you need it.
1925

@@ -24,14 +30,14 @@ The default color theme is based on solarized, and font weights are modified to
2430
### Install
2531

2632
```bash
27-
npm i vue-json-component
28-
yarn add vue-json-component
33+
npm i vue3-json-component
34+
yarn add vue3-json-component
2935
```
3036

3137
### Import Locally
3238

3339
```js
34-
import { JSONView } from 'vue-json-component';
40+
import { JSONView } from 'vue3-json-component';
3541
export default Vue.extend({
3642
components: { 'json-view': JSONView }
3743
});
@@ -40,7 +46,7 @@ export default Vue.extend({
4046
### Import Globally
4147

4248
```js
43-
import JSONView from 'vue-json-component';
49+
import JSONView from 'vue3-json-component';
4450
Vue.use(JSONView);
4551
```
4652

babel.config.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
const devPresets = ['@vue/babel-preset-app'];
2+
const buildPresets = [
3+
[
4+
'@babel/preset-env',
5+
// Config for @babel/preset-env
6+
{
7+
// Example: Always transpile optional chaining/nullish coalescing
8+
// include: [
9+
// /(optional-chaining|nullish-coalescing)/
10+
// ],
11+
},
12+
],
13+
'@babel/preset-typescript',
14+
];
115
module.exports = {
2-
presets: [['@vue/app', { useBuiltIns: 'entry', corejs: { version: 2 } }]]
16+
presets: (process.env.NODE_ENV === 'development' ? devPresets : buildPresets),
317
};

bili.config.js

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

build/rollup.config.js

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
// rollup.config.js
2+
import fs from 'fs';
3+
import path from 'path';
4+
import vue from 'rollup-plugin-vue';
5+
import alias from '@rollup/plugin-alias';
6+
import commonjs from '@rollup/plugin-commonjs';
7+
import resolve from '@rollup/plugin-node-resolve';
8+
import replace from '@rollup/plugin-replace';
9+
import babel from '@rollup/plugin-babel';
10+
import PostCSS from 'rollup-plugin-postcss';
11+
import { terser } from 'rollup-plugin-terser';
12+
import ttypescript from 'ttypescript';
13+
import typescript from 'rollup-plugin-typescript2';
14+
import minimist from 'minimist';
15+
import scss from 'rollup-plugin-scss';
16+
import postcss from 'postcss';
17+
import autoprefixer from 'autoprefixer';
18+
19+
// Get browserslist config and remove ie from es build targets
20+
const esbrowserslist = fs.readFileSync('./.browserslistrc')
21+
.toString()
22+
.split('\n')
23+
.filter((entry) => entry && entry.substring(0, 2) !== 'ie');
24+
25+
// Extract babel preset-env config, to combine with esbrowserslist
26+
const babelPresetEnvConfig = require('../babel.config')
27+
.presets.filter((entry) => entry[ 0 ] === '@babel/preset-env')[ 0 ][ 1 ];
28+
29+
const argv = minimist(process.argv.slice(2));
30+
31+
const projectRoot = path.resolve(__dirname, '..');
32+
33+
const baseConfig = {
34+
input : 'src/entry.ts',
35+
plugins: {
36+
preVue : [
37+
alias({
38+
entries: [
39+
{
40+
find : '@',
41+
replacement: `${path.resolve(projectRoot, 'src')}`
42+
}
43+
]
44+
})
45+
],
46+
replace: {
47+
'process.env.NODE_ENV': JSON.stringify('production')
48+
},
49+
vue : {},
50+
postVue: [
51+
resolve({
52+
extensions: [ '.js', '.jsx', '.ts', '.tsx', '.vue' ]
53+
}),
54+
scss({
55+
processor : () => postcss([ autoprefixer() ]),
56+
includePaths: [
57+
path.join(__dirname, '../../node_modules/'),
58+
'node_modules/'
59+
]
60+
}),
61+
// Process only `<style module>` blocks.
62+
PostCSS({
63+
modules: {
64+
generateScopedName: '[local]___[hash:base64:5]'
65+
},
66+
include: /&module=.*\.css$/
67+
}),
68+
// Process all `<style>` blocks except `<style module>`.
69+
PostCSS({include: /(?<!&module=.*)\.css$/}),
70+
commonjs()
71+
],
72+
babel : {
73+
exclude : 'node_modules/**',
74+
extensions : [ '.js', '.jsx', '.ts', '.tsx', '.vue' ],
75+
babelHelpers: 'bundled'
76+
}
77+
}
78+
};
79+
80+
// ESM/UMD/IIFE shared settings: externals
81+
// Refer to https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency
82+
const external = [
83+
// list external dependencies, exactly the way it is written in the import statement.
84+
// eg. 'jquery'
85+
'vue'
86+
];
87+
88+
// UMD/IIFE shared settings: output.globals
89+
// Refer to https://rollupjs.org/guide/en#output-globals for details
90+
const globals = {
91+
// Provide global variable names to replace your external imports
92+
// eg. jquery: '$'
93+
vue: 'Vue'
94+
};
95+
96+
// Customize configs for individual targets
97+
const buildFormats = [];
98+
if (!argv.format || argv.format === 'es') {
99+
const esConfig = {
100+
...baseConfig,
101+
input : 'src/entry.esm.ts',
102+
external,
103+
output : {
104+
file : 'dist/JSONView.esm.js',
105+
format : 'esm',
106+
exports: 'named'
107+
},
108+
plugins: [
109+
replace(baseConfig.plugins.replace),
110+
...baseConfig.plugins.preVue,
111+
vue(baseConfig.plugins.vue),
112+
...baseConfig.plugins.postVue,
113+
// Only use typescript for declarations - babel will
114+
// do actual js transformations
115+
typescript({
116+
typescript : ttypescript,
117+
useTsconfigDeclarationDir: true,
118+
emitDeclarationOnly : true
119+
}),
120+
babel({
121+
...baseConfig.plugins.babel,
122+
presets: [
123+
[
124+
'@babel/preset-env',
125+
{
126+
...babelPresetEnvConfig,
127+
targets: esbrowserslist
128+
}
129+
]
130+
]
131+
})
132+
]
133+
};
134+
buildFormats.push(esConfig);
135+
}
136+
137+
if (!argv.format || argv.format === 'cjs') {
138+
const umdConfig = {
139+
...baseConfig,
140+
external,
141+
output : {
142+
compact: true,
143+
file : 'dist/JSONView.ssr.js',
144+
format : 'cjs',
145+
name : 'JSONView',
146+
exports: 'auto',
147+
globals
148+
},
149+
plugins: [
150+
replace(baseConfig.plugins.replace),
151+
...baseConfig.plugins.preVue,
152+
vue(baseConfig.plugins.vue),
153+
...baseConfig.plugins.postVue,
154+
babel(baseConfig.plugins.babel)
155+
]
156+
};
157+
buildFormats.push(umdConfig);
158+
}
159+
160+
if (!argv.format || argv.format === 'iife') {
161+
const unpkgConfig = {
162+
...baseConfig,
163+
external,
164+
output : {
165+
compact: true,
166+
file : 'dist/JSONView.min.js',
167+
format : 'iife',
168+
name : 'JSONView',
169+
exports: 'auto',
170+
globals
171+
},
172+
plugins: [
173+
replace(baseConfig.plugins.replace),
174+
...baseConfig.plugins.preVue,
175+
vue(baseConfig.plugins.vue),
176+
...baseConfig.plugins.postVue,
177+
babel(baseConfig.plugins.babel),
178+
terser({
179+
output: {
180+
ecma: 5
181+
}
182+
})
183+
]
184+
};
185+
buildFormats.push(unpkgConfig);
186+
}
187+
188+
// Export config
189+
export default buildFormats;

dev/serve.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { createApp } from 'vue';
2+
import Dev from './serve.vue';
3+
4+
const app = createApp(Dev);
5+
app.mount('#app');

0 commit comments

Comments
 (0)