For my project, I need to deploy "extension scripts" into a vendor managed NodeJS environment that gets run as a part of a pipeline of work at different extension/hook points. My vendor expects a single JS file per "extension point". I found myself repeating functionality so extracted it to files/modules. To assemble the final scripts, I've been developing some WebPack config to inline the local modules. Because the runtime is Node (as opposed to a browser) I don't need the optimisations, or transpilation features. However with my current config, I still have WebPack generating some boilerplate relating to module loading that I don't need but I don't know if, or how to turn it off.
For example
// my-module.js
exports.doSomething = function() { return "something"; }
// my-script.js
const lib = require("lib");
const { doSomething } = require("./my-module");
exports.extension = function() {
return doSomething().toUpperCase();
}
With the following config
module.exports = {
target: "node",
mode: "none",
entry: "my-script.js",
output: {
libraryTarget: "commonjs2",
path: path.resolve(__dirname, "build"),
filename: "my-script.js"
},
externals: [
require("webpack-node-externals")()
]
};
WebPack creates:
module.exports =
/******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ([
/* 0 */
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
const lib = __webpack_require__(1);
const { doSomething } = __webpack_require__(2);
exports.extension = function() {
return doSomething().toUpperCase();
}
/***/ }),
/* 1 */
/***/ ((module) => {
"use strict";
module.exports = require("lib");;
/***/ }),
/* 2 */
/***/ ((__unused_webpack_module, exports) => {
"use strict";
exports.doSomething = function() {
return "something";
}
/***/ })
/******/ ]);
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
// ... Omitted for brevity
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/ // module exports must be returned from runtime so entry inlining is disabled
/******/ // startup
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })()
;
Is there a way to make WebPack simply inline the local code without generating the extra module loading boilerplate?