Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Commit

Permalink
feat: add entry name option (#4)
Browse files Browse the repository at this point in the history
* add entry name option

* fix readme

* fix review

* fix review

* spacing

Co-authored-by: Atipat Pankong <[email protected]>
  • Loading branch information
JAmoMES and Atipat Pankong authored Jul 22, 2022
1 parent 55b4918 commit 89a4029
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ module.exports = {
}
```

custom entry name

```js
const { SourceReplacementPlugin } = require('source-replacement-webpack-plugin')

module.exports = {
...
plugins: [
...,
new SourceReplacementPlugin('main') // default is 'client'
]
}
```

#### On your browser

Enter page with the following example
Expand Down
10 changes: 9 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ const CODE_BLOCKER_SRC = path.resolve(
'code-blocker.js',
)

const DEFAULT_ENTRY_NAME = 'client'

export class SourceReplacementPlugin {
private readonly entryName: string

constructor(entryName = DEFAULT_ENTRY_NAME) {
this.entryName = entryName
}

apply(compiler: Webpack.Compiler) {
new AddAssetHtmlWebpackPlugin({
filepath: require.resolve('source-replacement'),
Expand All @@ -21,6 +29,6 @@ export class SourceReplacementPlugin {
},
}).apply(compiler)

new InjectEntryPlugin({ entry: 'main', filepath: CODE_BLOCKER_SRC }).apply(compiler)
new InjectEntryPlugin({ entry: this.entryName, filepath: CODE_BLOCKER_SRC }).apply(compiler)
}
}
21 changes: 9 additions & 12 deletions test/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ const HTMLWebpackPlugin = require('html-webpack-plugin')
const { SourceReplacementPlugin } = require('../build')

module.exports = {
entry: path.resolve(__dirname, 'index.js'),
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'build')
},
plugins: [
new HTMLWebpackPlugin(),
new SourceReplacementPlugin(),
],
target: 'node',
mode: 'development',
devtool: false,
entry: path.resolve(__dirname, 'index.js'),
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'build'),
},
plugins: [new HTMLWebpackPlugin(), new SourceReplacementPlugin('main')],
target: 'node',
mode: 'development',
devtool: false,
}

0 comments on commit 89a4029

Please sign in to comment.