Skip to content

Commit 0730813

Browse files
committed
Mention example-vue-lib in the docs
1 parent 929aca2 commit 0730813

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

packages/docs/src/dist-files.md

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Tooling in the consuming application should pick this up automatically, as it's
121121

122122
### `<name>.esm.dev.mjs`
123123

124-
This file exposes the library as an ES module. It is intended to be used during development, either with a bundler or directly in the browser via `<script type="module">` and import maps.
124+
This file exposes the library as an ES module. It is intended to be used during development, either with a bundler or directly in the browser via `<script type="module">` and import maps (see the section about `<name>.esm-browser.prod.js` for more information about direct browser usage).
125125

126126
Some features of this build:
127127
- The file is not minified, to make debugging easier.
@@ -130,6 +130,10 @@ Some features of this build:
130130

131131
In production, you would use either `<name>.esm-browser.prod.js` or `<name>.esm-bundler.prod.mjs` instead.
132132

133+
This build is suitable for use in the Vue Playground:
134+
135+
- [Vue Playground example](https://play.vuejs.org/#eNqlU01v2zAM/SuEL9lHbHfYTplXdBsCbAXWDduOvmg24yiRJUGiUxdB/vsofy0LmrZADwIkvqfHR0rcRx+tTXYNRoso84WTlsAjNRaU0NWHPCKfR5e5lrU1jmAPy1bUVuFnwwGNmubw7e6H0KjgACtnaphd+a10pDDFnhqzeqzkn1mus7RPwYJ8IGRYEPIJIKuF1N2O96dJIB2RMRlJzsD2jk55BCtjCN0U7o+d/3AZ4AuKEh0IXY5Yr5oOsk/KMqldN55AwLoTfUTpMWeD1lNcTXduzJAbjHvgZpYOrc3So45Hc37awuiVrJKNN5rffx/YeVRw16VC992SNJqffwEdEjChlLm97mLkGpyP8WKNxfae+Ma3IcZlO/Todty+CSPhKqQeXv66wZb3E1ibsgnNfgD8id6oJnjsaZ8aXbLtI17n9mv3c6WufvtlS6j9WFQwGpiHjp9H/E3DhztX+j+7b5N33b1cH7iL/WTEtbAnfeyB/0XOzUZfwZrI+kWaNtpuq4TfIT3HT0vp6TSYoK+TEndJveGsRxY93Sn0SeE9u7saRrlx6sXsuRlZcvbyfZjm8Mf6OmvRxreypDV36uLCtgyzj4FxCa/gNa+B6SqpYzJ2AW8mZnT4C74KhmM=)
136+
133137
If your library needs to differentiate between bundlers and direct browser usage during development then you may need to adjust the build to generate more files.
134138

135139
### `<name>.esm-browser.prod.js`
@@ -141,18 +145,35 @@ This file is an ES module build intended to be used directly in the browser, not
141145
{
142146
"imports": {
143147
"vue": "https://unpkg.com/vue@3/dist/vue.esm-browser.prod.js",
144-
"@skirtle/example-lib": "https://unpkg.com/@skirtle/example-lib/dist/example-lib.esm-browser.prod.js"
148+
"@skirtle/example-vue-lib": "https://unpkg.com/@skirtle/example-vue-lib/dist/example-vue-lib.esm-browser.prod.js"
145149
}
146150
}
147151
</script>
148152
<script type="module">
149-
import { ExampleComponent } from '@skirtle/example-lib'
153+
import { ExampleComponent } from '@skirtle/example-vue-lib'
150154
// ...
151155
</script>
152156
```
153157

154158
It's a production build, so in real code the versions should be pinned.
155159

160+
An *import map* is required. While browsers do support importing directly from a URL, that wouldn't be able to resolve imports from `vue` inside the library. So, for example, this wouldn't work:
161+
162+
```html
163+
<script type="module">
164+
// This won't work. // [!code error]
165+
// It won't be able to resolve 'vue' inside the imported file. // [!code error]
166+
import { ExampleComponent } from 'https://unpkg.com/@skirtle/example-vue-lib/dist/example-vue-lib.esm-browser.prod.js' // [!code error]
167+
// ...
168+
</script>
169+
```
170+
171+
This build is suitable for use in the Vue Playground:
172+
173+
- [Vue Playground example](https://play.vuejs.org/#__PROD__eNqlU8tu2zAQ/JUFL+7DklK0J9cN0hYG2gBNi7ZHXRhpLTOmSIJcxQoM/3uXkqw6RpwEyEGAuDOcnR2SW/HZufS2QTET81B45QgCUuNAS1N9ygWFXJznRtXOeoItLFpZO41fLRcMGprCj7tf0qCGHSy9rWFyEdbKk8YMe2rC6olW15PczLO+BQvygpBhScgrgHktlen++P+4CWR7ZN+MFHdgewerXMDSWkI/lvtl5z9uBviGskQP0pR7rFfNBtlndRnVLptAIGHViT6h9JSzQes5rsY9V3boDdY/snOeDdHOs4PExZSPtrBmqar0JljD57+N7FwUnLrS6H86Utbw8c+gQyImtbaby65GvsHpvl6ssFg/UL8Jbazx2B4D+luOb8RI+gqphxd/rrDl/xGsbdnEsB8Bf2Owuokee9qXxpRs+4DXuf3e3Vxlqr9h0RKasB8qGo3MXcfPBV/TeOFOjf7f7vv0Q7cvNztOsX8ZSS3dUY49cF/k1NvoJ1gRuTDLssa4dZXyOWSn+FmpAh0XUwx1cu3thpNOnbclG8rFgdVAdxpDWoTALi+GJ914/Wry0s5dN9advP4Yn3a8cP3QtWyTjSppxbGdnbmWYTYzMM7hDbzlb2D6SpmErJvBu5Epdv8AJsOLgA==)
174+
175+
In particular, note the configuration in the `Import Map` tab.
176+
156177
Some features of this build:
157178
- The file is minified, reducing its size. Note that Vite doesn't fully minify `esm` builds for libraries.
158179
- The global `__DEV__` flag will be set to `false` and dead code removed. This is only relevant if you're using it in your code.
@@ -175,28 +196,30 @@ From a bundler's perspective, the only significant difference between this build
175196

176197
Global builds can be used without build tools, just by including a `<script>` tag in the HTML page. They are built using the IIFE format.
177198

178-
The library is exposed using a global variable. For example, let's imagine our package is called `@skirtle/example-lib`, it might be used something like this:
199+
The library is exposed using a global variable. For example, the library `@skirtle/example-vue-lib` can be used something like this:
179200

180201
```html
181202
<body>
182203
<div id="app">
183-
<ExampleComponent />
204+
<example-component></example-component>
184205
</div>
185206
<script src="https://unpkg.com/vue@3"></script>
186-
<script src="https://unpkg.com/@skirtle/example-lib/dist/example-lib.global.dev.js"></script>
207+
<script src="https://unpkg.com/@skirtle/example-vue-lib/dist/example-vue-lib.global.dev.js"></script>
187208
<script>
188209
Vue.createApp({
189210
components: {
190-
ExampleComponent: ExampleLib.ExampleComponent
191-
}
211+
ExampleComponent: ExampleVueLib.ExampleComponent
212+
}
192213
}).mount('#app')
193214
</script>
194215
</body>
195216
```
196217

197-
The global build of Vue creates a global variable called `Vue`, exposing `createApp`. The global build of `@skirtle/example-lib` creates a global variable called `ExampleLib`, allowing us to access `ExampleComponent`.
218+
You can see a complete, running example in this [JSFiddle](https://jsfiddle.net/skirtle/jep2ws9a/).
219+
220+
The global build of Vue creates a global variable called `Vue`, exposing `createApp`. The global build of `@skirtle/example-vue-lib` creates a global variable called `ExampleVueLib`, allowing us to access `ExampleComponent`.
198221

199-
In production applications, the `prod` builds of both `vue` and `@skirtle/example-lib` should be used instead, and exact versions should be pinned in the URL.
222+
In production applications, the `prod` builds of both `vue` and `@skirtle/example-vue-lib` should be used instead, and exact versions should be pinned in the URL.
200223

201224
The differences between the `dev` and `prod` builds are:
202225
- `prod` is minified, `dev` isn't.

packages/docs/src/introduction.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ Currently unsupported (you'd need to configure them yourself):
5858
- Other Vue libraries, such as VueUse, Vue Router and Pinia
5959
- E2E testing
6060

61+
## Examples
62+
63+
You can see an example library, created using this tool, at:
64+
65+
- https://github.com/skirtles-code/example-vue-lib
66+
67+
This has been published to the npm registry as [`@skirtle/example-vue-lib`](https://www.npmjs.com/package/@skirtle/example-vue-lib).
68+
6169
## Prerequisites
6270

6371
Developing libraries to publish to npm is tricky. There is some inherent complexity to publishing packages that can't be avoided, and you're unlikely to succeed if you don't have prior experience of working with Vue, Vite and the wider ecosystem.

0 commit comments

Comments
 (0)