Skip to content
This repository has been archived by the owner on Apr 5, 2021. It is now read-only.

v3.4.0

Compare
Choose a tag to compare
@mmiller42 mmiller42 released this 16 Sep 01:40
· 39 commits to master since this release

What's New in v3.4.0

This is a summary of the differences between v3.4.0 and v3.3.5.

Commits

Show commits
SHA Author Message
1f68e25 mmiller42 space indent
42ff13e mmiller42 Run prettier when anything changes; remove build before packing since it's already done on CI
5562075 greenkeeper[bot] docs(readme): add Greenkeeper badge
cdb8ec6 mmiller42 Merge pull request #15 from mmiller42/greenkeeper/initial
Add Greenkeeper badge 🌴
e5abaae mmiller42 Update README.md
b21a14a mmiller42 Add lockfile updating via Greenkeeper
eecf37b mmiller42 Merge remote-tracking branch 'origin/master'
066724a mmiller42 sudoit
dbcb974 mmiller42 Retriggering CircleCI
fa54398 mmiller42 Anal-retentive syntax fix
62ad9c6 mmiller42 Add an enabled option
231ca52 mmiller42 3.4.0

Changed files

.circleci/config.yml

Show changes
@@ -16,11 +16,17 @@ jobs:
             npm install npm@latest --no-save &&
             sudo rm -rf /usr/local/lib/node_modules/npm &&
             sudo mv node_modules/npm /usr/local/lib/node_modules/npm
+      - run:
+          name: Install greenkeeper-lockfile
+          command: sudo npm install -g greenkeeper-lockfile@1
       - restore_cache:
           key: dependency-cache-{{ checksum "package.json" }}
       - run:
           name: Install dependencies
           command: npm install
+      - run:
+          name: Update lockfile
+          command: greenkeeper-lockfile-update
       - save_cache:
           key: dependency-cache-{{ checksum "package.json" }}
           paths:
@@ -31,6 +37,9 @@ jobs:
       - run:
           name: Test
           command: npm test
+      - run:
+          name: Upload lockfile
+          command: greenkeeper-lockfile-upload
       - deploy:
           name: Publish
           command: |

README.md

Show changes
@@ -1,4 +1,4 @@
-# html-webpack-externals-plugin [![CircleCI](https://circleci.com/gh/mmiller42/html-webpack-externals-plugin.svg?style=svg)](https://circleci.com/gh/mmiller42/html-webpack-externals-plugin)
+# html-webpack-externals-plugin [![CircleCI](https://circleci.com/gh/mmiller42/html-webpack-externals-plugin.svg?style=svg)](https://circleci.com/gh/mmiller42/html-webpack-externals-plugin) [![Greenkeeper badge](https://badges.greenkeeper.io/mmiller42/html-webpack-externals-plugin.svg)](https://greenkeeper.io/)
 
 Webpack plugin that works alongside [\`html-webpack-plugin\`](https://github.com/jantimon/html-webpack-plugin) to use pre-packaged vendor bundles.
 
@@ -31,7 +31,7 @@ plugins: [
   new HtmlWebpackPlugin(),
   new HtmlWebpackExternalsPlugin(
     // See API section
-  )
+  ),
 ]
 \`\`\`
 
@@ -51,6 +51,7 @@ The constructor takes a configuration object with the following properties.
 | \`outputPath\` | string | The path (relative to your Webpack \`outputPath\`) to store externals copied over by this plugin. | \`vendor\` |
 | \`publicPath\` | string \| null | Override Webpack config's \`publicPath\` for the externals files, or \`null\` to use the default \`output.publicPath\` value. | \`null\` |
 | \`files\` | string \| array<string> \| null | If you have multiple instances of HtmlWebpackPlugin, use this to specify globs of which files you want to inject assets into. Will add assets to all files by default. | \`null\` |
+| \`enabled\` | boolean | Set to \`false\` to disable the plugin (useful for disabling in development mode). | \`true\` |
 
 ## Examples
 
@@ -285,3 +286,20 @@ new HtmlWebpackExternalsPlugin({
   files: ['about.html'],
 })
 \`\`\`
+
+### Disabling the plugin
+
+Sometimes you only want the plugin to be activated in certain environments. Rather than create separate Webpack configs or mess with splicing the plugins array, simply set the \`enabled\` option to \`false\` to disable the externals plugin entirely.
+
+\`\`\`js
+new HtmlWebpackExternalsPlugin({
+  externals: [
+    {
+      module: 'jquery',
+      entry: 'dist/jquery.min.js',
+      global: 'jQuery',
+    },
+  ],
+  enabled: process.env.NODE_ENV === 'production',
+})
+\`\`\`

package-lock.json

Inline diff not displayed. View the whole file

package.json

Show changes
@@ -1,23 +1,17 @@
 {
   "name": "html-webpack-externals-plugin",
-  "version": "3.3.5",
+  "version": "3.4.0",
   "description": "Webpack plugin that works alongside html-webpack-plugin to use pre-packaged vendor bundles.",
-  "keywords": [
-    "htmlwebpackplugin",
-    "webpack",
-    "html",
-    "externals"
-  ],
+  "keywords": ["htmlwebpackplugin", "webpack", "html", "externals"],
   "main": "lib/index.js",
   "scripts": {
-    "prepack": "npm run build",
     "precommit": "lint-staged",
     "test": "mocha --require babel-register",
     "build": "rm -rf lib && babel src --out-dir lib --source-maps --copy-files",
     "watch": "npm run build -- --watch"
   },
   "lint-staged": {
-    "*.js": [
+    "*.{js,json}": [
       "prettier --write --no-semi --single-quote --trailing-comma es5 '{src/**/*.{js,json},test/**/*.js,*.json}'",
       "git add"
     ]
@@ -36,6 +30,7 @@
   },
   "homepage": "https://github.com/mmiller42/html-webpack-externals-plugin#readme",
   "devDependencies": {
+    "assertion-error": "^1.0.2",
     "babel-cli": "^6.24.1",
     "babel-core": "^6.25.0",
     "babel-plugin-add-module-exports": "^0.2.1",

src/HtmlWebpackExternalsPlugin.js

Show changes
@@ -25,11 +25,12 @@ export default class HtmlWebpackExternalsPlugin {
     this.assetsToCopy = []
     this.externals = {}
 
-    const { externals, hash, outputPath, publicPath, files } = config
+    const { externals, hash, outputPath, publicPath, files, enabled } = config
     this.hash = hash
     this.outputPath = outputPath
     this.publicPath = publicPath
     this.files = files
+    this.enabled = enabled
 
     externals.forEach(({ module, entry, global, supplements, append }) => {
       this.externals[module] = global
@@ -63,6 +64,10 @@ export default class HtmlWebpackExternalsPlugin {
   }
 
   apply(compiler) {
+    if (!this.enabled) {
+      return
+    }
+
     if (!compiler.options.externals) {
       compiler.options.externals = this.externals
     } else if (Array.isArray(compiler.options.externals)) {

src/configSchema.json

Show changes
@@ -75,6 +75,10 @@
       },
       "minItems": 1,
       "default": null
+    },
+    "enabled": {
+      "type": "boolean",
+      "default": true
     }
   },
   "required": ["externals"]

test/HtmlWebpackExternalsPlugin.spec.js

Show changes
@@ -1,4 +1,5 @@
 import assert from 'assert'
+import AssertionError from 'assertion-error'
 import HtmlWebpackPlugin from 'html-webpack-plugin'
 import HtmlWebpackExternalsPlugin from '../lib/'
 import {
@@ -288,11 +289,58 @@ describe('HtmlWebpackExternalsPlugin', function() {
           )
             .then(() =>
               reject(
-                'index.html should not have had the assets inserted into the HTML'
+                new AssertionError(
+                  'index.html should not have had the assets inserted into the HTML'
+                )
               )
             )
-            .catch(() => resolve())
+            .catch(resolve)
         })
       })
   })
+
+  it('does not run when enabled is false', function() {
+    const wp = runWebpack(
+      new HtmlWebpackPlugin(),
+      new HtmlWebpackExternalsPlugin({
+        externals: [
+          {
+            module: 'jquery',
+            entry: 'dist/jquery.min.js',
+            global: 'jQuery',
+          },
+        ],
+        enabled: false,
+      })
+    )
+
+    return Promise.all([
+      new Promise((resolve, reject) => {
+        wp
+          .then(() => checkBundleExcludes('jQuery'))
+          .then(() =>
+            reject(new AssertionError('Plugin should not have excluded jQuery'))
+          )
+          .catch(resolve)
+      }),
+      new Promise((resolve, reject) => {
+        wp
+          .then(() => checkCopied('vendor/jquery/dist/jquery.min.js'))
+          .then(() =>
+            reject(new AssertionError('Plugin should not have copied jQuery'))
+          )
+          .catch(resolve)
+      }),
+      new Promise((resolve, reject) => {
+        wp
+          .then(() =>
+            checkHtmlIncludes('vendor/jquery/dist/jquery.min.js', 'js')
+          )
+          .then(() =>
+            reject(new AssertionError('Plugin should not have injected jQuery'))
+          )
+          .catch(resolve)
+      }),
+    ])
+  })
 })

test/fixtures/style.css

Show changes
@@ -1,3 +1,3 @@
 body {
-	color: blue;
+  color: blue;
 }