Browse Source

Video 11: writing and using plugins.

Frederic G. MARAND 4 years ago
parent
commit
8e1f6ecf63
2 changed files with 15 additions and 4 deletions
  1. 5 1
      ExamplePlugin.js
  2. 10 3
      webpack.config.js

+ 5 - 1
ExamplePlugin.js

@@ -1,7 +1,11 @@
 class ExamplePlugin {
+  constructor(props) {
+    this.props = props;
+  }
+
   apply(compiler) {
     compiler.plugin("run", (compiler, callback) => {
-      console.log("Webpack is running our plugin");
+      console.log("Webpack is running our plugin", this.props.msg);
       callback();
     });
   }

+ 10 - 3
webpack.config.js

@@ -1,4 +1,6 @@
 const path = require("path"); // NodeJS builtin.
+const ExamplePlugin = require("./ExamplePlugin");
+const webpack = require("webpack");
 
 module.exports = {
   entry: "./src/index.js",
@@ -31,10 +33,15 @@ module.exports = {
         use: [
           // Use object format instead of string to pass options to a loader.
           {
-            loader: "file-loader",
-          },
+            loader: "file-loader"
+          }
         ]
       }
     ]
-  }
+  },
+  plugins: [
+    new ExamplePlugin({ msg: "Kilroy was here" }),
+    new webpack.optimize.UglifyJsPlugin(),
+    new webpack.ContextReplacementPlugin()
+  ]
 };