From c802144e9bd1f56392a40c20b22da7dade237b66 Mon Sep 17 00:00:00 2001 From: JounQin Date: Fri, 3 Feb 2017 15:00:26 +0800 Subject: [PATCH] add another option *styleMode* When we are running on development, usually we won't extract global styles to a *.css* file, what will make the global style loaded after the server rendered *style* tags, then the style could be overridden by global styles. By default, `styleMode` is `true`, if it is set to `false`, the server rendered *styles* tags will be injected before `tail` instead of after `head`, so that the server rendered styles won't be overridden by global styles. --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index f71cc0c..acdfcd1 100644 --- a/index.js +++ b/index.js @@ -10,6 +10,7 @@ class HTMLStream extends Transform { this.neck = template.neck this.tail = template.tail this.context = options.context || {} + this.styleMode = options.styleMode == null || options.styleMode } _transform (data, encoding, done) { @@ -22,7 +23,7 @@ class HTMLStream extends Transform { this.push(this.context.head) } // inline server-rendered CSS collected by vue-style-loader - if (this.context.styles) { + if (this.styleMode && this.context.styles) { this.push(this.context.styles) } this.push(this.neck) @@ -39,6 +40,9 @@ class HTMLStream extends Transform { serialize(this.context.state, { isJSON: true }) }`) } + if (!this.styleMode && this.context.styles) { + this.push(this.context.styles) + } this.push(this.tail) done() }