New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Loader cache is not used for multiple compiler runs #7533
Comments
/cc @ooflorent |
Are you using |
@sokra wow cool! didn't know about this caching limitation. After switching to development in the code Expand the source codeindex.js const webpackConfig = {
entry: { main: "./index.js" },
mode: "development", // <-------- switch to development
context: __dirname,
module: {
rules: [
{
test: /\.js$/,
loader: require.resolve("./loader")
}
]
},
output: {
path: __dirname + "/dist"
}
};
const webpack = require("webpack");
compiler = webpack(webpackConfig);
// Start first run:
compiler.run(() => {
// Start second run:
compiler.run(() => {
// Log output:
console.log(
"Content of compilation result",
require("fs").readFileSync("./dist/main.js", {
encoding: "utf8"
})
);
});
}); loader.js let runs = 0;
module.exports = function() {
runs++;
return "console.log(' ######## Loader Runs " + runs + " ########');";
}; Webpack generates the expected output: Expand the generated resultContent of compilation result /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = "./index.js");
/******/ })
/************************************************************************/
/******/ ({
/***/ "./index.js":
/*!******************!*\
!*** ./index.js ***!
\******************/
/*! no static exports found */
/***/ (function(module, exports) {
eval("console.log(' ######## Loader Runs 1 ########');\n\n//# sourceURL=webpack:///./index.js?");
/***/ })
/******/ });
|
It's not a limitation. It's only the default setting. Feel free to set |
Thanks - it's a perfect default setting. |
Bug report
What is the current behavior?
Multiple calls to
compiler.run()
won't retrieve data from the loader cache.If the current behavior is a bug, please provide the steps to reproduce.
index.js
loader.js
The dist/main.js contains
Loader Runs 2
This means that the loader was called twice although no file was changed.
What is the expected behavior?
I would expect that the loader would have been called only once so the dist/main.js should contain
Loader Runs 1
Other relevant information:
webpack version: 4.12.0
Node.js version: v6.9.1
Operating System: OSX 10.11.6
The text was updated successfully, but these errors were encountered: