eleventy webpack
1.0.0
準系統十一和 webpack 模板。叉子然後走。
.js
(ES6、Babel、Polyfill).css
(Sass、PostCSS、自動前綴器)noopener
和noreferrer
)現場示範 https://eleventy-webpack.netlify.app
首先安裝相依性:
npm install
然後你可以:
命令 | 描述 |
---|---|
npm run start | 在 http://localhost:8080 上經營您的網站 |
npm run build | 在/_site 內建立您的生產網站 |
npm run format | 在除/_site 之外的所有填充上運行 prettier |
npm run analyze | 輸出有關捆綁包大小的信息 |
確保使用正確的 node.js 版本:
# with bash nvm
nvm use ` cat .nvmrc `
# with windows nvm
nvm use $( cat .nvmrc )
# or just install the version specified inside `.nvmrc`
包含一個非常簡單的webpack.config.js
。請隨意更改它。
所有短代碼都可以在.md
或.njk
檔案內使用。
icon
新增至src/assets/icons
的任何 SVG 都會捆綁到符號精靈檔案中,並透過此短代碼提供。
<!-- Assuming `src/assets/icons/github.svg` exist -->
{% icon "github" %} Github icon
<!-- Will be rendered as -->
< svg class =" icon icon--github " role =" img " aria-hidden =" true " >
< use xlink:href =" /assets/images/sprite.svg#github " > </ use >
</ svg >
image
建立影像的 WebP 版本和對應的最佳化 JPEG / PNG。圖像將以多種尺寸建立。有關預設值,請參閱utils/shortcodes.js
。
<!-- Assuming `src/assets/images/image.jpeg` of width 330px exist -->
{% image "image.jpeg", "Image alt" %}
<!-- Will be rendered as -->
< picture >
< source type =" image/webp " srcset =" /assets/images/678868de-320.webp 320w, /assets/images/678868de.webp 330w " sizes =" 90vw " >
< source type =" image/png " srcset =" /assets/images/678868de-320.png 320w, /assets/images/678868de.png 330w " sizes =" 90vw " >
< img loading =" lazy " src =" /assets/images/678868de.png " alt =" Image alt " width =" 330 " height =" 580 " >
</ picture >
<!-- If a title is passed the shortcode will output a <figure> with <figcaption> -->
{% image "image.jpeg", "Image alt", "Image title" %}
<!-- Will be rendered as -->
< figure >
< picture >
< source type =" image/webp " srcset =" /assets/images/678868de-320.webp 320w, /assets/images/678868de.webp 330w " sizes =" 90vw " >
< source type =" image/png " srcset =" /assets/images/678868de-320.png 320w, /assets/images/678868de.png 330w " sizes =" 90vw " >
< img loading =" lazy " src =" /assets/images/678868de.png " alt =" Image alt " width =" 330 " height =" 580 " >
</ picture >
< figcaption > Image title </ figcaption >
</ figure >
<!-- Additional options -->
{% image [100,100], "image.jpeg", "Image alt", "Image title", "my-class", false, "90vw" %}
<!-- Will be rendered as -->
< figure class =" fig-my-class " >
< picture >
< source type =" image/webp " srcset =" ... " sizes =" 90vw " >
< source type =" image/png " srcset =" ... " sizes =" 90vw " >
< img class =" img-my-class " loading =" eager " src =" ... " alt =" Image alt " width =" 100 " height =" 100 " >
</ picture >
< figcaption > Image title </ figcaption >
</ figure >
markdown
輕鬆嵌入 Markdown。
{% markdown %}
Let's you use **Markdown** like _this_.
Or with includes {%- include 'content.md' -%}.
{% endmarkdown %}
所有過濾器都可以在.md
或.njk
檔案內使用。
format
使用 date-fns 格式化傳遞的日期:
<!-- Assuming page.date is a javascript date -->
{{ page.date | format("yyyy") }}
<!-- Will be rendered as -->
2020
formatISO
根據 ISO 格式格式化傳遞的日期:
<!-- Assuming page.date is a javascript date -->
{{ page.date | formatISO }}
<!-- Will be rendered as -->
2020-09-18T19:00:52Z
markdown
用 markdown 解析傳遞的字串:
<!-- Assuming page.title is `# My header` -->
{{ page.title | markdown }}
<!-- Will be rendered as -->
< h1 > My header </ h1 >