diff --git a/README.md b/README.md index 9009ca3..5f38d84 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,13 @@ # web-ext-webpack-plugin A webpack plugin for web-ext + +**webpack.config.js** +```js +const WebExtWebpackPlugin = require('web-ext-webpack-plugin'); + +module.exports = { + plugins: [ + new WebExtWebpackPlugin({ sourceDir: './extension-dist' }) + ] +} +``` diff --git a/web-ext-webpack-plugin.js b/web-ext-webpack-plugin.js index b53a868..3ec9896 100644 --- a/web-ext-webpack-plugin.js +++ b/web-ext-webpack-plugin.js @@ -6,15 +6,17 @@ const webExt = require('web-ext').default; const pluginName = 'WebExtWebpackPlugin'; class WebExtWebpackPlugin { - constructor() { + constructor({ + sourceDir = process.cwd(), + artifactsDir = path.join(sourceDir, 'web-ext-artifacts') + } = {}) { this.runner = null; this.watchMode = false; + this.sourceDir = sourceDir; + this.artifactsDir = artifactsDir; } apply(compiler) { - const sourceDir = process.cwd(); - const artifactsDir = path.join(sourceDir, 'web-ext-artifacts'); - const watchRun = async (compiler) => { this.watchMode = true; }; @@ -22,12 +24,12 @@ class WebExtWebpackPlugin { const afterEmit = async (compilation) => { try { await webExt.cmd.lint({ - artifactsDir, + artifactsDir: this.artifactsDir, boring: false, metadata: false, output: 'text', pretty: false, - sourceDir, + sourceDir: this.sourceDir, verbose: false, warningsAsErrors: true, }, { @@ -44,8 +46,8 @@ class WebExtWebpackPlugin { } await webExt.cmd.run({ - sourceDir, - artifactsDir, + sourceDir: this.sourceDir, + artifactsDir: this.artifactsDir, noReload: true, }, { }).then((runner) => this.runner = runner);