isahaq-barcode 1.8.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -104,13 +104,49 @@ const generateBarcode = async () => {
104
104
  };
105
105
  ```
106
106
 
107
- ### Alternative for Client-Side
107
+ ### Webpack Configuration
108
108
 
109
- For browser-based barcode generation, consider:
109
+ If you're using webpack and encountering module resolution issues, add this to your webpack config:
110
110
 
111
- - **jsbarcode** - Client-side barcode generation
112
- - **qrcode** - Client-side QR code generation
113
- - **Server-side API** - Use this package on your backend
111
+ ```javascript
112
+ module.exports = {
113
+ resolve: {
114
+ fallback: {
115
+ fs: false,
116
+ path: false,
117
+ os: false,
118
+ canvas: false,
119
+ pdfkit: false,
120
+ chalk: false,
121
+ ora: false,
122
+ commander: false,
123
+ },
124
+ },
125
+ };
126
+ ```
127
+
128
+ ### Next.js Configuration
129
+
130
+ For Next.js projects, add this to your `next.config.js`:
131
+
132
+ ```javascript
133
+ module.exports = {
134
+ webpack: config => {
135
+ config.resolve.fallback = {
136
+ ...config.resolve.fallback,
137
+ fs: false,
138
+ path: false,
139
+ os: false,
140
+ canvas: false,
141
+ pdfkit: false,
142
+ chalk: false,
143
+ ora: false,
144
+ commander: false,
145
+ };
146
+ return config;
147
+ },
148
+ };
149
+ ```
114
150
 
115
151
  **Global CLI Installation:**
116
152
 
package/index.js CHANGED
@@ -5,17 +5,29 @@
5
5
 
6
6
  // Detect environment
7
7
  const isBrowser =
8
- typeof window !== 'undefined' && typeof document !== 'undefined';
8
+ typeof window !== 'undefined' &&
9
+ typeof document !== 'undefined' &&
10
+ typeof process === 'undefined';
9
11
 
10
12
  if (isBrowser) {
11
13
  // Browser environment - use browser-compatible version
12
14
  module.exports = require('./browser');
13
15
  } else {
14
16
  // Node.js environment - use full-featured version
15
- const BarcodeService = require('./src/services/BarcodeService');
16
- const QrCodeBuilder = require('./src/builders/QrCodeBuilder');
17
- const { BarcodeTypes } = require('./src/types/BarcodeTypes');
18
- const { RenderFormats } = require('./src/renderers/RenderFormats');
17
+ let BarcodeService, QrCodeBuilder, BarcodeTypes, RenderFormats;
18
+
19
+ try {
20
+ BarcodeService = require('./src/services/BarcodeService');
21
+ QrCodeBuilder = require('./src/builders/QrCodeBuilder');
22
+ BarcodeTypes = require('./src/types/BarcodeTypes');
23
+ RenderFormats = require('./src/renderers/RenderFormats');
24
+ } catch {
25
+ // If server dependencies are not available, fall back to browser version
26
+ console.warn(
27
+ 'Server dependencies not available, falling back to browser-compatible version'
28
+ );
29
+ module.exports = require('./browser');
30
+ }
19
31
 
20
32
  // Main service instance
21
33
  const barcodeService = new BarcodeService();
package/package.json CHANGED
@@ -1,13 +1,17 @@
1
1
  {
2
2
  "name": "isahaq-barcode",
3
- "version": "1.8.0",
3
+ "version": "1.9.0",
4
4
  "description": "A universal barcode generator package supporting multiple barcode types and output formats, with extra features like batch generation, watermarking, validation, CLI, and Express.js integration",
5
5
  "main": "index.js",
6
6
  "browser": {
7
7
  "fs": false,
8
8
  "path": false,
9
9
  "os": false,
10
- "canvas": false
10
+ "canvas": false,
11
+ "pdfkit": false,
12
+ "chalk": false,
13
+ "ora": false,
14
+ "commander": false
11
15
  },
12
16
  "bin": {
13
17
  "barcode-generate": "./bin/generate.js"
@@ -47,13 +51,15 @@
47
51
  "author": "hmisahaq01@gmail.com",
48
52
  "license": "MIT",
49
53
  "dependencies": {
54
+ "jsbarcode": "^3.12.1",
55
+ "qrcode": "^1.5.4"
56
+ },
57
+ "optionalDependencies": {
50
58
  "canvas": "^3.2.0",
51
59
  "chalk": "^5.6.2",
52
60
  "commander": "^14.0.1",
53
- "jsbarcode": "^3.12.1",
54
61
  "ora": "^9.0.0",
55
- "pdfkit": "^0.17.2",
56
- "qrcode": "^1.5.4"
62
+ "pdfkit": "^0.17.2"
57
63
  },
58
64
  "peerDependencies": {
59
65
  "jsbarcode": "^3.12.1",
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Webpack configuration for isahaq-barcode
3
+ * This helps bundlers understand which modules to exclude in browser environments
4
+ */
5
+
6
+ module.exports = {
7
+ resolve: {
8
+ fallback: {
9
+ fs: false,
10
+ path: false,
11
+ os: false,
12
+ canvas: false,
13
+ pdfkit: false,
14
+ chalk: false,
15
+ ora: false,
16
+ commander: false,
17
+ },
18
+ },
19
+ externals: {
20
+ canvas: 'canvas',
21
+ pdfkit: 'pdfkit',
22
+ chalk: 'chalk',
23
+ ora: 'ora',
24
+ commander: 'commander',
25
+ },
26
+ };