-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e76aa7
commit 54f3562
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Chunks Plugin | ||
|
||
Support for split chunks | ||
|
||
## Install | ||
|
||
``` | ||
npm install -D @rambler-tech/razzle-chunks | ||
``` | ||
|
||
or | ||
|
||
``` | ||
yarn add -D @rambler-tech/razzle-chunks | ||
``` | ||
|
||
## Usage | ||
|
||
Add the plugin to `razzle.config.js` | ||
|
||
```js | ||
const path = require('path') | ||
const ChunksPlugin = require('@rambler-tech/razzle-chunks') | ||
|
||
module.exports = { | ||
plugins: [ | ||
ChunksPlugin({ | ||
vendors: /[\\/]node_modules[\\/]*[\\/]/ | ||
}) | ||
], | ||
modifyWebpackConfig({webpackConfig}) { | ||
// ... | ||
return webpackConfig | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module.exports = (groups) => ({ | ||
modifyWebpackConfig({env: {target}, webpackConfig}) { | ||
const isBrowser = target === 'web' | ||
|
||
if (isBrowser) { | ||
const entries = Object.keys(webpackConfig.entry) | ||
|
||
webpackConfig.optimization = { | ||
splitChunks: { | ||
cacheGroups: {} | ||
} | ||
} | ||
|
||
for (const entry of entries) { | ||
for (const group in groups) { | ||
webpackConfig.optimization.splitChunks.cacheGroups[ | ||
`${entry}.${group}` | ||
] = { | ||
test: groups[group], | ||
name: `${entry}.${group}`, | ||
chunks: (chunk) => chunk.name === entry, | ||
enforce: true, | ||
priority: 1 | ||
} | ||
} | ||
} | ||
} | ||
|
||
return webpackConfig | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "@rambler-tech/razzle-chunks", | ||
"version": "0.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"sideEffects": false, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"peerDependencies": { | ||
"razzle": ">=4", | ||
"webpack": ">=5" | ||
} | ||
} |