You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: BUNDLERS.md
+16-10Lines changed: 16 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -2,11 +2,11 @@
2
2
3
3
This project has non-ESM dependencies, which unfortunately cannot be *bundled* in with your other app code. Modern bundlers unfortunately don't out-of-the-box support configurations that can handle such a situation.
4
4
5
-
As such, this project provides plugins for webpack and vite, to take care of the various steps needed to get these non-ESM dependencies into an otherwise bundled web app built by those tools.
5
+
As such, this project provides plugins for Vite and Webpack, to take care of the various steps needed to get these non-ESM dependencies into an otherwise bundled web app built by those tools.
6
6
7
7
## Bundler Plugins
8
8
9
-
The plugins for vite and webpack are included in the `bundler-plugins/` directory. They should handle all necessary steps to load the dependencies.
9
+
The plugins for Vite and Webpack are included in the `bundler-plugins/` directory. They should handle all necessary steps to load the dependencies.
10
10
11
11
**Note:** You should not need to manually copy any files out of the `dist/bundlers/` directory, as the plugins access the `qr-data-sync` dependency (in `node_modules`) directly to pull the files needed. But for reference, the files these plugins access are:
12
12
@@ -24,7 +24,7 @@ The plugins for vite and webpack are included in the `bundler-plugins/` director
24
24
25
25
### Vite Plugin
26
26
27
-
If using Vite 5+, it's strongly suggested to import this library's vite-plugin to manage the loading of its non-ESM dependencies. Add something like the following to your `vite.config.js` file:
27
+
If using Vite 5+, it's strongly suggested to import this library's Vite-plugin to manage the loading of its non-ESM dependencies. Add something like the following to your `vite.config.js` file:
28
28
29
29
```js
30
30
import { defineConfig } from"vite";
@@ -39,19 +39,25 @@ export default defineConfig({
39
39
});
40
40
```
41
41
42
-
This plugin works for both the `vite dev` (dev-server) mode and the `vite build`mode. In both cases, it copies the `dist/bundlers/qrds-external-bundle.js` file into the `public/` directory of your project root. It also injects a `<script src="qrds-external-bundle.js"></script>` tag into the markup of the `index.html` file that vite produces for your app.
42
+
This plugin works for the `vite dev` (dev-server), `vite preview` (also dev-server), and `vite build`modes. In all cases, it copies the `dist/bundlers/qrds-external-bundle.js` file into the `public/` directory of your project root. It also injects a `<script src="/qrds-external-bundle.js"></script>` tag into the markup of the `index.html` file that Vite produces for your app.
43
43
44
-
**Note:** At present, this plugin is not configurable in any way (i.e., calling `QRDS()` above with no arguments). If something about its behavior is not compatible with your vite project setup -- which can vary widely and be quite complex to predict or support by a basic plugin -- it's recommended you simply copy over the `qr-data-sync/bundler-plugins/vite.mjs` plugin and make necessary changes.
44
+
**Note:** At present, this plugin is not configurable in any way (i.e., calling `QRDS()` above with no arguments). If something about its behavior is not compatible with your Vite project setup -- which can vary widely and be quite complex to predict or support by a basic plugin -- it's recommended you simply copy over the `qr-data-sync/bundler-plugins/vite.mjs` plugin and make necessary changes.
45
+
46
+
#### SSR Breakage
47
+
48
+
An unfortunate gotcha of tools that wrap Vite (e.g., Astro, Nuxt, etc) and do SSR (server-side rendering) is that they *break* a key assumption/behavior of this module's Vite plugin: the HTML injection of `<script src="/qrds-external-bundle.js"></script>`.
49
+
50
+
As such, you'll likely need to manually add that `<script>` tag to your HTML pages/templates. The Vite plugin still copies that file into the `public/` folder for you, so it should load once the tag is added to your HTML.
45
51
46
52
### Webpack Plugin
47
53
48
54
If using Webpack 5+, make sure you're already using the [HTML Webpack Plugin](https://github.com/jantimon/html-webpack-plugin/) to manage building your `index.html` (and/or other HTML pages).
49
55
50
-
Then import this library's webpack-plugin to manage the loading of its non-ESM dependencies. Add something like the following to your `webpack.config.js`:
56
+
Then import this library's Webpack-plugin to manage the loading of its non-ESM dependencies. Add something like the following to your `webpack.config.js`:
51
57
52
58
```js
53
59
// 'HtmlWebpackPlugin' is a required dependency of the
54
-
// qr-data-sync webpack plugin
60
+
// qr-data-sync Webpack plugin
55
61
importHtmlWebpackPluginfrom"html-webpack-plugin";
56
62
importQRDSfrom"qr-data-sync/bundlers/webpack";
57
63
@@ -71,9 +77,9 @@ export default {
71
77
};
72
78
```
73
79
74
-
This plugin copies the `dist/bundlers/qrds-external-bundle.js` file into the build root (default `dist/`), along with the other bundled files. It also injects a `<script src="qrds-external-bundle.js"></script>` tag into the markup of the `index.html` file (and any other HTML files) that webpack produces for your app.
80
+
This plugin copies the `dist/bundlers/qrds-external-bundle.js` file into the build root (default `dist/`), along with the other bundled files. It also injects a `<script src="qrds-external-bundle.js"></script>` tag into the markup of the `index.html` file (and any other HTML files) that Webpack produces for your app.
75
81
76
-
**Note:** At present, this plugin is not configurable in any way (i.e., calling `QRDS()` above with no arguments). If something about its behavior is not compatible with your webpack project setup -- which can vary widely and be quite complex to predict or support by a basic plugin -- it's recommended you simply copy over the `qr-data-sync/bundler-plugins/webpack.mjs` plugin and make necessary changes.
82
+
**Note:** At present, this plugin is not configurable in any way (i.e., calling `QRDS()` above with no arguments). If something about its behavior is not compatible with your Webpack project setup -- which can vary widely and be quite complex to predict or support by a basic plugin -- it's recommended you simply copy over the `qr-data-sync/bundler-plugins/webpack.mjs` plugin and make necessary changes.
77
83
78
84
## Import/Usage
79
85
@@ -83,4 +89,4 @@ To import and use **qr-data-sync** in a *bundled* browser app:
83
89
import { todo } from"qr-data-sync";
84
90
```
85
91
86
-
When `import`ed like this, both vite and webpack should (via these plugins) properly find and bundle the `dist/bundlers/qrds.js` ESM library module with the rest of your app code, without any further steps necessary.
92
+
When `import`ed like this, both Vite and Webpack should (via these plugins) properly find and bundle the `dist/bundlers/qrds.js` ESM library module with the rest of your app code, hopefully without any further steps necessary.
**QR Data Sync** is a browser library with utils for sharing/synchronizing data via "animated" QR codes.
@@ -13,11 +13,15 @@
13
13
14
14
## Deployment / Import
15
15
16
-
The [**qr-data-sync** npm package](https://npmjs.com/package/webauthn-local-client) includes a `dist/` directory with all files you need to deploy **qr-data-sync** (and its dependencies) into your application/project.
16
+
```cmd
17
+
npm install @lofi/qr-data-sync
18
+
```
19
+
20
+
The [**qr-data-sync** npm package](https://npmjs.com/package/@lofi/webauthn-local-client) includes a `dist/` directory with all files you need to deploy **qr-data-sync** (and its dependencies) into your application/project.
17
21
18
22
If you obtain this library via git instead of npm, you'll need to [build `dist/` manually](#re-building-dist) before deployment.
19
23
20
-
***USING A WEB BUNDLER?** (vite, webpack, etc) Use the `dist/bundlers/*` files and see [Bundler Deployment](BUNDLERS.md) for instructions.
24
+
***USING A WEB BUNDLER?** (Vite, Webpack, etc) Use the `dist/bundlers/*` files and see [Bundler Deployment](BUNDLERS.md) for instructions.
21
25
22
26
* Otherwise, use the `dist/auto/*` files and see [Non-Bundler Deployment](NON-BUNDLERS.md) for instructions.
0 commit comments