Skip to content

Commit f868775

Browse files
committed
docs: fix and improve resource hosting instructions
1 parent fe9f2da commit f868775

File tree

1 file changed

+34
-21
lines changed

1 file changed

+34
-21
lines changed

README.md

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ Dynamsoft's **Mobile Document Scanner JavaScript Edition (MDS)** is a web SDK de
1717
- [Use Precompiled Script](#use-precompiled-script)
1818
- [Self-Host Resources](#self-host-resources)
1919
- [Download Resources](#download-resources)
20-
- [Point to Resources](#point-to-resources)
2120
- [Modify the Build Script](#modify-the-build-script)
21+
- [Point to Resources](#point-to-resources)
2222
- [Build the Project](#build-the-project)
23+
- [Host `node` Packages](#host-node-packages)
2324
- [Serve the Project Locally](#serve-the-project-locally)
2425
- [Serve over HTTPS](#serve-over-https)
2526
- [Set MIME Type](#set-mime-type)
@@ -180,7 +181,11 @@ Alternatively, you can use other methods like `IIS` or `Apache` to serve the pro
180181
181182
### Self-Host Resources
182183
183-
By default, the MDS library (whether pre-compiled or self-compiled) fetches resource files (Dynamsoft `node` dependencies and an HTML UI template) from CDNs. Self-hosting library resources gives you full control over hosting your application. Rather than using CDNs to serve these resources, you can instead host these resources on your own servers to deliver to your users directly when they use your application. You can also use this option to host MDS fully offline by pointing to local resources.
184+
By default, the MDS library (whether pre-compiled or self-compiled) fetches resource files (Dynamsoft `node` dependencies and an HTML UI template) from CDNs. Self-hosting library resources gives you full control over hosting your application. Rather than using CDNs to serve these resources, you can instead host these resources on your own servers to deliver to your users directly when they use your application. You can also use this option to host MDS fully offline by pointing to local resources. Here are the resources to self-host:
185+
186+
1. `document-scanner.ui.xml` - the UI template for the `DocumentScannerView`/viewfinder.
187+
2. `dynamsoft-capture-vision-bundle` - the `node` package for the Dynamsoft Capture Vision (DCV) engine resources.
188+
3. `dynamsoft-capture-vision-data` - the `node` package for DCV engine configuration templates.
184189
185190
#### Download Resources
186191
@@ -199,12 +204,29 @@ First, download a copy of the resources:
199204
4. In the terminal, navigate to the project root directory and run the following to install project dependencies:
200205
201206
```shell
207+
npm install [email protected]
202208
npm install
203209
```
210+
211+
> [!NOTE]
212+
> We install `dynamsoft-capture-vision-data` as MDS does not use it as a build dependency.
213+
214+
#### Modify the Build Script
215+
216+
Add a script by updating the `scripts` property in `package.json` that automatically copies the two `node` dependencies to the output `dist` directory during the build process. We will configure MDS to request the resources here.
217+
218+
```json
219+
"scripts": {
220+
"serve": "node dev-server/index.js",
221+
"build": "rollup -c",
222+
"copy-libs": "npx mkdirp dist/libs && npx cpx \"node_modules/dynamsoft-capture-vision-bundle/**/*\" dist/libs/[email protected]/ -L && npx cpx \"node_modules/dynamsoft-capture-vision-data/**/*\" dist/libs/[email protected]/ -L",
223+
"build:production": "rollup -c --environment BUILD:production"
224+
},
225+
```
204226
205227
#### Point to Resources
206228
207-
The library uses [`engineResourcePaths`](https://www.dynamsoft.com/mobile-document-scanner/docs/web/api/index.html#engineresourcepaths) to locate required Dynamsoft `node` dependencies by pointing to the location of the resources on your web server. The library also uses `scannerViewConfig.cameraEnhancerUIPath` similarly to set the path for the HTML UI template of the `ScannerView`. Later steps will place both the `node` dependencies and the HTML template in the local `dist` directory. Therefore, set `engineResourcePaths` in the MDS constructor to point to the local `dist` directory (along with setting your license key, and all other configurations):
229+
The library uses [`engineResourcePaths`](https://www.dynamsoft.com/mobile-document-scanner/docs/web/api/index.html#engineresourcepaths) to locate required Dynamsoft `node` dependencies by pointing to the location of the resources on your web server. The library also uses `scannerViewConfig.cameraEnhancerUIPath` similarly to set the path for the HTML UI template of the `ScannerView`.Therefore, set `engineResourcePaths` in the MDS constructor to point to the local `dist` directory, where the resources are located (along with setting your license key, and all other configurations):
208230
209231
```javascript
210232
const documentScanner = new Dynamsoft.DocumentScanner({
@@ -213,12 +235,8 @@ const documentScanner = new Dynamsoft.DocumentScanner({
213235
cameraEnhancerUIPath: "./dist/document-scanner.ui.xml", // Use the local file
214236
},
215237
engineResourcePaths: {
216-
std: "./dist/libs/dynamsoft-capture-vision-std/dist/",
217-
dip: "./dist/libs/dynamsoft-image-processing/dist/",
218-
core: "./dist/libs/dynamsoft-core/dist/",
219-
license: "./dist/libs/dynamsoft-license/dist/",
220-
cvr: "./dist/libs/dynamsoft-capture-vision-router/dist/",
221-
ddn: "./dist/libs/dynamsoft-document-normalizer/dist/",
238+
bundle: "./dist/libs/dynamsoft-capture-vision-bundle/dist/",
239+
data: "./dist/libs/dynamsoft-capture-vision-data/",
222240
},
223241
});
224242
```
@@ -231,25 +249,20 @@ API Reference:
231249
- [`engineResourcePaths`](https://www.dynamsoft.com/mobile-document-scanner/docs/web/api/index.html#engineresourcepaths)
232250
- [`cameraEnhancerUIPath`](https://www.dynamsoft.com/mobile-document-scanner/docs/web/api/index.html#cameraenhanceruipaths)
233251
234-
#### Modify the Build Script
252+
#### Build the Project
235253
236-
Update the `scripts` section in `package.json` to automatically copy resources to the output `dist` directory during the build process.
254+
Build the project by running:
237255
238-
```json
239-
"scripts": {
240-
"serve": "node dev-server/index.js",
241-
"build": "rollup -c && npm run copy-libs",
242-
"copy-libs": "npx mkdirp dist/libs && npx cpx \"node_modules/dynamsoft-*/**/*\" dist/libs/ --dereference",
243-
"build:production": "rollup -c --environment BUILD:production"
244-
},
256+
```shell
257+
npm run build
245258
```
246259
247-
#### Build the Project
260+
#### Host `node` Packages
248261
249-
Build the project by running:
262+
Move the resources to the set location by running the new `npm` script:
250263
251264
```shell
252-
npm run build
265+
npm run copy-libs
253266
```
254267
255268
#### Serve the Project Locally

0 commit comments

Comments
 (0)