Exclude JS source code from the output

This commit is contained in:
Cotes Chung 2021-04-19 14:51:45 +08:00
parent 52f4012463
commit 72e8ffafa6
17 changed files with 24 additions and 23 deletions

View file

@ -40,7 +40,8 @@ const PvOpts = (function () {
hasLocalMeta() { hasLocalMeta() {
return hasContent("meta[name=pv-cache-path]"); return hasContent("meta[name=pv-cache-path]");
} }
} };
}()); }());
const PvStorage = (function () { const PvStorage = (function () {

View file

@ -10,27 +10,27 @@ const uglify = require('gulp-uglify');
const insert = require('gulp-insert'); const insert = require('gulp-insert');
const fs = require('fs'); const fs = require('fs');
const JS_ROOT = 'assets/js'; const JS_SRC = '_javascript';
const jsDest = `${ JS_ROOT }/dist/`; const JS_DEST = `assets/js/dist/`;
function concatJs(files, output) { function concatJs(files, output) {
return src(files) return src(files)
.pipe(concat(output)) .pipe(concat(output))
.pipe(rename({ extname: '.min.js' })) .pipe(rename({ extname: '.min.js' }))
.pipe(dest(jsDest)); .pipe(dest(JS_DEST));
} }
function minifyJs() { function minifyJs() {
return src(`${ jsDest }/*.js`) return src(`${ JS_DEST }/*.js`)
.pipe(insert.prepend(fs.readFileSync(`${ JS_ROOT }/_copyright`, 'utf8'))) .pipe(insert.prepend(fs.readFileSync(`${ JS_SRC }/copyright`, 'utf8')))
.pipe(uglify({output: {comments: /^!|@preserve|@license|@cc_on/i}})) .pipe(uglify({output: {comments: /^!|@preserve|@license|@cc_on/i}}))
.pipe(dest(jsDest)); .pipe(dest(JS_DEST));
} }
const homeJs = () => { const homeJs = () => {
return concatJs([ return concatJs([
`${JS_ROOT}/_commons/*.js`, `${JS_SRC}/commons/*.js`,
`${JS_ROOT}/_utils/timeago.js` `${JS_SRC}/utils/timeago.js`
], ],
'home' 'home'
); );
@ -38,34 +38,34 @@ const homeJs = () => {
const postJs = () => { const postJs = () => {
return concatJs([ return concatJs([
`${JS_ROOT}/_commons/*.js`, `${JS_SRC}/commons/*.js`,
`${JS_ROOT}/_utils/timeago.js`, `${JS_SRC}/utils/timeago.js`,
`${JS_ROOT}/_utils/lang-badge.js`, `${JS_SRC}/utils/lang-badge.js`,
// 'smooth-scroll.js' must be called after ToC is ready // 'smooth-scroll.js' must be called after ToC is ready
`${JS_ROOT}/_utils/smooth-scroll.js` `${JS_SRC}/utils/smooth-scroll.js`
], 'post' ], 'post'
); );
}; };
const categoriesJs = () => { const categoriesJs = () => {
return concatJs([ return concatJs([
`${JS_ROOT}/_commons/*.js`, `${JS_SRC}/commons/*.js`,
`${JS_ROOT}/_utils/category-collapse.js` `${JS_SRC}/utils/category-collapse.js`
], 'categories' ], 'categories'
); );
}; };
const pageJs = () => { const pageJs = () => {
return concatJs([ return concatJs([
`${JS_ROOT}/_commons/*.js`, `${JS_SRC}/commons/*.js`,
`${JS_ROOT}/_utils/smooth-scroll.js` `${JS_SRC}/utils/smooth-scroll.js`
], 'page' ], 'page'
); );
}; };
// GA pageviews report // GA pageviews report
const pvreportJs = () => { const pvreportJs = () => {
return concatJs(`${JS_ROOT}/_utils/pageviews.js`, 'pvreport'); return concatJs(`${JS_SRC}/utils/pageviews.js`, 'pvreport');
}; };
const buildJs = parallel(homeJs, postJs, categoriesJs, pageJs, pvreportJs); const buildJs = parallel(homeJs, postJs, categoriesJs, pageJs, pvreportJs);
@ -76,9 +76,9 @@ exports.liveRebuild = () => {
buildJs(); buildJs();
watch([ watch([
`${ JS_ROOT }/_commons/*.js`, `${ JS_SRC }/commons/*.js`,
`${ JS_ROOT }/_utils/*.js`, `${ JS_SRC }/utils/*.js`,
`${ JS_ROOT }/lib/*.js` `${ JS_SRC }/lib/*.js`
], ],
buildJs buildJs
) )

View file

@ -4,7 +4,7 @@
# #
# 1. Bump latest version number to files: # 1. Bump latest version number to files:
# - _sass/jekyll-theme-chirpy.scss # - _sass/jekyll-theme-chirpy.scss
# - assets/js/_copyright.js # - _javascript/copyright
# - assets/js/dist/*.js (will be built by gulp later) # - assets/js/dist/*.js (will be built by gulp later)
# - jekyll-theme-chirpy.gemspec # - jekyll-theme-chirpy.gemspec
# - package.json # - package.json
@ -28,7 +28,7 @@ manual_release=false
ASSETS=( ASSETS=(
"_sass/jekyll-theme-chirpy.scss" "_sass/jekyll-theme-chirpy.scss"
"assets/js/_copyright" "_javascript/copyright"
) )
GEM_SPEC="jekyll-theme-chirpy.gemspec" GEM_SPEC="jekyll-theme-chirpy.gemspec"