Skip to content

Commit 24739c6

Browse files
committed
docs: fix and improve resource hosting instructions
1 parent 18566f3 commit 24739c6

File tree

1 file changed

+38
-33
lines changed

1 file changed

+38
-33
lines changed

guide/index.md

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,11 @@ Alternatively, you can use other methods like `IIS` or `Apache` to serve the pro
163163
164164
### Self-Host Resources
165165
166-
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.
166+
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:
167+
168+
1. `document-scanner.ui.xml` - the UI template for the `DocumentScannerView`/viewfinder.
169+
2. `dynamsoft-capture-vision-bundle` - the `node` package for the Dynamsoft Capture Vision (DCV) engine resources.
170+
3. `dynamsoft-capture-vision-data` - the `node` package for DCV engine configuration templates.
167171
168172
#### Download Resources
169173
@@ -174,19 +178,37 @@ First, download a copy of the resources:
174178
2. Extract the contents of the archive, and open the extracted directory in a code editor.
175179
176180
3. Set your [license key](#get-a-trial-license) in the Hello World sample:
177-
1. Open the Hello World sample at ([`/samples/hello-world.html`](https://github.com/Dynamsoft/document-scanner-javascript/blob/main/samples/hello-world.html)).
178181
179-
2. Search for `"YOUR_LICENSE_KEY_HERE"`, then replace it with your actual license key.
182+
1. Open the Hello World sample at ([`/samples/hello-world.html`](https://github.com/Dynamsoft/document-scanner-javascript/blob/main/samples/hello-world.html)).
183+
184+
2. Search for `"YOUR_LICENSE_KEY_HERE"`, then replace it with your actual license key.
180185
181186
4. In the terminal, navigate to the project root directory and run the following to install project dependencies:
182187
183-
```shell
184-
npm install
185-
```
188+
```shell
189+
npm install [email protected]
190+
npm install
191+
```
192+
193+
> [!NOTE]
194+
> We install `dynamsoft-capture-vision-data` as MDS does not use it as a build dependency.
195+
196+
#### Modify the Build Script
197+
198+
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.
199+
200+
```json
201+
"scripts": {
202+
"serve": "node dev-server/index.js",
203+
"build": "rollup -c",
204+
"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",
205+
"build:production": "rollup -c --environment BUILD:production"
206+
},
207+
```
186208
187209
#### Point to Resources
188210
189-
The library uses [`engineResourcePaths`]({{ site.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):
211+
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):
190212
191213
```javascript
192214
const documentScanner = new Dynamsoft.DocumentScanner({
@@ -195,12 +217,8 @@ const documentScanner = new Dynamsoft.DocumentScanner({
195217
cameraEnhancerUIPath: "./dist/document-scanner.ui.xml", // Use the local file
196218
},
197219
engineResourcePaths: {
198-
std: "./dist/libs/dynamsoft-capture-vision-std/dist/",
199-
dip: "./dist/libs/dynamsoft-image-processing/dist/",
200-
core: "./dist/libs/dynamsoft-core/dist/",
201-
license: "./dist/libs/dynamsoft-license/dist/",
202-
cvr: "./dist/libs/dynamsoft-capture-vision-router/dist/",
203-
ddn: "./dist/libs/dynamsoft-document-normalizer/dist/",
220+
bundle: "./dist/libs/dynamsoft-capture-vision-bundle/dist/",
221+
data: "./dist/libs/dynamsoft-capture-vision-data/",
204222
},
205223
});
206224
```
@@ -213,33 +231,20 @@ API Reference:
213231
- [`engineResourcePaths`]({{ site.api }}index.html#engineresourcepaths)
214232
- [`cameraEnhancerUIPath`]({{ site.api }}index.html#cameraenhanceruipaths)
215233
216-
#### Modify the Build Script
234+
#### Build the Project
217235
218-
Update the `scripts` section in `package.json` to automatically copy resources to the output `dist` directory during the build process. This script gets the `dynamsoft-capture-vision-data` package, and moves both `dynamsoft-capture-vision-data` and `dynamsoft-capture-vision-bundle` to `dist/libs/`, which is where we set the resource directory to.
236+
Build the project by running:
219237
220-
```json
221-
"scripts": {
222-
"serve": "node dev-server/index.js",
223-
"build": "rollup -c && npm run copy-libs",
224-
"copy-libs": "npx mkdirp dist/libs && npx cpx \"node_modules/dynamsoft-*/**/*\" dist/libs/ --dereference",
225-
"build:production": "rollup -c --environment BUILD:production"
226-
},
238+
```shell
239+
npm run build
227240
```
228241
229-
#### Serve the Resources
242+
#### Host `node` Packages
230243
231-
The included sample server at `dev-server/index.js` needs an extra statement to serve the resources. Include this line:
232-
233-
```javascript
234-
app.use("/dist/libs", express.static(path.resolve(__dirname, "../dist/libs")));
235-
````
236-
237-
#### Build the Project
238-
239-
Build the project by running:
244+
Move the resources to the set location by running the new `npm` script:
240245
241246
```shell
242-
npm run build
247+
npm run copy-libs
243248
```
244249
245250
#### Serve the Project Locally

0 commit comments

Comments
 (0)