From a2b89d3c44011e9c8c4af523a8d7039d9b27705c Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Thu, 17 Dec 2020 14:12:09 +0800 Subject: [PATCH] fix: resourceQuery could be undefined in webpack 5 fixes #1771 --- lib/index.js | 2 +- lib/plugin-webpack5.js | 2 ++ test/edgeCases.spec.js | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 990c86235..7760df47b 100644 --- a/lib/index.js +++ b/lib/index.js @@ -49,7 +49,7 @@ module.exports = function (source) { sourceMap, rootContext, resourcePath, - resourceQuery + resourceQuery = '' } = loaderContext const rawQuery = resourceQuery.slice(1) diff --git a/lib/plugin-webpack5.js b/lib/plugin-webpack5.js index dcec6e0c6..9b156ff12 100644 --- a/lib/plugin-webpack5.js +++ b/lib/plugin-webpack5.js @@ -120,6 +120,7 @@ class VueLoaderPlugin { const pitcher = { loader: require.resolve('./loaders/pitcher'), resourceQuery: query => { + if (!query) { return false } const parsed = qs.parse(query.slice(1)) return parsed.vue != null }, @@ -172,6 +173,7 @@ function cloneRule (rawRule, refs) { return true }, resourceQuery: query => { + if (!query) { return false } const parsed = qs.parse(query.slice(1)) if (parsed.vue == null) { return false diff --git a/test/edgeCases.spec.js b/test/edgeCases.spec.js index 8c4a4168a..f846d9483 100644 --- a/test/edgeCases.spec.js +++ b/test/edgeCases.spec.js @@ -1,5 +1,6 @@ const path = require('path') const normalizeNewline = require('normalize-newline') +const webpack = require('webpack') const HTMLPlugin = require('html-webpack-plugin') const { @@ -212,3 +213,17 @@ test('use with postLoader', done => { }, done) }) }) + +// #1711 +test('data: URI as entry', done => { + // this feature is only available in webpack 5 + if (webpack.version.startsWith('4')) { + return + } + + bundle({ + entry: { + main: 'data:text/javascript,console.log("hello world")' + } + }, () => done()) +})