Skip to content

Commit

Permalink
Merge pull request #3 from rambler-digital-solutions/multi-entry
Browse files Browse the repository at this point in the history
feat(multi-entry): add plugin
  • Loading branch information
andrepolischuk committed Oct 17, 2023
2 parents a0ecd9b + f34a619 commit 3f561e1
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
37 changes: 37 additions & 0 deletions packages/multi-entry/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Multi Entry Plugin

Support multiple entries instead of one client

## Install

```
npm install -D @rambler-tech/razzle-multi-entry
```

or

```
yarn add -D @rambler-tech/razzle-multi-entry
```

## Usage

Add the plugin to `razzle.config.js`

```js
const path = require('path')
const MultiEntryPlugin = require('@rambler-tech/razzle-multi-entry')

module.exports = {
plugins: [
MultiEntryPlugin({
mobile: path.resolve(__dirname, 'src/mobile/client'),
desktop: path.resolve(__dirname, 'src/desktop/client')
})
],
modifyWebpackConfig({webpackConfig}) {
// ...
return webpackConfig
}
}
```
29 changes: 29 additions & 0 deletions packages/multi-entry/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module.exports = (entrypoints) => ({
modifyWebpackConfig({env: {target, dev: isDev}, webpackConfig}) {
const isServer = target === 'node'

if (!isServer) {
const clientKeys = Object.keys(entrypoints)

if (isDev) {
const rurl = webpackConfig.entry.client[0]

webpackConfig.entry = () => {
const entryObj = {}

clientKeys.forEach((key) => {
entryObj[key] = [rurl, entrypoints[key]]
})

return entryObj
}

webpackConfig.output.filename = 'static/js/[name].js'
} else {
webpackConfig.entry = {...entrypoints}
}
}

return webpackConfig
}
})
14 changes: 14 additions & 0 deletions packages/multi-entry/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "@rambler-tech/razzle-multi-entry",
"version": "0.0.0",
"main": "index.js",
"license": "MIT",
"sideEffects": false,
"publishConfig": {
"access": "public"
},
"peerDependencies": {
"razzle": ">=4",
"webpack": ">=5"
}
}

0 comments on commit 3f561e1

Please sign in to comment.