-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
webpack.wuhaolin.cn |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# [在线阅读](http://webpack.wuhaolin.cn)《深入浅出 Webpack》 | ||
|
||
<p align='center'> | ||
<a href='http://webpack.wuhaolin.cn/'> | ||
<img src='http://p0.meituan.net/scarlett/df16c51ffb95186df6f75d8c0e22b965842464.png' width='306px' height='411px'/> | ||
</a> | ||
</p> | ||
|
||
## 内容简介 | ||
本书是国内第一本系统全面讲解 Webpack 的图书,涵盖了 Webpack 的入门、配置、实战、优化、原理。 | ||
|
||
- [第1章](http://webpack.wuhaolin.cn/1%E5%85%A5%E9%97%A8/)教你从0开始学会使用 Webpack; | ||
- [第2章](http://webpack.wuhaolin.cn/2%E9%85%8D%E7%BD%AE/)详细的讲解了 Webpack 提供的常用配置项; | ||
- [第3章](http://webpack.wuhaolin.cn/3%E5%AE%9E%E6%88%98/)结合实际项目中常见的场景给出最佳实践; | ||
- [第4章](http://webpack.wuhaolin.cn/4%E4%BC%98%E5%8C%96/)罗列出了各种优化 Webpack 的手段; | ||
- [第5章](http://webpack.wuhaolin.cn/5%E5%8E%9F%E7%90%86/)剖析了 Webpack 原理以及如何开发 Plugin 和 Loader。 | ||
|
||
除了深入讲解 Webpack,本书还附带介绍了 ES6、TypeScript、PostCSS、Prepack、离线缓存、单页应用、CDN 等 Web 开发相关的技能。 | ||
|
||
无论是对 Webpack 一无所知的初学者,还是经验丰富的工程师,相信都能通过本书进一步提高对 Webpack 的理解,让你在 Web 开发中更加熟练的运用 Webpack。 | ||
|
||
## 评价 | ||
> Webpack 凭借强大的功能与良好的使用体验,已经成为目前最流行,社区最活跃的打包工具,是现代 Web 开发必须掌握的技能之一。作者结合自身的实战经验,介绍了 Webpack 的使用与常见优化方法、并深入讲解了 Webpack 原理与架构,相信各阶段的 Webpack 用户都能通过本书得到启发。 | ||
> | ||
> -- [LeanCloud](https://leancloud.cn/?source=00YQRYTC) 联合创始人/CEO 江宏 | ||
|
||
> 本书的内容包含多个主题,Webpack 的用法、配置、使用场景等都有涉及,并且提供所有示例的源码,可以补充 Webpack 官方文档。 | ||
> | ||
> -- 阮一峰([著名技术博客](http://www.ruanyifeng.com/blog/),[《ES6 标准入门》](http://union-click.jd.com/jdc?d=Vaj3NC)的作者) | ||
|
||
> 我手边需要这样一本书,内容涵盖Webpack,或者说涵盖现代前端技术基础、构建与优化的方方面面。如果你已经上手 Webpack,那么本书将带领你进一步学习,真正掌握 Webpack! | ||
> | ||
> -- 陆金所前端架构师、[前端外刊评论](https://qianduan.group/)站长 寸志 | ||
## 版权许可 | ||
电子工业出版社持有本书全媒体形式的出版发行权利。 | ||
|
||
[吴浩麟](https://github.com/gwuhaolin)拥有本书的著作权。 | ||
|
||
**其它人不能将本书用于商用用途,不能转载,不能以任何形式发行,违者将追究法律责任**。 | ||
|
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* eslint-env browser */ | ||
|
||
require(['gitbook'], function (gitbook) { | ||
var adInsertPoint = '.page-inner section' | ||
, adPosition = 'bottom' | ||
, ad; | ||
|
||
gitbook.events.bind('start', function (e, cnf) { | ||
const config = cnf.adsense; | ||
|
||
// Use custom insert point if defined | ||
if (config.element) { | ||
adInsertPoint = config.element; | ||
} | ||
|
||
// Use custom position if defined | ||
if (config.position) { | ||
adPosition = config.position; | ||
} | ||
|
||
// Inject script to head. | ||
var adsByGoogleScript = document.createElement('script'); | ||
adsByGoogleScript.src = '//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js'; | ||
adsByGoogleScript.setAttribute('async', true); | ||
document.body.appendChild(adsByGoogleScript); | ||
|
||
// Generate <ins> (ad) | ||
ad = document.createElement('ins'); | ||
ad.style = 'display: block'; | ||
ad.className = 'adsbygoogle'; | ||
|
||
ad.setAttribute('data-ad-client', config.client); | ||
ad.setAttribute('data-ad-slot', config.slot); | ||
ad.setAttribute('data-ad-format', config.format); | ||
|
||
// Add the ad to the DOM | ||
var element = document.querySelector(adInsertPoint); | ||
|
||
if (adPosition === 'top') { | ||
element.insertBefore(ad, element.firstChild); | ||
} else { | ||
element.appendChild(ad); | ||
} | ||
|
||
(adsbygoogle = window.adsbygoogle || []).push({}); // eslint-disable-line | ||
}); | ||
|
||
// I insert ad again when switching pages | ||
gitbook.events.bind('page.change', function () { | ||
if (ad) { | ||
var element = document.querySelector(adInsertPoint); | ||
|
||
if (adPosition === 'top') { | ||
element.insertBefore(ad, element.firstChild); | ||
} else { | ||
element.appendChild(ad); | ||
} | ||
} | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,240 @@ | ||
require(['gitbook', 'jquery'], function(gitbook, $) { | ||
// Configuration | ||
var MAX_SIZE = 4, | ||
MIN_SIZE = 0, | ||
BUTTON_ID; | ||
|
||
// Current fontsettings state | ||
var fontState; | ||
|
||
// Default themes | ||
var THEMES = [ | ||
{ | ||
config: 'white', | ||
text: 'White', | ||
id: 0 | ||
}, | ||
{ | ||
config: 'sepia', | ||
text: 'Sepia', | ||
id: 1 | ||
}, | ||
{ | ||
config: 'night', | ||
text: 'Night', | ||
id: 2 | ||
} | ||
]; | ||
|
||
// Default font families | ||
var FAMILIES = [ | ||
{ | ||
config: 'serif', | ||
text: 'Serif', | ||
id: 0 | ||
}, | ||
{ | ||
config: 'sans', | ||
text: 'Sans', | ||
id: 1 | ||
} | ||
]; | ||
|
||
// Return configured themes | ||
function getThemes() { | ||
return THEMES; | ||
} | ||
|
||
// Modify configured themes | ||
function setThemes(themes) { | ||
THEMES = themes; | ||
updateButtons(); | ||
} | ||
|
||
// Return configured font families | ||
function getFamilies() { | ||
return FAMILIES; | ||
} | ||
|
||
// Modify configured font families | ||
function setFamilies(families) { | ||
FAMILIES = families; | ||
updateButtons(); | ||
} | ||
|
||
// Save current font settings | ||
function saveFontSettings() { | ||
gitbook.storage.set('fontState', fontState); | ||
update(); | ||
} | ||
|
||
// Increase font size | ||
function enlargeFontSize(e) { | ||
e.preventDefault(); | ||
if (fontState.size >= MAX_SIZE) return; | ||
|
||
fontState.size++; | ||
saveFontSettings(); | ||
} | ||
|
||
// Decrease font size | ||
function reduceFontSize(e) { | ||
e.preventDefault(); | ||
if (fontState.size <= MIN_SIZE) return; | ||
|
||
fontState.size--; | ||
saveFontSettings(); | ||
} | ||
|
||
// Change font family | ||
function changeFontFamily(configName, e) { | ||
if (e && e instanceof Event) { | ||
e.preventDefault(); | ||
} | ||
|
||
var familyId = getFontFamilyId(configName); | ||
fontState.family = familyId; | ||
saveFontSettings(); | ||
} | ||
|
||
// Change type of color theme | ||
function changeColorTheme(configName, e) { | ||
if (e && e instanceof Event) { | ||
e.preventDefault(); | ||
} | ||
|
||
var $book = gitbook.state.$book; | ||
|
||
// Remove currently applied color theme | ||
if (fontState.theme !== 0) | ||
$book.removeClass('color-theme-'+fontState.theme); | ||
|
||
// Set new color theme | ||
var themeId = getThemeId(configName); | ||
fontState.theme = themeId; | ||
if (fontState.theme !== 0) | ||
$book.addClass('color-theme-'+fontState.theme); | ||
|
||
saveFontSettings(); | ||
} | ||
|
||
// Return the correct id for a font-family config key | ||
// Default to first font-family | ||
function getFontFamilyId(configName) { | ||
// Search for plugin configured font family | ||
var configFamily = $.grep(FAMILIES, function(family) { | ||
return family.config == configName; | ||
})[0]; | ||
// Fallback to default font family | ||
return (!!configFamily)? configFamily.id : 0; | ||
} | ||
|
||
// Return the correct id for a theme config key | ||
// Default to first theme | ||
function getThemeId(configName) { | ||
// Search for plugin configured theme | ||
var configTheme = $.grep(THEMES, function(theme) { | ||
return theme.config == configName; | ||
})[0]; | ||
// Fallback to default theme | ||
return (!!configTheme)? configTheme.id : 0; | ||
} | ||
|
||
function update() { | ||
var $book = gitbook.state.$book; | ||
|
||
$('.font-settings .font-family-list li').removeClass('active'); | ||
$('.font-settings .font-family-list li:nth-child('+(fontState.family+1)+')').addClass('active'); | ||
|
||
$book[0].className = $book[0].className.replace(/\bfont-\S+/g, ''); | ||
$book.addClass('font-size-'+fontState.size); | ||
$book.addClass('font-family-'+fontState.family); | ||
|
||
if(fontState.theme !== 0) { | ||
$book[0].className = $book[0].className.replace(/\bcolor-theme-\S+/g, ''); | ||
$book.addClass('color-theme-'+fontState.theme); | ||
} | ||
} | ||
|
||
function init(config) { | ||
// Search for plugin configured font family | ||
var configFamily = getFontFamilyId(config.family), | ||
configTheme = getThemeId(config.theme); | ||
|
||
// Instantiate font state object | ||
fontState = gitbook.storage.get('fontState', { | ||
size: config.size || 2, | ||
family: configFamily, | ||
theme: configTheme | ||
}); | ||
|
||
update(); | ||
} | ||
|
||
function updateButtons() { | ||
// Remove existing fontsettings buttons | ||
if (!!BUTTON_ID) { | ||
gitbook.toolbar.removeButton(BUTTON_ID); | ||
} | ||
|
||
// Create buttons in toolbar | ||
BUTTON_ID = gitbook.toolbar.createButton({ | ||
icon: 'fa fa-font', | ||
label: 'Font Settings', | ||
className: 'font-settings', | ||
dropdown: [ | ||
[ | ||
{ | ||
text: 'A', | ||
className: 'font-reduce', | ||
onClick: reduceFontSize | ||
}, | ||
{ | ||
text: 'A', | ||
className: 'font-enlarge', | ||
onClick: enlargeFontSize | ||
} | ||
], | ||
$.map(FAMILIES, function(family) { | ||
family.onClick = function(e) { | ||
return changeFontFamily(family.config, e); | ||
}; | ||
|
||
return family; | ||
}), | ||
$.map(THEMES, function(theme) { | ||
theme.onClick = function(e) { | ||
return changeColorTheme(theme.config, e); | ||
}; | ||
|
||
return theme; | ||
}) | ||
] | ||
}); | ||
} | ||
|
||
// Init configuration at start | ||
gitbook.events.bind('start', function(e, config) { | ||
var opts = config.fontsettings; | ||
|
||
// Generate buttons at start | ||
updateButtons(); | ||
|
||
// Init current settings | ||
init(opts); | ||
}); | ||
|
||
// Expose API | ||
gitbook.fontsettings = { | ||
enlargeFontSize: enlargeFontSize, | ||
reduceFontSize: reduceFontSize, | ||
setTheme: changeColorTheme, | ||
setFamily: changeFontFamily, | ||
getThemes: getThemes, | ||
setThemes: setThemes, | ||
getFamilies: getFamilies, | ||
setFamilies: setFamilies | ||
}; | ||
}); | ||
|
||
|