Skip to content

Commit 0097168

Browse files
committed
use single import entry; add iife output
1 parent 4de9d5a commit 0097168

File tree

7 files changed

+62
-33
lines changed

7 files changed

+62
-33
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</template>
1313
1414
<script setup>
15-
import { VVPlot, VVGeomPoint } from 'vvplot/components'
15+
import { VVPlot, VVGeomPoint } from 'vvplot'
1616
1717
const data = [{ x: 1, y: 2 }, { x: 2, y: 3 }, { x: 3, y: 5 }]
1818
</script>

package.json

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vvplot",
3-
"version": "0.1.4",
3+
"version": "0.2.0",
44
"license": "MIT",
55
"files": [
66
"dist"
@@ -10,18 +10,16 @@
1010
"dev": "vite dev"
1111
},
1212
"type": "module",
13-
"module": "./dist/index.js",
14-
"types": "./dist/index.d.ts",
13+
"module": "./dist/vvplot.esm.js",
14+
"types": "./dist/vvplot.d.ts",
1515
"imports": {
1616
"#base/*": "./src/*"
1717
},
1818
"exports": {
19-
".": "./dist/index.js",
20-
"./components": "./dist/components.js",
21-
"./scale": "./dist/scale.js",
22-
"./break": "./dist/break.js",
23-
"./theme": "./dist/theme.js",
24-
"./label": "./dist/label.js",
19+
".": {
20+
"import": "./dist/vvplot.esm.js",
21+
"types": "./dist/vvplot.d.ts"
22+
},
2523
"./style.css": "./dist/style.css"
2624
},
2725
"homepage": "https://fan-ix.github.io/vvplot/",

src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
import './style.css'
22
export * from './components'
3+
export * as components from './components'
4+
export { default as vvtheme } from './js/theme.js'
5+
export { default as vvbreak } from './js/break.js'
6+
export { default as vvlabel } from './js/label.js'
7+
export { default as vvscale } from './js/scale.js'
8+
export * from './js/scale.js'
9+
export * from './js/label.js'

tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"compilerOptions": {
3+
"allowJs": true,
4+
"checkJs": false,
35
"target": "esnext",
46
"useDefineForClassFields": true,
57
"module": "esnext",
@@ -19,5 +21,5 @@
1921
"vite/client"
2022
]
2123
},
22-
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue", "src/index.js"]
24+
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue", "src/**/*.js"]
2325
}

vite.config.js

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
import { dirname, resolve } from 'node:path'
22
import { fileURLToPath } from 'node:url'
3-
import { defineConfig } from 'vite'
3+
import { defineConfig, transformWithEsbuild } from 'vite'
44
import vue from '@vitejs/plugin-vue'
55
import dts from 'vite-plugin-dts'
66
import tailwindcss from '@tailwindcss/vite'
77

88
const __dirname = dirname(fileURLToPath(import.meta.url))
99

10+
const esbuildMinify = {
11+
name: 'minify-plugin',
12+
renderChunk(code) {
13+
return transformWithEsbuild(code, 'index.js', {
14+
minify: true,
15+
treeShaking: true,
16+
})
17+
}
18+
}
19+
1020
export default defineConfig({
1121
define: {
1222
'process.env.NODE_ENV': JSON.stringify('production')
@@ -31,27 +41,39 @@ export default defineConfig({
3141
build: {
3242
minify: false,
3343
lib: {
34-
entry: {
35-
index: resolve(__dirname, 'src/index.ts'),
36-
components: resolve(__dirname, 'src/components/index.ts'),
37-
scale: resolve(__dirname, 'src/js/scale.js'),
38-
break: resolve(__dirname, 'src/js/break.js'),
39-
label: resolve(__dirname, 'src/js/label.js'),
40-
theme: resolve(__dirname, 'src/js/theme.js'),
41-
},
44+
entry: resolve(__dirname, 'src/index.ts'),
4245
name: 'VVPlot',
43-
formats: ['es'],
46+
fileName: 'vvplot',
4447
cssFileName: "style"
4548
},
4649
rollupOptions: {
4750
external: ['vue'],
48-
output: {
49-
chunkFileNames: '[name].js',
50-
minifyInternalExports: false,
51-
globals: {
52-
vue: 'Vue',
51+
output: [
52+
{
53+
format: 'es',
54+
entryFileNames: 'vvplot.esm.js',
55+
minifyInternalExports: false,
56+
},
57+
{
58+
format: 'es',
59+
entryFileNames: 'vvplot.esm.min.js',
60+
plugins: [esbuildMinify]
61+
},
62+
{
63+
format: 'iife',
64+
name: 'VVPlot',
65+
entryFileNames: 'vvplot.global.js',
66+
minifyInternalExports: false,
67+
globals: { vue: 'Vue' },
68+
},
69+
{
70+
format: 'iife',
71+
name: 'VVPlot',
72+
entryFileNames: 'vvplot.global.min.js',
73+
globals: { vue: 'Vue' },
74+
plugins: [esbuildMinify]
5375
},
54-
},
76+
],
5577
},
5678
},
5779
})

web-docs/docs/quick-start.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,9 @@ const render = ref('canvas')
244244
Like <code>ggplot2</code>, VVPlot comes with several built-in themes.
245245
</p>
246246
<p>
247-
To use a built-in theme, you need to import it from the <code>vvplot/theme</code> module.
247+
To use a built-in theme, you need to import it from the <code>vvtheme</code> module.
248248
</p>
249-
<pre-highlight lang="javascript">import vvtheme from 'vvplot/theme'</pre-highlight>
249+
<pre-highlight lang="javascript">import { vvtheme } from 'vvplot'</pre-highlight>
250250
<p>
251251
You can provide a single theme object or an array of theme objects to the <code>theme</code> property of
252252
<code>&lt;VVPlot&gt;</code>:

web-docs/docs/scale.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ const size_limits_max = ref(600)
2222
</p>
2323
<p>
2424
VVPlot provides several built-in scale function wrappers for different aesthetics
25-
in the <code>vvplot/scale</code> module.
25+
in the <code>vvscale</code> module.
2626
They can be imported directly from the module:
2727
</p>
28-
<pre-highlight lang="javascript">import vvscale from 'vvplot/scale'</pre-highlight>
28+
<pre-highlight lang="javascript">import { vvscale } from 'vvplot'</pre-highlight>
2929
<h3><code>identity</code> scale: keep values unchanged</h3>
3030
<p>
3131
The identity scale (<code>vvscale.*.identity()</code>) maps data values to aesthetic attributes directly
@@ -114,9 +114,9 @@ const size_limits_max = ref(600)
114114
</p>
115115
<p>
116116
The <code>oob</code> argument property controls how out-of-boundary values will be handled.
117-
VVPlot provides several built-in oob functions in the <code>vvplot/scale</code> module:
117+
VVPlot provides several built-in oob functions:
118118
</p>
119-
<pre-highlight lang="javascript">import { oob } from 'vvplot/scale'</pre-highlight>
119+
<pre-highlight lang="javascript">import { oob } from 'vvplot'</pre-highlight>
120120
<p>
121121
The following oob functions are available:
122122
</p>

0 commit comments

Comments
 (0)