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

Commit

Permalink
feat: use bundle more plugin (#7)
Browse files Browse the repository at this point in the history
* feature: 

* use bundle more plugin
  • Loading branch information
JAmoMES authored Aug 1, 2022
1 parent 8f87380 commit 040cccc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 28 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"webpack-cli": "4.9.1"
},
"dependencies": {
"bundle-more-webpack-plugin": "2.0.0",
"source-replacement": "2.0.1"
}
}
33 changes: 5 additions & 28 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,7 @@
import Webpack from 'webpack'
import { Compiler } from 'webpack'
import { BundleMoreWebpackPlugin } from 'bundle-more-webpack-plugin'

const DEFAULT_ENTRY_NAME = 'client'

function injectEntry(
options: Compiler['options'],
entryName: string,
injectFilepath: string[],
): void {
const entry: any =
typeof options.entry === 'function' ? options.entry() : Promise.resolve(options.entry)

options.entry = () =>
entry.then((e: any) => {
const injectEntry: typeof e[string] | undefined = e[entryName]

if (!injectEntry?.import) {
throw new Error(
`Could not find an entry named '${entryName}'. See https://webpack.js.org/concepts/entry-points/ for an overview of webpack entries.`,
)
}

injectEntry.import.unshift(...injectFilepath)

return e
})
}

export class SourceReplacementPlugin {
private readonly entryName: string

Expand All @@ -35,9 +10,11 @@ export class SourceReplacementPlugin {
}

apply(compiler: Webpack.Compiler) {
injectEntry(compiler.options, this.entryName, [
const sourceReplacementEntry = [
require.resolve('source-replacement'),
require.resolve('source-replacement/build/code-blocker.js'),
])
]

new BundleMoreWebpackPlugin(sourceReplacementEntry, this.entryName).apply(compiler)
}
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,11 @@ builtins@^1.0.3:
resolved "https://registry.yarnpkg.com/builtins/-/builtins-1.0.3.tgz#cb94faeb61c8696451db36534e1422f94f0aee88"
integrity sha1-y5T662HIaWRR2zZTThQi+U8K7og=

[email protected]:
version "2.0.0"
resolved "https://registry.yarnpkg.com/bundle-more-webpack-plugin/-/bundle-more-webpack-plugin-2.0.0.tgz#2694731e9a609e563816419e748070263643e7f4"
integrity sha512-LqX0dWN3yxPaGcmX1MKcHUcBmfZ/lS+6m1H/ZkFI9Vj4guVwMOAeyK2UBPdjMv2GfFFDfnC/2NXaHmlZOczWSg==

cacache@^15.0.3, cacache@^15.0.5, cacache@^15.2.0, cacache@^15.3.0:
version "15.3.0"
resolved "https://registry.yarnpkg.com/cacache/-/cacache-15.3.0.tgz#dc85380fb2f556fe3dda4c719bfa0ec875a7f1eb"
Expand Down

0 comments on commit 040cccc

Please sign in to comment.