Skip to content

Can you help me with a webpack custom plugin? #9

@AlonsoK28

Description

@AlonsoK28

I have tried to write a custom plugin for my project using webpack 5

I cant use the webpack dev server on my project because is on PHP, then I want to write a plugin that open the browser when the first compilation ends

This is my example, but it does nothing

const open = require('open'); 
const myUrl = 'localhost/project-2' 
// docs https://webpack.js.org/contribute/writing-a-plugin/#creating-a-plugin 
// example https://medium.com/finnovate-io/make-webpack-exit-on-compilation-errors-16d2eec03391 
class OpenBrowserPlugin { 
  apply(compiler) { 
    compiler.hooks.done.tapAsync('MyPlugin', async function (stats, callback) { 
      await open(myUrl, { app: { name: 'google chrome', arguments: ['--incognito'] } }); 
      console.log('will open browser'); 
      callback(); 
    }); 
  } 
} 

module.exports = OpenBrowserPlugin;

Greetings

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions