Skip to content

Commit be28007

Browse files
skyhark-sachaAkryum
authored andcommitted
feat: Add the ability to disable critical css for users who wants to keep css separated (#48)
* Add the ability to disable criticalCss for users who wants to keep CSS in a separated file * Fix dev server render error when a custom path is used for the server-renderer bundles * refactor: rename to criticalCSS * docs: criticalCSS * chore: clean code + comments
1 parent 86de5f9 commit be28007

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

docs/guide/configuration.md

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ module.exports = {
2222
defaultTitle: 'My app',
2323
// Path to favicon
2424
favicon: './public/favicon.ico',
25+
// Enable Critical CSS
26+
criticalCSS: true,
2527
// Skip some requests from being server-side rendered
2628
skipRequests: req => req.originalUrl === '/graphql',
2729
// See https://ssr.vuejs.org/guide/build-config.html#externals-caveats

lib/config.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module.exports = {
99
entry: target => `./src/entry-${target}`,
1010
defaultTitle: 'My app',
1111
favicon: './public/favicon.ico',
12+
criticalCSS: true,
1213
skipRequests: req => req.originalUrl === '/graphql',
1314
nodeExternalsWhitelist: [/\.css$/, /\?vue&type=style/],
1415
applyDefaultServer: true,

lib/dev-server.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,13 @@ module.exports.setupDevServer = ({ server, templatePath, onUpdate }) => new Prom
7070
jsonStats.warnings.forEach(err => console.warn(err))
7171
}
7272
if (stats.hasErrors()) return
73+
74+
// Fix dev server render error when a custom path is used for the server-renderer bundles
75+
const ssrPlugin = (clientConfig.plugins.find((p) => (p.__pluginName || p.constructor.name) === 'ssr') || {}).options || {}
76+
7377
clientManifest = JSON.parse(readFile(
7478
devMiddleware.fileSystem,
75-
'vue-ssr-client-manifest.json'
79+
(ssrPlugin && ssrPlugin.filename) || 'vue-ssr-client-manifest.json'
7680
))
7781

7882
// HTML Template
@@ -109,8 +113,17 @@ module.exports.setupDevServer = ({ server, templatePath, onUpdate }) => new Prom
109113
jsonStats.warnings.forEach(err => console.warn(err))
110114
}
111115
if (stats.hasErrors()) return
116+
117+
// Try to find ssr plugin config options
118+
// to fix dev server render error when a custom path is used for the server-renderer bundles
119+
const ssrPlugin = (serverConfig.plugins.find((p) => (p.__pluginName || p.constructor.name) === 'ssr') || {}).options || {}
120+
112121
// read bundle generated by vue-ssr-webpack-plugin
113-
serverBundle = JSON.parse(readFile(serverMfs, 'vue-ssr-server-bundle.json'))
122+
serverBundle = JSON.parse(readFile(
123+
serverMfs,
124+
(ssrPlugin && ssrPlugin.filename) || 'vue-ssr-server-bundle.json'
125+
))
126+
114127
update()
115128
onCompilationCompleted()
116129
})

lib/webpack.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ exports.chainWebpack = (webpackConfig) => {
2424
webpackConfig.plugins.delete('friendly-errors')
2525

2626
const isExtracting = webpackConfig.plugins.has('extract-css')
27-
if (isExtracting) {
27+
if (isExtracting && config.criticalCSS) {
2828
// Remove extract
2929
const langs = ['css', 'postcss', 'scss', 'sass', 'less', 'stylus']
3030
const types = ['vue-modules', 'vue', 'normal-modules', 'normal']

0 commit comments

Comments
 (0)