// for creation of HTMLconstHtmlWebpackPlugin=require('html-webpack-plugin');.../**
* loop multiple files
*/letentryHtmlPlugins=Object.keys(getEntryList('pug')).map(function(entryName){letv=getEntryList('pug')[entryName];// get full pathletfilenamePath=v.split(/src\/([^.]*)/)[1]+'.html';lettemplatePath=v.split(/(src\/.*)/)[1];// filter chunks configletchunkList=[];switch(entryName){case'default':chunkList.push('commons','index');}returnnewHtmlWebpackPlugin({filename:filenamePath,chunks:chunkList,template:templatePath})});....../********* pug to js */{test:/\.pug$/,exclude:['/node_modules/','src/layouts/post.pug'],loader:'pug-html-loader',query:{pretty:true// must be pretty html for jekyll}},......plugins:[...].concat(entryHtmlPlugins)...
webpack for stylus
install stylus-loader and extract-text-webpack-plugin
1
npm i stylus-loader extract-text-webpack-plugin -S
// for extract cssconstExtractTextPlugin=require('extract-text-webpack-plugin');...// pathconstpath=require('path');constPATHS={app:path.join(__dirname,'src'),bin:path.join(__dirname,'')};......// for get multiple entry listfunctiongetEntryList(type){letglob=require('glob');letfileList=[];letentryList=glob.sync(PATHS.app+'/**/*.'+type).reduce(function(o,v,i){letregex=/([^\/]+)(?=\.\w+$)/;letindex=v.match(regex)[0];o[index]=v;returno;},{});returnentryList;}......module.exports={entry:getEntryList('ts'),output:{path:PATHS.bin,publicPath:debug?'./':'/',filename:debug?'js/[name].js':'js/[name]-[hash:8].js'},...plugins:[.../** extract css */newExtractTextPlugin('css/[name].css'),...]
webpack for font-awesome
install url-loader file-loader
1
npmifont-awesomeurl-loaderfile-loader-S
config woff, woff2, ttf, eot, svg for font-awesome
constwebpackConfig=require('./webpack.config.js');constchild=require('child_process');constjekyllCommand=process.platform==='win32'?'jekyll.bat':'jekyll';varmessages={jekyllBuild:'<span style="color: grey">Running:</span> $ jekyll build'};/**
* start jekyll with watch
*/gulp.task('jekyll',()=>{constjekyll=child.spawn('jekyll',['build','--watch','--incremental','--drafts']);constjekyllLogger=(buffer)=>{buffer.toString().split(/\n/).forEach((message)=>gutil.log('Jekyll: '+message));};jekyll.stdout.on('data',jekyllLogger);jekyll.stderr.on('data',jekyllLogger);});/*************** webpack ************************/gulp.task('webpack',function(){returnwebpack(webpackConfig,function(err,stats){if(err)thrownewgutil.PluginError('webpack',err);gutil.log('webpack',stats.toString({colors:true}));});});/**
* default task that first webpack then jekyll
*/gulp.task('default',['webpack','jekyll']);
bug
for now, there is a bug with using pug to html, and not be fixed. pug issue
I use pug to write jekyll make github page, so when I used yml front matter in pug, it always compiled a blank line at first line, so code like
1
2
3
4
5
|---|layout:default|title:ShangWenLong's blog
|---
.hello index contents
be compiled to
1
2
3
4
5
6
/******** Here is a blank line **********/---layout:defaulttitle:ShangWenLong's blog
---
<div class="hello">index contents</div>
Through my test, in pretty mode because jekyll needs yml front matter format, there is blank line at first line without doctype, but with doctype everything is OK