From ab3803fe5904ad17898198ea1b81b4f858d98b97 Mon Sep 17 00:00:00 2001 From: Kevin MacMartin Date: Sat, 28 Sep 2019 01:50:06 -0400 Subject: [PATCH] Don't include both the production and dev versions of vue when targeting one or the other --- gulpfile.js | 50 +++++++++++++++++++++--------- package-lock.json | 63 ++++++++++++++++++++++++++++++++++++++ package.json | 1 + resources/assets/js/app.js | 4 +-- 4 files changed, 102 insertions(+), 16 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index c1d2842..08cb255 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -2,6 +2,7 @@ const gulp = require("gulp"), minimist = require("minimist"), log = require("fancy-log"), + insert = require("gulp-insert"), plumber = require("gulp-plumber"), concat = require("gulp-concat"); @@ -40,7 +41,7 @@ const sassOutputStyle = isProduction ? "compressed" : "expanded", vuePaths = [ "./bower_components", "./node_modules", "./resources/components", "./resources/assets/js" ]; // Javascript files for the public site -const jsPublic = [ "resources/assets/js/app.js" ]; +const jsPublic = "resources/assets/js/app.js"; // Javascript libraries for the public site const jsPublicLibs = [ @@ -118,21 +119,42 @@ function processCSS(outputFilename, inputFiles) { // Process vue function processVue(outputFilename, inputFile) { - const javascript = browserify({ - entries: [ inputFile ], - paths: vuePaths - }).transform("babelify") - .transform(vueify) - .bundle() - .on("error", handleError) - .pipe(source(`${outputFilename}.js`)) - .pipe(buffer()); + const processedDir = "storage/app/", + processedFile = `__${outputFilename}.js`; - if (isProduction) { - javascript.pipe(stripDebug()).pipe(uglify().on("error", handleError)); - } + const preProcess = () => { + const javascript = gulp.src([ inputFile ]); - return javascript.pipe(gulp.dest("public/js/")); + if (isProduction) { + javascript.pipe(insert.transform(function(contents) { + return contents.replace(/vue\.js/, "vue.min.js"); + })); + } + + return javascript.pipe(concat(processedFile)) + .pipe(gulp.dest(processedDir)); + }; + + const process = () => { + const javascript = browserify({ + entries: [ processedDir + processedFile ], + paths: vuePaths + }).transform("babelify") + .transform(vueify) + .bundle() + .on("error", handleError) + .pipe(source(`${outputFilename}.js`)) + .pipe(buffer()); + + if (isProduction) { + javascript.pipe(stripDebug()).pipe(uglify().on("error", handleError)); + } + + return javascript.pipe(gulp.dest("public/js/")); + }; + + preProcess(); + return process(); } // Process javascript diff --git a/package-lock.json b/package-lock.json index f7be649..4a8c544 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4136,6 +4136,38 @@ "vinyl": "^2.0.0" } }, + "gulp-insert": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/gulp-insert/-/gulp-insert-0.5.0.tgz", + "integrity": "sha1-MjE/E+SiPPWsylzl8MCAkjx3hgI=", + "requires": { + "readable-stream": "^1.0.26-4", + "streamqueue": "0.0.6" + }, + "dependencies": { + "isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=" + }, + "readable-stream": { + "version": "1.1.14", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", + "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.1", + "isarray": "0.0.1", + "string_decoder": "~0.10.x" + } + }, + "string_decoder": { + "version": "0.10.31", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", + "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=" + } + } + }, "gulp-plumber": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/gulp-plumber/-/gulp-plumber-1.2.1.tgz", @@ -8041,6 +8073,37 @@ "limiter": "^1.0.5" } }, + "streamqueue": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/streamqueue/-/streamqueue-0.0.6.tgz", + "integrity": "sha1-ZvX17JTpuK8knkrsLdH3Qb/pTeM=", + "requires": { + "readable-stream": "^1.0.26-2" + }, + "dependencies": { + "isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=" + }, + "readable-stream": { + "version": "1.1.14", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", + "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.1", + "isarray": "0.0.1", + "string_decoder": "~0.10.x" + } + }, + "string_decoder": { + "version": "0.10.31", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", + "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=" + } + } + }, "strict-uri-encode": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz", diff --git a/package.json b/package.json index 7d136dc..99468ec 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "gulp-babel": "^8.0.0", "gulp-clean-css": "^4.2.0", "gulp-concat": "^2.6.1", + "gulp-insert": "^0.5.0", "gulp-plumber": "^1.2.1", "gulp-postcss": "^8.0.0", "gulp-sass": "^4.0.2", diff --git a/resources/assets/js/app.js b/resources/assets/js/app.js index 35c8b0e..e642820 100644 --- a/resources/assets/js/app.js +++ b/resources/assets/js/app.js @@ -1,5 +1,5 @@ -// Determine whether to use vue.js in debug or production mode -const Vue = env.debug ? require("vue/dist/vue.js") : require("vue/dist/vue.min.js"); +// Initialize Vue +const Vue = require("vue/dist/vue.js"); // Import plugins import VueRouter from "vue-router";