Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@
"parserOptions": {
"project": "./tsconfig.json"
}
},
{
"files": ["*"],
"rules": {
"import/extensions": ["error", "ignorePackages"]
}
}
],
"settings": {
Expand Down
2 changes: 1 addition & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
tabWidth: 4,
singleQuote: true,
trailingComma: 'all',
Expand Down
16 changes: 14 additions & 2 deletions example/.eslintrc.js → example/.eslintrc.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
module.exports = {
import path from 'path';
import {fileURLToPath} from 'url';

const filename = fileURLToPath(import.meta.url);
const dirname = path.dirname(filename);

export default {
root: true,
env: {
browser: true,
Expand All @@ -9,7 +15,7 @@ module.exports = {
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
tsconfigRootDir: __dirname,
tsconfigRootDir: dirname,
},
extends: ['eslint:recommended', 'airbnb', 'plugin:@typescript-eslint/recommended', 'plugin:react/jsx-runtime', 'plugin:jsx-a11y/recommended', 'plugin:react/recommended', 'prettier'],
plugins: ['@typescript-eslint', 'react', 'jsx-a11y'],
Expand Down Expand Up @@ -65,6 +71,12 @@ module.exports = {
project: './tsconfig.json',
},
},
{
files: ['*'],
rules: {
'import/extensions': ['error', 'ignorePackages'],
},
},
],
settings: {
react: {
Expand Down
921 changes: 461 additions & 460 deletions example/package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.0",
"description": "react-fast-pdf",
"main": "./src/index.js",
"type": "module",
"files": [
"dist",
"src"
Expand Down Expand Up @@ -61,7 +62,7 @@
"style-loader": "^3.3.3",
"ts-loader": "^9.4.4",
"typescript": "^5.1.6",
"webpack": "^5.88.2",
"webpack": "^5.104.1",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1"
}
Expand Down
5 changes: 4 additions & 1 deletion example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import './index.css';
function App() {
const [file, setFile] = useState<string | null>(null);

// `.default` is required when referencing the legacy CJS package.
const packageName = ('default' in ReactFastPDF ? (ReactFastPDF.default as {PackageName: string}) : ReactFastPDF).PackageName;

return (
<main className="container">
<h1 className="title">Hello, I am {ReactFastPDF.PackageName}!</h1>
<h1 className="title">Hello, I am {packageName}!</h1>

{file ? (
<>
Expand Down
1 change: 1 addition & 0 deletions example/src/pdf.worker.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'pdfjs-dist/build/pdf.worker.min.mjs';
2 changes: 1 addition & 1 deletion example/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions": {
"target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"jsx": "react" /* Specify what JSX code is generated. */,
"module": "commonjs" /* Specify what module code is generated. */,
"module": "nodenext" /* Specify what module code is generated. */,
"rootDir": "./src" /* Specify the root folder within your source files. */,
"declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
"declarationMap": true /* Create sourcemaps for d.ts files. */,
Expand Down
28 changes: 17 additions & 11 deletions example/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
import path from 'path';
import {fileURLToPath} from 'url';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';

const cMapsDir = path.join(path.dirname(require.resolve('pdfjs-dist/package.json')), 'cmaps');
const filename = fileURLToPath(import.meta.url);
const dirname = path.dirname(filename);

module.exports = {
entry: path.join(__dirname, 'src', 'index.js'),
const pdfjsPkgUrl = import.meta.resolve('pdfjs-dist/package.json');
const pdfjsPkgPath = fileURLToPath(pdfjsPkgUrl);

const cMapsDir = path.join(path.dirname(pdfjsPkgPath), 'cmaps');

export default {
entry: path.join(dirname, 'src', 'index.js'),
output: {
path: path.resolve(__dirname, 'dist'),
path: path.resolve(dirname, 'dist'),
filename: 'bundle.js',
},
resolve: {
modules: [path.join(__dirname, 'src'), 'node_modules'],
modules: [path.join(dirname, 'src'), 'node_modules'],
alias: {
react: path.join(__dirname, 'node_modules', 'react'),
react: path.join(dirname, 'node_modules', 'react'),
},
extensions: ['.tsx', '.ts', '.js'],
},
Expand Down Expand Up @@ -53,7 +59,7 @@ module.exports = {
},
plugins: [
new HtmlWebpackPlugin({
template: path.join(__dirname, 'public', 'index.html'),
template: path.join(dirname, 'public', 'index.html'),
}),
new CopyWebpackPlugin({
patterns: [
Expand Down
Loading
Loading