From f9f3f3fa63610aa5a89825091ee57aa6e66a7dfd Mon Sep 17 00:00:00 2001 From: Ashley Hill Date: Thu, 7 Feb 2019 18:24:37 -0500 Subject: [PATCH] Update manifest with compilation hash in dev mode --- src/config/webpack.common.js | 4 +--- src/config/webpack.dev.js | 8 ++++++++ src/config/webpack.prod.js | 17 ++++++++++++++--- src/utils/webpack/manifest-builder.js | 11 +++++++++-- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/config/webpack.common.js b/src/config/webpack.common.js index afd51fd..4facf6c 100644 --- a/src/config/webpack.common.js +++ b/src/config/webpack.common.js @@ -1,5 +1,4 @@ const fs = require("fs"); -const ManifestBuilder = require("../utils/webpack/manifest-builder"); const SimpleCopyPlugin = require("../utils/webpack/simple-copy-plugin"); const WatchExtraFilesPlugin = require("../utils/webpack/watch-extra-files"); const { resolveBuildPath, resolveExtensionPath } = require("../utils/paths"); @@ -52,7 +51,6 @@ module.exports = { new SimpleCopyPlugin(copies), new WatchExtraFilesPlugin({ files: [resolveExtensionPath("package.json"), readmePath] - }), - new ManifestBuilder(extensionPath, bundleName) + }) ] }; \ No newline at end of file diff --git a/src/config/webpack.dev.js b/src/config/webpack.dev.js index 9a58686..c3fe3ce 100644 --- a/src/config/webpack.dev.js +++ b/src/config/webpack.dev.js @@ -1,5 +1,13 @@ const merge = require("webpack-merge"); const common = require("./webpack.common"); +const ManifestBuilder = require("../utils/webpack/manifest-builder"); +const { resolveExtensionPath } = require("../utils/paths"); +const { bundleName } = require("./constants"); + +const extensionPath = resolveExtensionPath(); + +// Build dev manifest +common.plugins.push(new ManifestBuilder(extensionPath, bundleName, true)); module.exports = merge(common, { output: { diff --git a/src/config/webpack.prod.js b/src/config/webpack.prod.js index 89dd8a2..080e448 100644 --- a/src/config/webpack.prod.js +++ b/src/config/webpack.prod.js @@ -1,10 +1,21 @@ const merge = require("webpack-merge"); const UglifyJSPlugin = require("uglifyjs-webpack-plugin"); +const ManifestBuilder = require("../utils/webpack/manifest-builder"); const common = require("./webpack.common"); +const { resolveExtensionPath } = require("../utils/paths"); +const { bundleName } = require("./constants"); -common.plugins.push(new UglifyJSPlugin({ - sourceMap: true -})); +const extensionPath = resolveExtensionPath(); + +common.plugins.push( + // Build prod manifest + new ManifestBuilder(extensionPath, bundleName), + + // Minify + new UglifyJSPlugin({ + sourceMap: true + }) +); module.exports = merge(common, { output: { diff --git a/src/utils/webpack/manifest-builder.js b/src/utils/webpack/manifest-builder.js index c06972a..2d01761 100644 --- a/src/utils/webpack/manifest-builder.js +++ b/src/utils/webpack/manifest-builder.js @@ -39,9 +39,10 @@ function parseRepository(repoInfo) { } class ManifestBuilder { - constructor(extensionPath, bundleName) { + constructor(extensionPath, bundleName, developmentMode = false) { this.extensionPath = extensionPath; this.bundleName = bundleName; + this.developmentMode = developmentMode; } apply(compiler) { @@ -62,12 +63,18 @@ class ManifestBuilder { manifest.packageName = pkgInfo.name; manifest.name = pkgInfo.zeplin.displayName || pkgInfo.name; manifest.description = pkgInfo.description; - manifest.version = pkgInfo.version; manifest.author = pkgInfo.author; manifest.options = pkgInfo.zeplin.options; manifest.projectTypes = pkgInfo.zeplin.projectTypes; manifest.moduleURL = `./${chunk.files[0]}`; + if (this.developmentMode) { + // Add hash because you're in the middle of dev and you want the "Reload Local Plugins" to detect a change + manifest.version = `${pkgInfo.version}-pre.${compilation.hash}`; + } else { + manifest.version = pkgInfo.version; + } + if (pkgInfo.repository) { manifest.repository = parseRepository(pkgInfo.repository); }