M
M
mixtape2015-12-14 00:52:02
webpack
mixtape, 2015-12-14 00:52:02

How to exclude require parsing in module list in webpack?

Guru advice needed. There is a directory containing jade templates. I want to make simple compilation in html. That is the simple principle "to compile and spit out" is necessary. In some js modules, of course, these jade templates are required, which are processed by such a chain of file!jade-html loaders in the webpack config. That is, html is first compiled, which is passed to the file-loader, which saves the compiled version in the directory. The problem is that after running webpack, additional modules are created in the build, due to the fact that the js entry point has require("./tmpl.jade"). How can I make loaders run, but the presence of this require does not lead to the creation of modules in the assembly of this entry point?
Example:
webpack.config.js:

"use strict";

let path = require("path");

module.exports = {
  context: __dirname,
  entry: {
    index: "./js/index"
  },
  output: {
    path: path.resolve(__dirname, "./dist"),
    filename: "./[name].min.js",
    publicPath: "/"
  },
  plugins: [],
  module: {
    loaders: [
      { test: /\.jade$/, loader: "file?name=[name].html!jade-html" }
    ]
  }
};

entry point ./js/index.js:
"use strict";
require("./template.jade");
console.log("etc");

the template compiled fine and created (dist/template.html), but this created an unnecessary second module in dist/index.min.js due to require:
...
/* 0 */
/*!*************************!*\
  !*** ./js/index.js ***!
  \*************************/
  function(module, exports, __webpack_require__) {
  "use strict";
  __webpack_require__(/*! ./template.jade */ 1);
  console.log("etc");
    },
/* 1 */
/*!********************************!*\
  !*** ./js/template.jade ***!
  \********************************/
  function(module, exports, __webpack_require__) {
  module.exports = __webpack_require__.p + "./dist/template.html";
  }
...

It is necessary that this is not reflected in the js assembly, that is:
...
/* 0 */
/*!*************************!*\
  !*** ./js/index.js ***!
  \*************************/
  function(module, exports, __webpack_require__) {
  "use strict";
  console.log("etc");
  }
...

How is this task solved by means of webpack?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question