Skip to content

zhangHongEn/inject-webpack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

inject-webpack

npm

webpack inject plugin

API

// webpack.config.js
const Inject = require("inject-webpack")

module.exports = {
    entry: {
        a,
        b
    },
    plugins: [
        new ModuleFederation({
          filename: "remoteEntry.js",
          exposes: {
            "App": "src/App",
            "Button": "src/Button"
          },
        }),
        new Inject(() => {
            return `console.log("inject code1")`
        }, {
            // entry: a、b、webpack-dev-server.....
            // remoteEntry: remoteEntry.js
            // exposesEntry: src/App、src/Button
            // default value is ["entry", "remoteEntry"]
            scopes: ["entry", "remoteEntry", "exposesEntry"],
            // In addition to the entry files corresponding to scopes, code is also injected into these files
            extraInjection: [/src\/a\//]
        }),
    ]
}