I need to migrate legacy system to webpack-4
from gulp
. I stucked with concatenating few scripts into one. My goal is to achieve pure concatenation without additional staff generated by webpack. So result from gulp must equals result from webpack.
I used webpack-concat-plugin.
Here is my webpack.config.js
const ConcatPlugin = require('webpack-concat-plugin');
module.exports = [
{
plugins: [
new ConcatPlugin(
{
fileName: "js/bootstrap/bootstrap.js",
filesToConcat: [
"./js/bootstrap/button.js",
"./js/bootstrap/collapse.js",
"./js/bootstrap/datetimepicker.js", // this script requires jQuery and Moment.js
"./js/bootstrap/dropdown.js",
"./js/bootstrap/modal.js",
"./js/bootstrap/multiselect.js",
"./js/bootstrap/tooltip.js",
"./js/bootstrap/popover.js",
"./js/bootstrap/select2.js",
"./js/bootstrap/tab.js",
"./js/bootstrap/transition.js"
]
}
)
}]
This produces bundle, but I got extra code inside like:
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
and depencencies (for example to jQuery as below)
/***/ }),
/***/ "./node_modules/jquery/dist/jquery.js":
/*!********************************************!*\
!*** ./node_modules/jquery/dist/jquery.js ***!
\********************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
eval("var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*!\n * jQuery JavaScript Library v2.2.4\n * http://jquery.com/\n *\n *
It means that webpack added by default dependency defined in require
in ./js/bootstrap/datetimepicker.js
. Of course added also dependencies from moment.js.
My bundle is terrible big, because it contains additional libraries I didn't want to include. I have external dependencies to jQuery
and moment.js
I tried to use webpack externals:
externals: {
"jquery": "jQuery"
},
but still jQuery is included.
Is there any way to do pure concatenation for webpack without webpack bootstrap code?
Thanks
Rafal