Say we have a util.js
contains functions a
and b
:
// util.js
export function a() {
...
}
export function b() {
...
}
And I require them in index.js
:
// index.js
export default function main() {
const {a, b} = require('./util');
...
a(); // use them somewhere
b();
}
But I want to replace the require function to its source code like this before the bundling:
// replaced index.js
export default function main() {
const a = function () {
// ... source code from util.js
};
const b = function () {
// ... source code from util.js
};
...
a(); // use them somewhere
b();
}
I'm not that familiar with webpack plugins and hooks API. Is this possible and if yes, how to do it?
Thanks!
One solution not that clever, do string replace directly by string-replace-loader
.