Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit f956f87

Browse files
author
PSPDFKit
committed
Nutrient Web SDK Webpack Example
0 parents  commit f956f87

14 files changed

+6036
-0
lines changed

Diff for: .eslintrc

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": ["eslint:recommended"],
3+
"env": {
4+
"node": true
5+
},
6+
"rules": {
7+
"no-console": 0
8+
}
9+
}

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist
2+
node_modules

Diff for: LICENSE

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
The PSPDFKit Sample applications are licensed with a modified BSD
2+
license. In plain language: you're allowed to do whatever you wish
3+
with the code, modify, redistribute, embed in your products (free or
4+
commercial), but you must include copyright, terms of usage and
5+
disclaimer as stated in the license.
6+
7+
You will require a commercial PSPDFKit License to run these examples
8+
in non-demo mode. Please refer to [email protected] for details.
9+
10+
Copyright © 2017-present PSPDFKit GmbH.
11+
All rights reserved.
12+
13+
Redistribution and use in source or binary forms,
14+
with or without modification, are permitted provided
15+
that the following conditions are met:
16+
17+
- Redistributions of source code must retain the above copyright
18+
notice, this list of conditions and the following disclaimer.
19+
20+
- Redistributions in binary form must reproduce the above copyright
21+
notice, this list of conditions and the following disclaimer in the
22+
documentation and/or other materials provided with the
23+
distribution.
24+
25+
- Redistributions of PSPDFKit Samples must include attribution to
26+
PSPDFKit, either in documentation or other appropriate media.
27+
28+
- Neither the name of the PSPDFKit, PSPDFKit GmbH, nor its developers
29+
may be used to endorse or promote products derived from
30+
this software without specific prior written permission.
31+
32+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
35+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
37+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
38+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
39+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
40+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
41+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
42+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Diff for: README.md

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
> ⚠️ **Repository Moved**
2+
> This repository has been moved to https://github.com/PSPDFKit/nutrient-web-examples/tree/main/examples/webpack.
3+
> Please update your bookmarks and issues accordingly.
4+
>
5+
> This repo is now archived and will no longer receive updates.
6+
7+
# Nutrient Web SDK Example – Webpack
8+
9+
This example shows how to build a [PSPDFKit for Web](https://www.nutrient.io/sdk/web/) web application with
10+
[webpack](https://webpack.js.org/).
11+
12+
This example uses the Standalone version of [PSPDFKit for Web](https://www.nutrient.io/sdk/web/)
13+
distributed as an npm package.
14+
15+
## Prerequisites
16+
17+
- [Node.js](http://nodejs.org/)
18+
19+
## Support, Issues and License Questions
20+
21+
PSPDFKit offers support for customers with an active SDK license via https://www.nutrient.io/support/request/
22+
23+
Are you [evaluating our SDK](https://www.nutrient.io/try/)? That's great, we're happy to help out! To make sure this is fast, please use a work email and have someone from your company fill out our sales form: https://www.nutrient.io/sales/
24+
25+
## Getting Started
26+
27+
Clone the repo:
28+
29+
```bash
30+
git clone https://github.com/PSPDFKit/pspdfkit-web-example-webpack.git
31+
cd pspdfkit-web-example-webpack
32+
```
33+
34+
Install the project dependencies with `npm`:
35+
36+
```bash
37+
npm install
38+
```
39+
40+
## Running the Example
41+
42+
We are ready to launch the app! 🎉
43+
44+
```bash
45+
npm run start
46+
```
47+
48+
You can now open http://localhost:8080 in your browser and enjoy!
49+
50+
Upload a PDF either via the `Select File` button at top-left or by dropping a PDF into the page.
51+
52+
We put a sample PDF document in the `assets` folder of this project for you to try!
53+
54+
For further instructions please refer to our online guide available at
55+
https://www.nutrient.io/guides/web/current/standalone/adding-to-your-project#toc_install-with-npm
56+
57+
### Development mode
58+
59+
To run the app in development mode run
60+
61+
```bash
62+
npm run start:dev
63+
```
64+
65+
## webpack configuration file
66+
67+
The `webpack` configuration file is located at [./config/webpack.js](config/webpack.js).
68+
69+
## License
70+
71+
This software is licensed under a [modified BSD license](LICENSE).
72+
73+
## Contributing
74+
75+
Please ensure
76+
[you signed our CLA](https://www.nutrient.io/guides/web/current/miscellaneous/contributing/) so we can
77+
accept your contributions.

Diff for: assets/download.svg

+4
Loading

Diff for: assets/example.pdf

234 KB
Binary file not shown.

Diff for: bin/verify-install.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
try {
2+
require("@nutrient-sdk/viewer");
3+
} catch (error) {
4+
if (!/cannot find module/i.test(error.message)) {
5+
return;
6+
}
7+
8+
console.log(
9+
`This application requires you to install PSPDFKit for Web manually using your unique customer or trial url.
10+
For further instructions please refer to our online guide available at:
11+
12+
https://www.nutrient.io/guides/web/current/standalone/adding-to-your-project#toc_install-with-npm`
13+
);
14+
process.exit(1);
15+
}

Diff for: config/webpack.js

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/**
2+
* webpack configuration file used to build both a development and production
3+
* version of the app.
4+
*
5+
* The production version is built in the `./dist` folder. When building the
6+
* development mode it also starts a web server at http://localhost:8080
7+
*
8+
* This configuration file creates two main bundles:
9+
*
10+
* - vendor.js - contains external libraries (including nutrient-viewer.js).
11+
* - app.js - contains the application code.
12+
*
13+
* It also copies the WASM/ASM and CSS files from the npm package folder, since
14+
* `PSPDFKit.load` loads them relative to the application execution path.
15+
*/
16+
17+
const path = require("path");
18+
const HtmlWebpackPlugin = require("html-webpack-plugin");
19+
const CopyWebpackPlugin = require("copy-webpack-plugin");
20+
21+
/**
22+
* Determine whether we are in development mode.
23+
*
24+
* $ NODE_ENV=development webpack --config config/webpack.js
25+
*/
26+
const isDev = process.env.NODE_ENV === "development";
27+
28+
const filesToCopy = [
29+
// PSPDFKit files.
30+
{
31+
from: "./node_modules/@nutrient-sdk/viewer/dist/nutrient-viewer-lib",
32+
to: "./nutrient-viewer-lib",
33+
},
34+
// Application CSS.
35+
{
36+
from: "./src/index.css",
37+
to: "./index.css",
38+
},
39+
// Assets directory.
40+
{
41+
from: "./assets",
42+
to: "./assets",
43+
},
44+
];
45+
46+
/**
47+
* webpack main configuration object.
48+
*/
49+
const config = {
50+
entry: {
51+
// Creates an `app.js` bundle which contains the application code.
52+
app: path.resolve("./src/index.js"),
53+
},
54+
55+
// Configure Compilation Mode
56+
mode: isDev ? "development" : "production",
57+
58+
output: {
59+
path: path.resolve("./dist"),
60+
publicPath: "/",
61+
// [name] is the bundle name from above.
62+
filename: "[name].js",
63+
},
64+
65+
resolve: {
66+
modules: [path.resolve("./src"), path.resolve("./node_modules")],
67+
},
68+
69+
plugins: [
70+
// Automatically insert <script src="[name].js"><script> to the page.
71+
new HtmlWebpackPlugin({
72+
template: path.resolve("./src/index.html"),
73+
chunks: ["vendor", "app"],
74+
}),
75+
76+
// Copy the WASM/ASM and CSS files to the `output.path`.
77+
new CopyWebpackPlugin({
78+
patterns: filesToCopy,
79+
}),
80+
],
81+
82+
optimization: {
83+
splitChunks: {
84+
cacheGroups: {
85+
// Creates a `vendor.js` bundle which contains external libraries (including nutrient-viewer.js).
86+
vendor: {
87+
test: /node_modules/,
88+
chunks: "initial",
89+
name: "vendor",
90+
priority: 10,
91+
enforce: true,
92+
},
93+
},
94+
},
95+
},
96+
};
97+
98+
module.exports = config;

0 commit comments

Comments
 (0)