Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update manifest with compilation hash in dev mode #15

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/config/webpack.common.js
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -52,7 +51,6 @@ module.exports = {
new SimpleCopyPlugin(copies),
new WatchExtraFilesPlugin({
files: [resolveExtensionPath("package.json"), readmePath]
}),
new ManifestBuilder(extensionPath, bundleName)
})
]
};
8 changes: 8 additions & 0 deletions src/config/webpack.dev.js
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down
17 changes: 14 additions & 3 deletions src/config/webpack.prod.js
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down
11 changes: 9 additions & 2 deletions src/utils/webpack/manifest-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down