From 7a9f03f913014423770bdc58dc9c9836ae24dfd8 Mon Sep 17 00:00:00 2001 From: Di Weng Date: Sun, 21 Jan 2018 19:19:10 +0800 Subject: [PATCH] Detect and skip WebWorker scripts --- lib/addStylesClient.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/addStylesClient.js b/lib/addStylesClient.js index c817574d..48bdfe6c 100644 --- a/lib/addStylesClient.js +++ b/lib/addStylesClient.js @@ -5,9 +5,10 @@ */ var hasDocument = typeof document !== 'undefined' +var isWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope if (typeof DEBUG !== 'undefined' && DEBUG) { - if (!hasDocument) { + if (!isWebWorker && !hasDocument) { throw new Error( 'vue-style-loader cannot be used in a non-browser environment. ' + "Use { target: 'node' } in your Webpack config to indicate a server-rendering environment." @@ -48,6 +49,10 @@ var noop = function () {} var isOldIE = typeof navigator !== 'undefined' && /msie [6-9]\b/.test(navigator.userAgent.toLowerCase()) module.exports = function (parentId, list, _isProduction) { + if (isWebWorker) { + return + } + isProduction = _isProduction var styles = listToStyles(parentId, list)