Skip to content
Permalink
Browse files
feat(js): combine and minify all JS files into one to improve load speed
  • Loading branch information
talha131 committed Feb 2, 2020
1 parent 2d597ab commit f5047d4cbce02a187f1b04f11f026817ed1757d9
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 16 deletions.
@@ -10,6 +10,7 @@ import cssnano from "cssnano";
import postcssPresetEnv from "postcss-preset-env";
import rfs from "rfs";
import concat from "gulp-concat";
import terser from "gulp-terser";

const browserSync = browserSyncCreate();

@@ -65,9 +66,10 @@ const watchFiles = () => {
"static/**/*.css",
"static/**/*.less",
"!static/**/elegant.prod.css",
"static/**/*.js",
"!static/js/elegant.prod.js",
"!static/**/bootstrap.css",
"!static/**/bootstrap_responsive.css",
"static/**/*.js"
"!static/**/bootstrap_responsive.css"
],
{ ignoreInitial: false },
buildAll
@@ -81,6 +83,17 @@ const rmProdCSS = cb => {
}
cb();
};
const minifyJS = () => {
return src([
"static/tipuesearch/tipuesearch_set.js",
"static/tipuesearch/tipuesearch.min.js",
"static/applause-button/applause-button.js",
"!static/js/elegant.prod.js"
])
.pipe(concat("elegant.prod.js"))
.pipe(terser())
.pipe(dest("static/js/"));
};

const compileCSS = () => {
const plugins = [
@@ -106,12 +119,14 @@ const buildAll = series(
compileBootstrapLess,
compileResponsiveLess,
compileCSS,
minifyJS,
buildContent
);
const elegant = series(
compileBootstrapLess,
compileResponsiveLess,
compileCSS,
minifyJS,
cleanOutput,
buildContent,
parallel(watchFiles, reload)
@@ -13,6 +13,7 @@
"gulp-concat": "^2.6.1",
"gulp-postcss": "^8.0.0",
"gulp-run-command": "^0.0.10",
"gulp-terser": "^1.2.0",
"postcss-font-magician": "^2.3.1",
"postcss-preset-env": "^6.7.0",
"recess": "^1.1.9",

Large diffs are not rendered by default.

@@ -9,7 +9,6 @@
{% set identifier = article.applause_button_id %}
{% endif %}

<script src="{{ SITEURL }}/theme/applause-button/applause-button.js"></script>
<div class="applause_button">
<applause-button url={{ identifier }}> </applause-button>
</div>

This file was deleted.

@@ -103,6 +103,7 @@
{% endif %}
<script src="//code.jquery.com/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
<script src="{{ SITEURL }}/theme/js/elegant.prod.js"></script>
<script>
function validateForm(query)
{
@@ -32,13 +32,6 @@

{% block script %}
{{ super() }}
{% if 'assets' in PLUGINS %}
{% include '_includes/minify_tipuesearch.html' with context %}
{% else %}
<script src="{{ SITEURL }}/theme/tipuesearch/tipuesearch_set.js"></script>
<script src="{{ SITEURL }}/theme/tipuesearch/tipuesearch.min.js"></script>
{% endif %}

{% if 'tipue_search' in PLUGINS %}
<script src="{{ SITEURL }}/tipuesearch_content.js"></script>
{% endif %}
@@ -1860,7 +1860,7 @@ combined-stream@^1.0.6, combined-stream@~1.0.6:
dependencies:
delayed-stream "~1.0.0"

commander@^2.2.0, commander@~2.20.3:
commander@^2.2.0, commander@^2.20.0, commander@~2.20.3:
version "2.20.3"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==
@@ -3664,6 +3664,16 @@ gulp-run-command@^0.0.10:
spawn-args "0.2.0"
timeout-as-promise "^1.0.0"

gulp-terser@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/gulp-terser/-/gulp-terser-1.2.0.tgz#41df2a1d0257d011ba8b05efb2568432ecd0495b"
integrity sha512-lf+jE2DALg2w32p0HRiYMlFYRYelKZPNunHp2pZccCYrrdCLOs0ItbZcN63yr2pbz116IyhUG9mD/QbtRO1FKA==
dependencies:
plugin-error "^1.0.1"
terser "^4.0.0"
through2 "^3.0.1"
vinyl-sourcemaps-apply "^0.2.1"

gulp@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/gulp/-/gulp-4.0.2.tgz#543651070fd0f6ab0a0650c6a3e6ff5a7cb09caa"
@@ -8152,6 +8162,14 @@ source-map-support@^0.4.15:
dependencies:
source-map "^0.5.6"

source-map-support@~0.5.12:
version "0.5.16"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.16.tgz#0ae069e7fe3ba7538c64c98515e35339eac5a042"
integrity sha512-efyLRJDr68D9hBBNIPWFjhpFzURh+KJykQwvMyW5UiZzYwoF6l4YMMDIJJEyFWxWCqfyxLzz6tSfUFR+kXXsVQ==
dependencies:
buffer-from "^1.0.0"
source-map "^0.6.0"

source-map-url@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.4.0.tgz#3e935d7ddd73631b97659956d55128e87b5084a3"
@@ -8162,7 +8180,7 @@ source-map@^0.5.1, source-map@^0.5.6, source-map@^0.5.7:
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"
integrity sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=

source-map@^0.6.1, source-map@~0.6.1:
source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
@@ -8593,6 +8611,15 @@ term-size@^1.2.0:
dependencies:
execa "^0.7.0"

terser@^4.0.0:
version "4.6.3"
resolved "https://registry.yarnpkg.com/terser/-/terser-4.6.3.tgz#e33aa42461ced5238d352d2df2a67f21921f8d87"
integrity sha512-Lw+ieAXmY69d09IIc/yqeBqXpEQIpDGZqT34ui1QWXIUpR2RjbqEkT8X7Lgex19hslSqcWM5iMN2kM11eMsESQ==
dependencies:
commander "^2.20.0"
source-map "~0.6.1"
source-map-support "~0.5.12"

text-extensions@^1.0.0:
version "1.9.0"
resolved "https://registry.yarnpkg.com/text-extensions/-/text-extensions-1.9.0.tgz#1853e45fee39c945ce6f6c36b2d659b5aabc2a26"
@@ -8627,7 +8654,7 @@ through2@^2.0.0, through2@^2.0.2, through2@^2.0.3, through2@~2.0.0:
readable-stream "~2.3.6"
xtend "~4.0.1"

through2@^3.0.0:
through2@^3.0.0, through2@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/through2/-/through2-3.0.1.tgz#39276e713c3302edf9e388dd9c812dd3b825bd5a"
integrity sha512-M96dvTalPT3YbYLaKaCuwu+j06D/8Jfib0o/PxbVt6Amhv3dUAtW6rTV1jPgJSBG83I/e04Y6xkVdVhSRhi0ww==

0 comments on commit f5047d4

Please sign in to comment.