Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

126
Views
Which hook should I choose when I am writting a webpack plugin

I am writting a webpack plugin (for version 4.41.5) in order to do the following job before the "real compile" time:
search the all file with the pattern like **/foo/index.page.vue, **/bar/index.page.vue, **/index.page.vue, get the path of those files, then generate javascript code like below and finally insert them into the corresponding code.

[
  {
    name: "foo"
    path: "/foo",
    component: import(/* webpackChunkName: "foo" */ "[any-path-prefix]/foo/index.page.vue"),
  },
  {
    name: "bar"
    path: "/bar",
    component: import(/* webpackChunkName: "bar" */ "[any-path-prefix]/bar/index.page.vue"),
  },
  ...
];

the plugin should be invoke in both product and development mode only once in each compile or re-compile time. so which hook should I choose in best practice?

I tried to invoke the plugin in the "before-compile" hook. I don't konw if it is the best hook but this hook seems to be invoked too much times in compiling at product mode. my code is like

function RegisterRoutePlugin(config) {
  // do something...
}
RegisterRoutePlugin.prototype.apply = function (compiler) {
  compiler.plugin('before-compile', (compilation, callback) => {
     // do something...
     callback()
  })
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!