I'm trying to write a plugin (or find one) that for each entry, I can add extra code.
If I have 2 entry files:
// entry1.js
import React from "react";
export default function() {
return (
<div>
Entry 1
</div>
);
}
// entry2.js
import React from "react";
export default function() {
return (
<div>
Entry 2
</div>
);
}
and a webpack config file:
module.exports = {
entry: {
entry1: "./entry1.js",
entry2: "./entry2.js",
},
output: {
path: path.join(__dirname, "../output"),
filename: "js/[name].js",
publicPath: "/",
},
}
Then each webpack entry should have the following added:
import React from "react";
import ReactDOM from "react-dom";
import Component from "????";
ReactDOM.render(<Component />, document.getElementById("mount"));
Where ????
is ./entry1.js
for entry1, and ./entry2.js
for entry2, etc.
I've tried child compilation inside the emit phase, but referencing the existing module is a problem, and I think that it should probably be done sooner than emit.
With code like that above, I feel that I really need to replace the entry module with a new module that references the old entry module all before the loaders act on them.
Not really sure where to go from here, so any guidance would be appreciated