-
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.
Merge pull request #3 from rambler-digital-solutions/multi-entry
feat(multi-entry): add plugin
- Loading branch information
Showing
3 changed files
with
80 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,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 | ||
} | ||
} | ||
``` |
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,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 | ||
} | ||
}) |
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-multi-entry", | ||
"version": "0.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"sideEffects": false, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"peerDependencies": { | ||
"razzle": ">=4", | ||
"webpack": ">=5" | ||
} | ||
} |