Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 49c7a80

Browse files
authored
feat(template): support pug template (#960)
1 parent 5ce45ed commit 49c7a80

File tree

8 files changed

+205
-1
lines changed

8 files changed

+205
-1
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ yarn create nuxt-app <my-project>
5050
- [Vant](https://github.com/youzan/vant)
5151
- [View UI](https://www.iviewui.com/)
5252
- [Vuetify](https://github.com/vuetifyjs/vuetify)
53+
1. Template engine
54+
- HTML
55+
- Pug
5356
1. Nuxt.js modules:
5457
- [Axios - Promise based HTTP client](https://github.com/nuxt-community/axios-module)
5558
- [Progressive Web App (PWA)](https://github.com/nuxt-community/pwa-module)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"dependencies": {
3+
"pug": "^3.0.2",
4+
"pug-plain-loader": "^1.1.0"
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<template lang="pug">
2+
tutorial
3+
</template>
4+
5+
<script>
6+
import Vue from 'vue'
7+
8+
export default Vue.extend({
9+
name: 'IndexPage'
10+
})

packages/create-nuxt-app/lib/package.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ module.exports = {
2222
},
2323
load (generator) {
2424
const nuxtPkg = this.loadPackage('nuxt', generator)
25+
const templatePkg = this.loadPackage(generator.answers.template, generator)
2526
const uiPkg = this.loadPackage(generator.answers.ui, generator)
2627
const testPkg = this.loadPackage(generator.answers.test, generator)
27-
const pkg = merge(nuxtPkg, uiPkg, testPkg)
28+
const pkg = merge(nuxtPkg, templatePkg, uiPkg, testPkg)
2829
pkg.dependencies = sortByKey(pkg.dependencies)
2930
pkg.devDependencies = sortByKey(pkg.devDependencies)
3031
return pkg

packages/create-nuxt-app/lib/prompts.js

+10
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ module.exports = [
4848
],
4949
default: 'none'
5050
},
51+
{
52+
name: 'template',
53+
message: 'Template engine:',
54+
type: 'list',
55+
choices: [
56+
{ name: 'HTML', value: 'html' },
57+
{ name: 'Pug', value: 'pug' }
58+
],
59+
default: 'html'
60+
},
5161
{
5262
name: 'features',
5363
message: 'Nuxt.js modules:',

packages/create-nuxt-app/lib/saofile.js

+8
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ module.exports = {
7474
}
7575
}]
7676

77+
if (this.answers.template !== 'html') {
78+
actions.push({
79+
type: 'add',
80+
files: '**',
81+
templateDir: join(frameworksDir, this.answers.template)
82+
})
83+
}
84+
7785
if (this.answers.ui !== 'none') {
7886
actions.push({
7987
type: 'add',

packages/create-nuxt-app/test/snapshots/index.test.js.md

+166
Original file line numberDiff line numberDiff line change
@@ -1746,6 +1746,172 @@ Generated by [AVA](https://avajs.dev).
17461746
}␊
17471747
`
17481748

1749+
## verify template: HTML
1750+
1751+
> Generated files
1752+
1753+
[
1754+
'.editorconfig',
1755+
'.gitignore',
1756+
'README.md',
1757+
'components/NuxtLogo.vue',
1758+
'components/Tutorial.vue',
1759+
'nuxt.config.js',
1760+
'package.json',
1761+
'pages/index.vue',
1762+
'static/favicon.ico',
1763+
'store/README.md',
1764+
]
1765+
1766+
> package.json
1767+
1768+
{
1769+
dependencies: {
1770+
'core-js': '^3.25.0',
1771+
nuxt: '^2.15.8',
1772+
vue: '^2.7.10',
1773+
'vue-server-renderer': '^2.7.10',
1774+
'vue-template-compiler': '^2.7.10',
1775+
},
1776+
devDependencies: {},
1777+
private: true,
1778+
scripts: {
1779+
build: 'nuxt build',
1780+
dev: 'nuxt',
1781+
generate: 'nuxt generate',
1782+
start: 'nuxt start',
1783+
},
1784+
}
1785+
1786+
> Generated nuxt.config.js
1787+
1788+
`export default {␊
1789+
// Global page headers: https://go.nuxtjs.dev/config-head␊
1790+
head: {␊
1791+
title: 'output',␊
1792+
htmlAttrs: {␊
1793+
lang: 'en'␊
1794+
},␊
1795+
meta: [␊
1796+
{ charset: 'utf-8' },␊
1797+
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },␊
1798+
{ hid: 'description', name: 'description', content: '' },␊
1799+
{ name: 'format-detection', content: 'telephone=no' }␊
1800+
],␊
1801+
link: [␊
1802+
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }␊
1803+
]␊
1804+
},␊
1805+
1806+
// Global CSS: https://go.nuxtjs.dev/config-css␊
1807+
css: [␊
1808+
],␊
1809+
1810+
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins␊
1811+
plugins: [␊
1812+
],␊
1813+
1814+
// Auto import components: https://go.nuxtjs.dev/config-components␊
1815+
components: true,␊
1816+
1817+
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules␊
1818+
buildModules: [␊
1819+
],␊
1820+
1821+
// Modules: https://go.nuxtjs.dev/config-modules␊
1822+
modules: [␊
1823+
],␊
1824+
1825+
// Build Configuration: https://go.nuxtjs.dev/config-build␊
1826+
build: {␊
1827+
}␊
1828+
}␊
1829+
`
1830+
1831+
## verify template: Pug
1832+
1833+
> Generated files
1834+
1835+
[
1836+
'.editorconfig',
1837+
'.gitignore',
1838+
'README.md',
1839+
'components/NuxtLogo.vue',
1840+
'components/Tutorial.vue',
1841+
'nuxt.config.js',
1842+
'package.json',
1843+
'pages/index.vue',
1844+
'static/favicon.ico',
1845+
'store/README.md',
1846+
]
1847+
1848+
> package.json
1849+
1850+
{
1851+
dependencies: {
1852+
'core-js': '^3.25.0',
1853+
nuxt: '^2.15.8',
1854+
pug: '^3.0.2',
1855+
'pug-plain-loader': '^1.1.0',
1856+
vue: '^2.7.10',
1857+
'vue-server-renderer': '^2.7.10',
1858+
'vue-template-compiler': '^2.7.10',
1859+
},
1860+
devDependencies: {},
1861+
private: true,
1862+
scripts: {
1863+
build: 'nuxt build',
1864+
dev: 'nuxt',
1865+
generate: 'nuxt generate',
1866+
start: 'nuxt start',
1867+
},
1868+
}
1869+
1870+
> Generated nuxt.config.js
1871+
1872+
`export default {␊
1873+
// Global page headers: https://go.nuxtjs.dev/config-head␊
1874+
head: {␊
1875+
title: 'output',␊
1876+
htmlAttrs: {␊
1877+
lang: 'en'␊
1878+
},␊
1879+
meta: [␊
1880+
{ charset: 'utf-8' },␊
1881+
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },␊
1882+
{ hid: 'description', name: 'description', content: '' },␊
1883+
{ name: 'format-detection', content: 'telephone=no' }␊
1884+
],␊
1885+
link: [␊
1886+
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }␊
1887+
]␊
1888+
},␊
1889+
1890+
// Global CSS: https://go.nuxtjs.dev/config-css␊
1891+
css: [␊
1892+
],␊
1893+
1894+
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins␊
1895+
plugins: [␊
1896+
],␊
1897+
1898+
// Auto import components: https://go.nuxtjs.dev/config-components␊
1899+
components: true,␊
1900+
1901+
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules␊
1902+
buildModules: [␊
1903+
],␊
1904+
1905+
// Modules: https://go.nuxtjs.dev/config-modules␊
1906+
modules: [␊
1907+
],␊
1908+
1909+
// Build Configuration: https://go.nuxtjs.dev/config-build␊
1910+
build: {␊
1911+
}␊
1912+
}␊
1913+
`
1914+
17491915
## verify features: Axios - Promise based HTTP client, Progressive Web App (PWA), Content - Git-based headless CMS
17501916

17511917
> Generated files
Binary file not shown.

0 commit comments

Comments
 (0)