friendly-errors-webpack-plugin
friendly-errors-webpack-plugin copied to clipboard
Can you help me with a webpack custom plugin?
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