-
Notifications
You must be signed in to change notification settings - Fork 17
/
index.js
143 lines (115 loc) · 3.95 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/* eslint-disable no-void */
/**
* Quasar App Extension index/runner script
* (runs on each dev/build)
*
* Docs: https://quasar.dev/app-extensions/development-guide/index-api
* API: https://github.com/quasarframework/quasar/blob/master/app/lib/app-extension/IndexAPI.js
*/
const { join, isAbsolute } = require('path')
const { merge } = require('webpack-merge')
const appRequire = require('./helpers/app-require')
const getUniqueArray = require('./helpers/get-unique-array')
const extendQuasarConf = function extendQuasarConf (conf, api) {
conf.ssg = merge({
concurrency: 10,
interval: 0,
fallback: '404.html',
cache: {
ignore: [],
globbyOptions: {
gitignore: true
}
},
rendererOptions: {}
}, conf.ssg ? conf.ssg : {})
// Set SSG distDir
if (!conf.build.distDir) {
conf.ssg.__distDir = join(api.appDir, 'dist', 'ssg')
}
if (!isAbsolute(conf.ssg.__distDir)) {
conf.ssg.__distDir = join(api.appDir, conf.ssg.__distDir)
}
// Set SSG buildDir
if (!conf.ssg.buildDir) {
if (conf.ssg.cache !== false) {
conf.ssg.buildDir = api.resolve.app('node_modules/.cache/quasar-app-extension-ssg')
} else {
conf.ssg.buildDir = api.resolve.app('.ssg-build')
}
}
if (!isAbsolute(conf.ssg.buildDir)) {
conf.ssg.buildDir = join(api.appDir, conf.ssg.buildDir)
}
// Overrides it to expect build output folder in SSR mode being our SSG buildDir
conf.build.distDir = conf.ssg.buildDir
if (conf.ssg.cache !== false) {
const ignore = [
join(conf.ssg.__distDir, '/**'),
join(conf.ssg.buildDir, '/**'),
'dist/**',
'public/**',
'src-ssr/**',
'src-cordova/**',
'src-electron/**',
'src-bex/**',
'node_modules/**',
'.**/*',
'.*',
'README.md'
]
if (typeof conf.ssg.cache.ignore === 'function') {
conf.ssg.cache.ignore = conf.ssg.cache.ignore(ignore)
} else if (Array.isArray(conf.ssg.cache.ignore)) {
conf.ssg.cache.ignore = getUniqueArray(conf.ssg.cache.ignore.concat(ignore))
}
}
if (conf.ssg.routes === void 0) {
conf.ssg.routes = ['/']
}
// Client takeover to set body classes like desktop/mobile, touch/no-touch, etc...
// The server can't know the platform used from the browser at build time.
conf.boot.push({ server: false, path: '~quasar-app-extension-ssg/src/boot/body-classes' })
conf.build.transpileDependencies.push(/quasar-app-extension-ssg[\\/]src/)
conf.build.htmlFilename = conf.ssg.fallback
conf.build.ssrPwaHtmlFilename = conf.ssg.fallback
conf.build.vueRouterMode = 'history'
}
const chainWebpack = function ({ isClient, isServer }, chain, api, quasarConf) {
if (isClient && !api.ctx.mode.pwa) {
const injectHtml = appRequire('@quasar/app/lib/webpack/inject.html', api.appDir)
const cfg = merge(quasarConf, {
build: {
distDir: join(quasarConf.build.distDir, 'www')
}
})
injectHtml(chain, cfg)
}
if (isServer) {
const SsrArtifacts = require('./webpack/plugin.ssr-artifacts')
chain.plugin('ssr-artifacts')
.use(SsrArtifacts, [quasarConf, api])
}
if (api.ctx.mode.pwa) {
// handle workbox after build instead of webpack
// This way all assets could be precached, including generated html
chain.plugins.delete('workbox')
}
}
module.exports = function (api) {
api.registerCommand('generate', () => {
require('./bin/ssg-generate')(api)
})
api.registerCommand('serve', () => require('./bin/server'))
// Make sure we are running from command "quasar ssg"
if (api.ctx.prod && api.ctx.mode.ssr && process.argv[2] === 'ssg') {
let quasarConf = {}
api.extendQuasarConf((conf, api) => {
extendQuasarConf(conf, api)
quasarConf = conf
})
api.chainWebpack((chain, { isClient, isServer }, api) => chainWebpack({ isClient, isServer }, chain, api, quasarConf))
// We do not use webserver for SSG
api.chainWebpackWebserver((chain) => chain.plugins.delete('progress'))
}
}