Updating gulpfile
This commit is contained in:
@@ -12,6 +12,7 @@ const hash = require("gulp-hash-filename");
|
|||||||
const rename = require("gulp-rename");
|
const rename = require("gulp-rename");
|
||||||
const clean = require("gulp-clean");
|
const clean = require("gulp-clean");
|
||||||
const replace = require("gulp-replace");
|
const replace = require("gulp-replace");
|
||||||
|
const merge = require("merge-stream");
|
||||||
|
|
||||||
// Directories
|
// Directories
|
||||||
const currentDir = getCurrentDir(__dirname);
|
const currentDir = getCurrentDir(__dirname);
|
||||||
@@ -58,40 +59,62 @@ async function buildTheme(cb) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clear ./static/dist
|
// Clear ./static/dist
|
||||||
function cleanJS(cb) {
|
async function cleanJS() {
|
||||||
gulp.src(`${currentDir}/static/dist/*.js`, { read: false }).pipe(clean());
|
gulp.src(`${currentDir}/static/dist/*.js`, { read: false }).pipe(clean());
|
||||||
cb();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy lunrjs into static
|
// Define js scripts outside of webpack bundle.
|
||||||
const jsFiles = {
|
// const jsFiles = {
|
||||||
lunrjs_gulp: "s",
|
// lunrjs_gulp: {
|
||||||
};
|
// node_path: "/node_modules/lunr/lunr.js",
|
||||||
|
// },
|
||||||
|
// };
|
||||||
|
|
||||||
function lunr(cb) {
|
var jsFiles = [
|
||||||
gulp
|
{
|
||||||
.src(`${currentDir}/node_modules/lunr/lunr.js`)
|
module: "lunrjs_gulp",
|
||||||
.pipe(hash({ format: "{name}.{hash}.{ext}" }))
|
nodePath: "/node_modules/lunr/lunr.js",
|
||||||
.pipe(uglify())
|
minimizedFile: "",
|
||||||
.pipe(
|
},
|
||||||
rename(function (path) {
|
];
|
||||||
file = path.basename += "min";
|
|
||||||
for (const key in jsFiles) {
|
function minifyJS() {
|
||||||
if (jsFiles.hasOwnProperty(key)) {
|
destinationPath = `${currentDir}/static/dist/`;
|
||||||
jsFiles.key = file += ".js";
|
var streams = [];
|
||||||
console.log(jsFiles.key);
|
jsFiles.forEach(function (module) {
|
||||||
}
|
var stream = gulp
|
||||||
}
|
.src(`${currentDir}/${module["nodePath"]}`)
|
||||||
})
|
.pipe(hash({ format: "{name}.{hash}.{ext}" }))
|
||||||
)
|
.pipe(uglify())
|
||||||
.pipe(gulp.dest(`${currentDir}/static/dist`));
|
.pipe(
|
||||||
cb();
|
rename(function (path) {
|
||||||
|
// append min to the filename
|
||||||
|
path.basename += "min";
|
||||||
|
// add minimizedFile to the object
|
||||||
|
module["minimizedFile"] = path.basename + path.extname;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.pipe(gulp.dest(destinationPath));
|
||||||
|
streams.push(stream);
|
||||||
|
});
|
||||||
|
return merge(streams);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert js into HTML
|
function insertLunrJS() {
|
||||||
function insertJS(cb) {
|
var streams = [];
|
||||||
|
jsFiles.forEach(function (module) {
|
||||||
cb();
|
console.log(JSON.stringify(module["minimizedFile"]));
|
||||||
|
var stream = gulp
|
||||||
|
.src([`${themeDir}/layouts/search/single.html`])
|
||||||
|
.pipe(replace(module["module"], module["minimizedFile"]))
|
||||||
|
.pipe(
|
||||||
|
gulp.dest(function (file) {
|
||||||
|
return file.base;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
streams.push(stream);
|
||||||
|
});
|
||||||
|
return merge(streams);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@@ -100,13 +123,13 @@ module.exports = {
|
|||||||
buildTheme: buildTheme,
|
buildTheme: buildTheme,
|
||||||
minifyImages: minifyImages,
|
minifyImages: minifyImages,
|
||||||
cleanJS: cleanJS,
|
cleanJS: cleanJS,
|
||||||
insertJS: insertJS,
|
minifyJS: minifyJS,
|
||||||
lunr: lunr,
|
buildLunr: gulp.series(cleanJS, minifyJS, insertLunrJS),
|
||||||
buildBlog: gulp.parallel([
|
buildBlog: gulp.parallel([
|
||||||
buildSearch,
|
buildSearch,
|
||||||
buildHugo,
|
buildHugo,
|
||||||
buildTheme,
|
buildTheme,
|
||||||
minifyImages,
|
minifyImages,
|
||||||
lunr,
|
buildLunr,
|
||||||
]),
|
]),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
"gulp-replace": "^1.0.0",
|
"gulp-replace": "^1.0.0",
|
||||||
"gulp-uglify": "^3.0.2",
|
"gulp-uglify": "^3.0.2",
|
||||||
"lunr": "^2.3.8",
|
"lunr": "^2.3.8",
|
||||||
|
"merge-stream": "^2.0.0",
|
||||||
"parser-front-matter": "^1.6.4",
|
"parser-front-matter": "^1.6.4",
|
||||||
"readdirp": "^3.4.0",
|
"readdirp": "^3.4.0",
|
||||||
"webpack": "^4.43.0"
|
"webpack": "^4.43.0"
|
||||||
@@ -17,9 +18,10 @@
|
|||||||
"buildHugo": "gulp buildHugo",
|
"buildHugo": "gulp buildHugo",
|
||||||
"buildBlog": "gulp buildBlog",
|
"buildBlog": "gulp buildBlog",
|
||||||
"buildTheme": "gulp buildTheme",
|
"buildTheme": "gulp buildTheme",
|
||||||
|
"buildLunr": "gulp buildLunr",
|
||||||
"cleanJS": "gulp cleanJS",
|
"cleanJS": "gulp cleanJS",
|
||||||
"insertJS": "gulp insertJS",
|
"insertJS": "gulp insertJS",
|
||||||
"lunr": "gulp lunr",
|
"minifyJS": "gulp minifyJS",
|
||||||
"minifyImages": "gulp minifyImages"
|
"minifyImages": "gulp minifyImages"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user