vite-plugin-cross-origin-storage 1.3.0 → 1.3.1

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.
Files changed (2) hide show
  1. package/README.md +37 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -43,6 +43,43 @@ export default defineConfig({
43
43
  | `include` | `string \| RegExp \| Array` | `['**/*']` | Pattern to include chunks to be managed by COS. |
44
44
  | `exclude` | `string \| RegExp \| Array` | `undefined` | Pattern to exclude chunks from being managed. |
45
45
 
46
+ ## Recipe: Granular Vendor Splitting
47
+
48
+ To maximize caching benefits, it is recommended to split your `node_modules` dependencies into separate chunks. This ensures that updates to one package (e.g., `react`) do not invalidate the cache for others (e.g., `lodash`).
49
+
50
+ Add the following `manualChunks` configuration to your `vite.config.ts`:
51
+
52
+ ```ts
53
+ // vite.config.ts
54
+ import { defineConfig } from 'vite';
55
+ import cosPlugin from 'vite-plugin-cross-origin-storage';
56
+
57
+ export default defineConfig({
58
+ build: {
59
+ rollupOptions: {
60
+ output: {
61
+ manualChunks(id) {
62
+ if (id.includes('node_modules')) {
63
+ // Split each package into its own chunk
64
+ // e.g. "node_modules/react/..." -> "vendor-react"
65
+ // e.g. "node_modules/@scope/pkg/..." -> "vendor-scope-pkg"
66
+ const parts = id.split('node_modules/')[1].split('/');
67
+ const packageName = parts[0].startsWith('@') ? `${parts[0]}/${parts[1]}` : parts[0];
68
+ return `vendor-${packageName.replace('@', '').replace('/', '-')}`;
69
+ }
70
+ },
71
+ },
72
+ },
73
+ },
74
+ plugins: [
75
+ cosPlugin({
76
+ // Only manage these vendor chunks with COS
77
+ include: ['**/vendor-*'],
78
+ }),
79
+ ],
80
+ });
81
+ ```
82
+
46
83
  ## How It Works
47
84
 
48
85
  1. **Build Time**:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-cross-origin-storage",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "Vite plugin to load chunks from Cross-Origin Storage",
5
5
  "keywords": [
6
6
  "vite",