From c359a38db0fbb4135fc97114baec3cd557d4123a Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Sun, 2 Jun 2019 14:43:57 +0800 Subject: [PATCH 001/146] chore: update @vue/component-compiler-utils to v3 It's a rather small change that does not affect vue-loader. Updated to accommodate future bug fixes. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7e202dddc..55f021e3c 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "webpack": "^4.1.0 || ^5.0.0-0" }, "dependencies": { - "@vue/component-compiler-utils": "^2.5.1", + "@vue/component-compiler-utils": "^3.0.0", "hash-sum": "^1.0.2", "loader-utils": "^1.1.0", "vue-hot-reload-api": "^2.3.0", From 6a05115ddf3ea680ab2b00862b2891da2e98a41c Mon Sep 17 00:00:00 2001 From: "X.L" Date: Thu, 18 Jul 2019 02:18:32 +0800 Subject: [PATCH 002/146] fix: use "api.isRecorded" instead of "module.hot.data" (#1569) --- lib/codegen/hotReload.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/codegen/hotReload.js b/lib/codegen/hotReload.js index 4f426b4d0..a1315a89d 100644 --- a/lib/codegen/hotReload.js +++ b/lib/codegen/hotReload.js @@ -19,7 +19,7 @@ if (module.hot) { api.install(require('vue')) if (api.compatible) { module.hot.accept() - if (!module.hot.data) { + if (!api.isRecorded('${id}')) { api.createRecord('${id}', component.options) } else { api.${functional ? 'rerender' : 'reload'}('${id}', component.options) From 0e5c7a133163fea4ec340a828de626baf18d170a Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Thu, 18 Jul 2019 14:55:12 +0800 Subject: [PATCH 003/146] chore: lockfile maintenance --- yarn.lock | 62 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/yarn.lock b/yarn.lock index bae4cb315..033af7330 100644 --- a/yarn.lock +++ b/yarn.lock @@ -851,20 +851,20 @@ source-map "^0.5.6" vue-template-es2015-compiler "^1.6.0" -"@vue/component-compiler-utils@^2.5.1": - version "2.5.1" - resolved "https://registry.yarnpkg.com/@vue/component-compiler-utils/-/component-compiler-utils-2.5.1.tgz#bd9cf68d728324d7dcede80462c2c0e8fe090acb" - integrity sha512-4mLLh8LYDciX4BO6FVfPbuG3QNYOI70dfsNcdCzHDnN/QYiJ9KWWrf9crSDa9D/aon+QME39Lj+XDHiy9t3sRQ== +"@vue/component-compiler-utils@^3.0.0": + version "3.0.0" + resolved "https://registry.yarnpkg.com/@vue/component-compiler-utils/-/component-compiler-utils-3.0.0.tgz#d16fa26b836c06df5baaeb45f3d80afc47e35634" + integrity sha512-am+04/0UX7ektcmvhYmrf84BDVAD8afFOf4asZjN84q8xzxFclbk5x0MtxuKGfp+zjN5WWPJn3fjFAWtDdIGSw== dependencies: consolidate "^0.15.1" hash-sum "^1.0.2" lru-cache "^4.1.2" merge-source-map "^1.1.0" - postcss "^7.0.7" + postcss "^7.0.14" postcss-selector-parser "^5.0.0" - prettier "1.16.0" - source-map "^0.7.3" - vue-template-es2015-compiler "^1.6.0" + prettier "1.16.3" + source-map "~0.6.1" + vue-template-es2015-compiler "^1.9.0" "@webassemblyjs/ast@1.5.13": version "1.5.13" @@ -2591,6 +2591,15 @@ chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.0, chalk@^2.3.1, chalk@^2.3 escape-string-regexp "^1.0.5" supports-color "^5.3.0" +chalk@^2.4.2: + version "2.4.2" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" + integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ== + dependencies: + ansi-styles "^3.2.1" + escape-string-regexp "^1.0.5" + supports-color "^5.3.0" + character-parser@^2.1.1: version "2.2.0" resolved "https://registry.yarnpkg.com/character-parser/-/character-parser-2.2.0.tgz#c7ce28f36d4bcd9744e5ffc2c5fcde1c73261fc0" @@ -8800,14 +8809,14 @@ postcss@^6.0.0, postcss@^6.0.1, postcss@^6.0.14, postcss@^6.0.20, postcss@^6.0.2 source-map "^0.6.1" supports-color "^5.4.0" -postcss@^7.0.7: - version "7.0.7" - resolved "https://registry.yarnpkg.com/postcss/-/postcss-7.0.7.tgz#2754d073f77acb4ef08f1235c36c5721a7201614" - integrity sha512-HThWSJEPkupqew2fnuQMEI2YcTj/8gMV3n80cMdJsKxfIh5tHf7nM5JigNX6LxVMqo6zkgQNAI88hyFvBk41Pg== +postcss@^7.0.14: + version "7.0.17" + resolved "https://registry.yarnpkg.com/postcss/-/postcss-7.0.17.tgz#4da1bdff5322d4a0acaab4d87f3e782436bad31f" + integrity sha512-546ZowA+KZ3OasvQZHsbuEpysvwTZNGJv9EfyCQdsIDltPSWHAeTQ5fQy/Npi2ZDtLI3zs7Ps/p6wThErhm9fQ== dependencies: - chalk "^2.4.1" + chalk "^2.4.2" source-map "^0.6.1" - supports-color "^5.5.0" + supports-color "^6.1.0" prelude-ls@~1.1.2: version "1.1.2" @@ -8829,10 +8838,10 @@ prettier@1.13.7: resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.13.7.tgz#850f3b8af784a49a6ea2d2eaa7ed1428a34b7281" integrity sha512-KIU72UmYPGk4MujZGYMFwinB7lOf2LsDNGSOC8ufevsrPLISrZbNJlWstRi3m0AMuszbH+EFSQ/r6w56RSPK6w== -prettier@1.16.0: - version "1.16.0" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.16.0.tgz#104dd25f5ee3d0c9d0a6ce4bb40ced8481d51219" - integrity sha512-MCBCYeAuZfejUPdEpkleLWvpRBwLii/Sp5jQs0eb8Ul/drGIDjkL6tAU24tk6yCGf0KPV5rhPPPlczfBmN2pWQ== +prettier@1.16.3: + version "1.16.3" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.16.3.tgz#8c62168453badef702f34b45b6ee899574a6a65d" + integrity sha512-kn/GU6SMRYPxUakNXhpP0EedT/KmaPzr0H5lIsDogrykbaxOpOfAFfk5XA7DZrJyMAv1wlMV3CPcZruGXVVUZw== pretty-bytes@^4.0.2: version "4.0.2" @@ -10131,11 +10140,6 @@ source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.0, source-map@~0.6.1: resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== -source-map@^0.7.3: - version "0.7.3" - resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.3.tgz#5302f8169031735226544092e64981f751750383" - integrity sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ== - spdx-correct@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/spdx-correct/-/spdx-correct-3.0.0.tgz#05a5b4d7153a195bc92c3c425b69f3b2a9524c82" @@ -10483,6 +10487,13 @@ supports-color@^5.5.0: dependencies: has-flag "^3.0.0" +supports-color@^6.1.0: + version "6.1.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-6.1.0.tgz#0764abc69c63d5ac842dd4867e8d025e880df8f3" + integrity sha512-qe1jfm1Mg7Nq/NSh6XE24gPXROEVsWHxC1LIx//XNlD9iw7YZQGjZNjYN7xGaEG6iKdA8EtNFW6R0gjnVXp+wQ== + dependencies: + has-flag "^3.0.0" + svgo@^0.7.0: version "0.7.2" resolved "https://registry.yarnpkg.com/svgo/-/svgo-0.7.2.tgz#9f5772413952135c6fefbf40afe6a4faa88b4bb5" @@ -11217,6 +11228,11 @@ vue-template-es2015-compiler@^1.6.0: resolved "https://registry.yarnpkg.com/vue-template-es2015-compiler/-/vue-template-es2015-compiler-1.6.0.tgz#dc42697133302ce3017524356a6c61b7b69b4a18" integrity sha512-x3LV3wdmmERhVCYy3quqA57NJW7F3i6faas++pJQWtknWT+n7k30F4TVdHvCLn48peTJFRvCpxs3UuFPqgeELg== +vue-template-es2015-compiler@^1.9.0: + version "1.9.1" + resolved "https://registry.yarnpkg.com/vue-template-es2015-compiler/-/vue-template-es2015-compiler-1.9.1.tgz#1ee3bc9a16ecbf5118be334bb15f9c46f82f5825" + integrity sha512-4gDntzrifFnCEvyoO8PqyJDmguXgVPxKiIxrBKjIowvL9l+N66196+72XVYR8BBf1Uv1Fgt3bGevJ+sEmxfZzw== + vue@^2.5.16: version "2.5.17" resolved "https://registry.yarnpkg.com/vue/-/vue-2.5.17.tgz#0f8789ad718be68ca1872629832ed533589c6ada" From 866043fd8adb1df0010aa03cfd62378b23cf1086 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Thu, 18 Jul 2019 15:37:52 +0800 Subject: [PATCH 004/146] 15.7.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 55f021e3c..8943087cd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-loader", - "version": "15.7.0", + "version": "15.7.1", "description": "Vue single-file component loader for Webpack", "main": "lib/index.js", "typings": "lib/index.d.ts", From 1aaedc7474f11db1036b01ba3ad4bbec9361dc96 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Thu, 18 Jul 2019 15:39:56 +0800 Subject: [PATCH 005/146] chore: changelog for v15.7.1 --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 350a6b216..e1c0e0279 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ + +## [15.7.1](https://github.com/vuejs/vue-loader/compare/v15.7.0...v15.7.1) (2019-07-18) + + +### Bug Fixes + +* use "api.isRecorded" instead of "module.hot.data" ([#1569](https://github.com/vuejs/vue-loader/issues/1569)) ([6a05115](https://github.com/vuejs/vue-loader/commit/6a05115)) + + + # [15.7.0](https://github.com/vuejs/vue-loader/compare/v15.6.4...v15.7.0) (2019-02-28) From d3fa467815c0a2da87fd3062ab8bb182cfa84264 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Nison?= Date: Mon, 2 Sep 2019 11:32:01 +0200 Subject: [PATCH 006/146] fix: use `require.resolve` when referencing `cache-loader` (#1585) --- lib/loaders/pitcher.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/loaders/pitcher.js b/lib/loaders/pitcher.js index 5cb3f46e2..222b9130c 100644 --- a/lib/loaders/pitcher.js +++ b/lib/loaders/pitcher.js @@ -128,7 +128,7 @@ module.exports.pitch = function (remainingRequest) { if (query.type === `template`) { const path = require('path') const cacheLoader = cacheDirectory && cacheIdentifier - ? [`cache-loader?${JSON.stringify({ + ? [`${require.resolve('cache-loader')}?${JSON.stringify({ // For some reason, webpack fails to generate consistent hash if we // use absolute paths here, even though the path is only used in a // comment. For now we have to ensure cacheDirectory is a relative path. From 0bcf3b707f68df654ee5331c60d15db7d8f1d954 Mon Sep 17 00:00:00 2001 From: Johnny <42905128+johnnywang1994@users.noreply.github.com> Date: Sun, 22 Sep 2019 13:03:19 +0800 Subject: [PATCH 007/146] docs: add `sassOptions` for sass-loader >= 8 (#1593) [ci skip] * #65 - add sassOptions for docs fix docs with error: 'options has an unknown property 'indentedSyntax'.' which new sass-loader are writen in 'sassOptions'; This should also cause quick prototyping's sass setting, after executing '$vue serve' * #65 - sassOptions fix for sass-loader * #65 - fix sassOptions - lang:ru * add comment for sassOptions version * add comment for sassOptions * add comment for sassOptions * Update docs/guide/pre-processors.md Co-Authored-By: Haoqun Jiang * Update pre-processors.md * Update pre-processors.md --- docs/guide/pre-processors.md | 4 ++++ docs/ru/guide/pre-processors.md | 4 ++++ docs/zh/guide/pre-processors.md | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/docs/guide/pre-processors.md b/docs/guide/pre-processors.md index 737b9df14..8c7fde45d 100644 --- a/docs/guide/pre-processors.md +++ b/docs/guide/pre-processors.md @@ -63,6 +63,10 @@ Note that `sass-loader` processes the non-indent-based `scss` syntax by default. loader: 'sass-loader', options: { indentedSyntax: true + // sass-loader version >= 8 + sassOptions: { + indentedSyntax: true + } } } ] diff --git a/docs/ru/guide/pre-processors.md b/docs/ru/guide/pre-processors.md index 04c49ec96..32e2a432c 100644 --- a/docs/ru/guide/pre-processors.md +++ b/docs/ru/guide/pre-processors.md @@ -63,6 +63,10 @@ module.exports = { loader: 'sass-loader', options: { indentedSyntax: true + // sass-loader >= 8 + sassOptions: { + indentedSyntax: true + } } } ] diff --git a/docs/zh/guide/pre-processors.md b/docs/zh/guide/pre-processors.md index cf96e9423..369ae6e29 100644 --- a/docs/zh/guide/pre-processors.md +++ b/docs/zh/guide/pre-processors.md @@ -63,6 +63,10 @@ module.exports = { loader: 'sass-loader', options: { indentedSyntax: true + // sass-loader version >= 8 + sassOptions: { + indentedSyntax: true + } } } ] From e8be394c83868aa18b96c5d9bbe35d7b767e5fd0 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Sun, 22 Sep 2019 13:57:36 +0800 Subject: [PATCH 008/146] docs: use prependData in sass-loader >= v8 --- docs/guide/pre-processors.md | 3 ++- docs/ru/guide/pre-processors.md | 3 ++- docs/zh/guide/pre-processors.md | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/guide/pre-processors.md b/docs/guide/pre-processors.md index 8c7fde45d..c9310faad 100644 --- a/docs/guide/pre-processors.md +++ b/docs/guide/pre-processors.md @@ -88,7 +88,8 @@ Note that `sass-loader` processes the non-indent-based `scss` syntax by default. loader: 'sass-loader', options: { // you can also read from a file, e.g. `variables.scss` - data: `$color: red;` + // use `data` here if sass-loader version < 8 + prependData: `$color: red;` } } ] diff --git a/docs/ru/guide/pre-processors.md b/docs/ru/guide/pre-processors.md index 32e2a432c..de6a956f5 100644 --- a/docs/ru/guide/pre-processors.md +++ b/docs/ru/guide/pre-processors.md @@ -88,7 +88,8 @@ module.exports = { loader: 'sass-loader', options: { // вы можете также указать файл, например `variables.scss` - data: `$color: red;` + // use `data` here if sass-loader version < 8 + prependData: `$color: red;` } } ] diff --git a/docs/zh/guide/pre-processors.md b/docs/zh/guide/pre-processors.md index 369ae6e29..bad2a6212 100644 --- a/docs/zh/guide/pre-processors.md +++ b/docs/zh/guide/pre-processors.md @@ -88,7 +88,8 @@ module.exports = { loader: 'sass-loader', options: { // 你也可以从一个文件读取,例如 `variables.scss` - data: `$color: red;` + // 如果 sass-loader 版本 < 8,这里使用 `data` 字段 + prependData: `$color: red;` } } ] From 5fab977f837370b575ebe26da535eaadd36a75bf Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Mon, 23 Sep 2019 12:09:10 +0800 Subject: [PATCH 009/146] docs: `data` -> `prependData` [ci skip] --- docs/guide/pre-processors.md | 2 +- docs/ru/guide/pre-processors.md | 2 +- docs/zh/guide/pre-processors.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/guide/pre-processors.md b/docs/guide/pre-processors.md index c9310faad..c6de149a1 100644 --- a/docs/guide/pre-processors.md +++ b/docs/guide/pre-processors.md @@ -75,7 +75,7 @@ Note that `sass-loader` processes the non-indent-based `scss` syntax by default. ### Sharing Global Variables -`sass-loader` also supports a `data` option which allows you to share common variables among all processed files without having to explicit import them: +`sass-loader` also supports a `prependData` option which allows you to share common variables among all processed files without having to explicit import them: ``` js // webpack.config.js -> module.rules diff --git a/docs/ru/guide/pre-processors.md b/docs/ru/guide/pre-processors.md index de6a956f5..44b653e77 100644 --- a/docs/ru/guide/pre-processors.md +++ b/docs/ru/guide/pre-processors.md @@ -75,7 +75,7 @@ module.exports = { ### Передача глобальных переменных -`sass-loader` также поддерживает опцию `data`, которая позволяет вам передавать общие переменные во все обрабатываемые файлы без необходимости везде их явно импортировать: +`sass-loader` также поддерживает опцию `prependData`, которая позволяет вам передавать общие переменные во все обрабатываемые файлы без необходимости везде их явно импортировать: ``` js // webpack.config.js -> module.rules diff --git a/docs/zh/guide/pre-processors.md b/docs/zh/guide/pre-processors.md index bad2a6212..ff05552d6 100644 --- a/docs/zh/guide/pre-processors.md +++ b/docs/zh/guide/pre-processors.md @@ -75,7 +75,7 @@ module.exports = { ### 共享全局变量 -`sass-loader` 也支持一个 `data` 选项,这个选项允许你在所有被处理的文件之间共享常见的变量,而不需要显式地导入它们: +`sass-loader` 也支持一个 `prependData` 选项,这个选项允许你在所有被处理的文件之间共享常见的变量,而不需要显式地导入它们: ``` js // webpack.config.js -> module.rules From e1c11cf87dfab6e57a17b0707686f389de04dec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=BB=D1=8C=D1=8F?= Date: Sat, 12 Oct 2019 17:05:38 +0300 Subject: [PATCH 010/146] docs: fix end of tag style (#1579) Based on good practices. --- docs/guide/custom-blocks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guide/custom-blocks.md b/docs/guide/custom-blocks.md index 59b4d6042..f34c18317 100644 --- a/docs/guide/custom-blocks.md +++ b/docs/guide/custom-blocks.md @@ -76,7 +76,7 @@ This is the documentation for component B. From e9d8b716492960a3def2052da22be43500ca890f Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Sat, 2 Nov 2019 12:54:49 +0800 Subject: [PATCH 011/146] fix: add cache-loader to optional peer dependency fix compatibility with yarn 2 --- package.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/package.json b/package.json index 8943087cd..b86ffbeaa 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,11 @@ "css-loader": "*", "webpack": "^4.1.0 || ^5.0.0-0" }, + "peerDependenciesMeta": { + "cache-loader": { + "optional": true + } + }, "dependencies": { "@vue/component-compiler-utils": "^3.0.0", "hash-sum": "^1.0.2", From ede19fee947e4ec337c0c991078fced847f97288 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Sat, 2 Nov 2019 13:20:18 +0800 Subject: [PATCH 012/146] 15.7.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b86ffbeaa..d9801e445 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-loader", - "version": "15.7.1", + "version": "15.7.2", "description": "Vue single-file component loader for Webpack", "main": "lib/index.js", "typings": "lib/index.d.ts", From e107cf1ed498c9bef94f0c4b59bb9bfb7eb88ff8 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Sat, 2 Nov 2019 13:20:48 +0800 Subject: [PATCH 013/146] chore: changelog for v15.7.2 --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1c0e0279..032e0e047 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ + +## [15.7.2](https://github.com/vuejs/vue-loader/compare/v15.7.1...v15.7.2) (2019-11-02) + + +### Bug Fixes + +* add cache-loader to optional peer dependency ([e9d8b71](https://github.com/vuejs/vue-loader/commit/e9d8b71)) +* use `require.resolve` when referencing `cache-loader` ([#1585](https://github.com/vuejs/vue-loader/issues/1585)) ([d3fa467](https://github.com/vuejs/vue-loader/commit/d3fa467)) + + + ## [15.7.1](https://github.com/vuejs/vue-loader/compare/v15.7.0...v15.7.1) (2019-07-18) From 0751213cc760488c310c8c58b3b4c24381827a95 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Wed, 6 Nov 2019 15:06:01 +0800 Subject: [PATCH 014/146] fix(types): should import type definition from the `dist` folder --- lib/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.d.ts b/lib/index.d.ts index b21db5c16..28a4e3c5f 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -1,5 +1,5 @@ import { Plugin } from 'webpack' -import { VueTemplateCompiler } from '@vue/component-compiler-utils/lib/types' +import { VueTemplateCompiler } from '@vue/component-compiler-utils/dist/types' import { CompilerOptions } from 'vue-template-compiler' declare namespace VueLoader { From d0ccd1748d22bc584b36df9583f58652f036bdcb Mon Sep 17 00:00:00 2001 From: Huzi Cheng Date: Sun, 10 Nov 2019 08:30:38 -0500 Subject: [PATCH 015/146] docs(zh): fix typo (#1605) [ci skip] --- docs/zh/guide/pre-processors.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/zh/guide/pre-processors.md b/docs/zh/guide/pre-processors.md index ff05552d6..efb709922 100644 --- a/docs/zh/guide/pre-processors.md +++ b/docs/zh/guide/pre-processors.md @@ -225,7 +225,7 @@ TypeScript 的配置可以通过 `tsconfig.json` 来完成。你也可以查阅 ## Pug -模板的处理会稍微有些不同,因为绝大对数 webpack 的模板类 loader,诸如 `pug-loader`,会返回一个模板函数而不是一个编译好的 HTML 字符串。所以我们需要使用一个返回原始的 HTML 字符串的 loader,例如 `pug-plain-loader`,而不是使用 `pug-loader`。 +模板的处理会稍微有些不同,因为绝大多数 webpack 的模板类 loader,诸如 `pug-loader`,会返回一个模板函数而不是一个编译好的 HTML 字符串。所以我们需要使用一个返回原始的 HTML 字符串的 loader,例如 `pug-plain-loader`,而不是使用 `pug-loader`。 ``` bash npm install -D pug pug-plain-loader From 51bbe040b956d7602913317634d355c0a9faa62a Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Wed, 27 Nov 2019 23:43:42 +0800 Subject: [PATCH 016/146] test: use `options` object instead of inline query string --- test/template.spec.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/template.spec.js b/test/template.spec.js index 1fee594ac..b0c0c4cdb 100644 --- a/test/template.spec.js +++ b/test/template.spec.js @@ -49,7 +49,13 @@ test('transform relative URLs and respects resolve alias', done => { }, module: { rules: [ - { test: /\.png$/, loader: 'file-loader?name=[name].[hash:6].[ext]' } + { + test: /\.png$/, + loader: 'file-loader', + options: { + name: '[name].[hash:6].[ext]' + } + } ] } }, ({ window, module }) => { From 1f57f5e9244119ebdb844444448fdc16168248d5 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Wed, 27 Nov 2019 23:44:57 +0800 Subject: [PATCH 017/146] test: `devtool` option does not need a leading `#` --- test/advanced.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/advanced.spec.js b/test/advanced.spec.js index 212ef4ef2..5d57e138c 100644 --- a/test/advanced.spec.js +++ b/test/advanced.spec.js @@ -90,7 +90,7 @@ test('expose file basename as __file in production when exposeFilename enabled', test('source map', done => { bundle({ entry: 'basic.vue', - devtool: '#source-map' + devtool: 'source-map' }, code => { const map = mfs.readFileSync('/test.build.js.map', 'utf-8') const smc = new SourceMapConsumer(JSON.parse(map)) From 92c02cb071cd348bc6c198beb936477566ae9c87 Mon Sep 17 00:00:00 2001 From: Alexander Sokolov Date: Thu, 28 Nov 2019 05:43:05 +0300 Subject: [PATCH 018/146] docs: [RU] Translation update (#1611) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [RU] Translation moved to VuePress * custom-block.md example fix * fix link * options.md правка * testing.md fix links * linting.md fix link * options.md added new section * options.md add exposeFilename * guide/README.md update * README.md обновление * docs: [RU] update * pre-processors.md update * custom-blocks.md update --- docs/ru/guide/custom-blocks.md | 2 +- docs/ru/guide/pre-processors.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/ru/guide/custom-blocks.md b/docs/ru/guide/custom-blocks.md index 3c3bb5758..6ac91f677 100644 --- a/docs/ru/guide/custom-blocks.md +++ b/docs/ru/guide/custom-blocks.md @@ -74,7 +74,7 @@ This is the documentation for component B. diff --git a/docs/ru/guide/pre-processors.md b/docs/ru/guide/pre-processors.md index 44b653e77..c96da2a04 100644 --- a/docs/ru/guide/pre-processors.md +++ b/docs/ru/guide/pre-processors.md @@ -88,7 +88,7 @@ module.exports = { loader: 'sass-loader', options: { // вы можете также указать файл, например `variables.scss` - // use `data` here if sass-loader version < 8 + // используйте свойство `data` здесь, если версия sass-loader < 8 prependData: `$color: red;` } } From 59eebca04f4d4290fb47f07861f62899c577897f Mon Sep 17 00:00:00 2001 From: 18566246732 <32592393+18566246732@users.noreply.github.com> Date: Tue, 10 Dec 2019 09:47:28 -0600 Subject: [PATCH 019/146] feat: add support for webpack5 (#1613) --- lib/plugin-webpack4.js | 163 ++++++++++++++++++++++++++++++++++ lib/plugin-webpack5.js | 193 +++++++++++++++++++++++++++++++++++++++++ lib/plugin.js | 169 ++---------------------------------- 3 files changed, 365 insertions(+), 160 deletions(-) create mode 100644 lib/plugin-webpack4.js create mode 100644 lib/plugin-webpack5.js diff --git a/lib/plugin-webpack4.js b/lib/plugin-webpack4.js new file mode 100644 index 000000000..a5d91a2f2 --- /dev/null +++ b/lib/plugin-webpack4.js @@ -0,0 +1,163 @@ +const qs = require('querystring') +const RuleSet = require('webpack/lib/RuleSet') + +const id = 'vue-loader-plugin' +const NS = 'vue-loader' + +class VueLoaderPlugin { + apply (compiler) { + // add NS marker so that the loader can detect and report missing plugin + if (compiler.hooks) { + // webpack 4 + compiler.hooks.compilation.tap(id, compilation => { + let normalModuleLoader + if (Object.isFrozen(compilation.hooks)) { + // webpack 5 + normalModuleLoader = require('webpack/lib/NormalModule').getCompilationHooks(compilation).loader + } else { + normalModuleLoader = compilation.hooks.normalModuleLoader + } + normalModuleLoader.tap(id, loaderContext => { + loaderContext[NS] = true + }) + }) + } else { + // webpack < 4 + compiler.plugin('compilation', compilation => { + compilation.plugin('normal-module-loader', loaderContext => { + loaderContext[NS] = true + }) + }) + } + + // use webpack's RuleSet utility to normalize user rules + const rawRules = compiler.options.module.rules + const { rules } = new RuleSet(rawRules) + + // find the rule that applies to vue files + let vueRuleIndex = rawRules.findIndex(createMatcher(`foo.vue`)) + if (vueRuleIndex < 0) { + vueRuleIndex = rawRules.findIndex(createMatcher(`foo.vue.html`)) + } + const vueRule = rules[vueRuleIndex] + + if (!vueRule) { + throw new Error( + `[VueLoaderPlugin Error] No matching rule for .vue files found.\n` + + `Make sure there is at least one root-level rule that matches .vue or .vue.html files.` + ) + } + + if (vueRule.oneOf) { + throw new Error( + `[VueLoaderPlugin Error] vue-loader 15 currently does not support vue rules with oneOf.` + ) + } + + // get the normlized "use" for vue files + const vueUse = vueRule.use + // get vue-loader options + const vueLoaderUseIndex = vueUse.findIndex(u => { + return /^vue-loader|(\/|\\|@)vue-loader/.test(u.loader) + }) + + if (vueLoaderUseIndex < 0) { + throw new Error( + `[VueLoaderPlugin Error] No matching use for vue-loader is found.\n` + + `Make sure the rule matching .vue files include vue-loader in its use.` + ) + } + + // make sure vue-loader options has a known ident so that we can share + // options by reference in the template-loader by using a ref query like + // template-loader??vue-loader-options + const vueLoaderUse = vueUse[vueLoaderUseIndex] + vueLoaderUse.ident = 'vue-loader-options' + vueLoaderUse.options = vueLoaderUse.options || {} + + // for each user rule (expect the vue rule), create a cloned rule + // that targets the corresponding language blocks in *.vue files. + const clonedRules = rules + .filter(r => r !== vueRule) + .map(cloneRule) + + // global pitcher (responsible for injecting template compiler loader & CSS + // post loader) + const pitcher = { + loader: require.resolve('./loaders/pitcher'), + resourceQuery: query => { + const parsed = qs.parse(query.slice(1)) + return parsed.vue != null + }, + options: { + cacheDirectory: vueLoaderUse.options.cacheDirectory, + cacheIdentifier: vueLoaderUse.options.cacheIdentifier + } + } + + // replace original rules + compiler.options.module.rules = [ + pitcher, + ...clonedRules, + ...rules + ] + } +} + +function createMatcher (fakeFile) { + return (rule, i) => { + // #1201 we need to skip the `include` check when locating the vue rule + const clone = Object.assign({}, rule) + delete clone.include + const normalized = RuleSet.normalizeRule(clone, {}, '') + return ( + !rule.enforce && + normalized.resource && + normalized.resource(fakeFile) + ) + } +} + +function cloneRule (rule) { + const { resource, resourceQuery } = rule + // Assuming `test` and `resourceQuery` tests are executed in series and + // synchronously (which is true based on RuleSet's implementation), we can + // save the current resource being matched from `test` so that we can access + // it in `resourceQuery`. This ensures when we use the normalized rule's + // resource check, include/exclude are matched correctly. + let currentResource + const res = Object.assign({}, rule, { + resource: { + test: resource => { + currentResource = resource + return true + } + }, + resourceQuery: query => { + const parsed = qs.parse(query.slice(1)) + if (parsed.vue == null) { + return false + } + if (resource && parsed.lang == null) { + return false + } + const fakeResourcePath = `${currentResource}.${parsed.lang}` + if (resource && !resource(fakeResourcePath)) { + return false + } + if (resourceQuery && !resourceQuery(query)) { + return false + } + return true + } + }) + + if (rule.oneOf) { + res.oneOf = rule.oneOf.map(cloneRule) + } + + return res +} + +VueLoaderPlugin.NS = NS +module.exports = VueLoaderPlugin diff --git a/lib/plugin-webpack5.js b/lib/plugin-webpack5.js new file mode 100644 index 000000000..a3ec14dff --- /dev/null +++ b/lib/plugin-webpack5.js @@ -0,0 +1,193 @@ +const qs = require('querystring') +const id = 'vue-loader-plugin' +const NS = 'vue-loader' +const BasicEffectRulePlugin = require('webpack/lib/rules/BasicEffectRulePlugin') +const BasicMatcherRulePlugin = require('webpack/lib/rules/BasicMatcherRulePlugin') +const RuleSetCompiler = require('webpack/lib/rules/RuleSetCompiler') +const UseEffectRulePlugin = require('webpack/lib/rules/UseEffectRulePlugin') + +const ruleSetCompiler = new RuleSetCompiler([ + new BasicMatcherRulePlugin('test', 'resource'), + new BasicMatcherRulePlugin('include', 'resource'), + new BasicMatcherRulePlugin('exclude', 'resource', true), + new BasicMatcherRulePlugin('resource'), + new BasicMatcherRulePlugin('conditions'), + new BasicMatcherRulePlugin('resourceQuery'), + new BasicMatcherRulePlugin('realResource'), + new BasicMatcherRulePlugin('issuer'), + new BasicMatcherRulePlugin('compiler'), + new BasicEffectRulePlugin('type'), + new BasicEffectRulePlugin('sideEffects'), + new BasicEffectRulePlugin('parser'), + new BasicEffectRulePlugin('resolve'), + new UseEffectRulePlugin() +]) + +class VueLoaderPlugin { + apply (compiler) { + // add NS marker so that the loader can detect and report missing plugin + compiler.hooks.compilation.tap(id, compilation => { + const normalModuleLoader = require('webpack/lib/NormalModule').getCompilationHooks(compilation).loader + normalModuleLoader.tap(id, loaderContext => { + loaderContext[NS] = true + }) + }) + + const rules = compiler.options.module.rules + let rawVueRules + let vueRules = [] + + for (const rawRule of rules) { + // skip the `include` check when locating the vue rule + const clonedRawRule = Object.assign({}, rawRule) + delete clonedRawRule.include + + const ruleSet = ruleSetCompiler.compile([{ + rules: [clonedRawRule] + }]) + vueRules = ruleSet.exec({ + resource: 'foo.vue' + }) + + if (!vueRules.length) { + vueRules = ruleSet.exec({ + resource: 'foo.vue.html' + }) + } + if (vueRules.length > 0) { + if (rawRule.oneOf) { + throw new Error( + `[VueLoaderPlugin Error] vue-loader 15 currently does not support vue rules with oneOf.` + ) + } + rawVueRules = rawRule + break + } + } + if (!vueRules.length) { + throw new Error( + `[VueLoaderPlugin Error] No matching rule for .vue files found.\n` + + `Make sure there is at least one root-level rule that matches .vue or .vue.html files.` + ) + } + + // get the normlized "use" for vue files + const vueUse = vueRules.filter(rule => rule.type === 'use').map(rule => rule.value) + + // get vue-loader options + const vueLoaderUseIndex = vueUse.findIndex(u => { + return /^vue-loader|(\/|\\|@)vue-loader/.test(u.loader) + }) + + if (vueLoaderUseIndex < 0) { + throw new Error( + `[VueLoaderPlugin Error] No matching use for vue-loader is found.\n` + + `Make sure the rule matching .vue files include vue-loader in its use.` + ) + } + + // make sure vue-loader options has a known ident so that we can share + // options by reference in the template-loader by using a ref query like + // template-loader??vue-loader-options + const vueLoaderUse = vueUse[vueLoaderUseIndex] + vueLoaderUse.ident = 'vue-loader-options' + vueLoaderUse.options = vueLoaderUse.options || {} + + // for each user rule (expect the vue rule), create a cloned rule + // that targets the corresponding language blocks in *.vue files. + const refs = new Map() + const clonedRules = rules + .filter(r => r !== rawVueRules) + .map((rawRule) => cloneRule(rawRule, refs)) + + // fix conflict with config.loader and config.options when using config.use + delete rawVueRules.loader + delete rawVueRules.options + rawVueRules.use = vueUse + + // global pitcher (responsible for injecting template compiler loader & CSS + // post loader) + const pitcher = { + loader: require.resolve('./loaders/pitcher'), + resourceQuery: query => { + const parsed = qs.parse(query.slice(1)) + return parsed.vue != null + }, + options: { + cacheDirectory: vueLoaderUse.options.cacheDirectory, + cacheIdentifier: vueLoaderUse.options.cacheIdentifier + } + } + + // replace original rules + compiler.options.module.rules = [ + pitcher, + ...clonedRules, + ...rules + ] + } +} + +function cloneRule (rawRule, refs) { + const rules = ruleSetCompiler.compileRules('ruleSet', [{ + rules: [rawRule] + }], refs) + let currentResource + + const conditions = rules[0].rules + .map(rule => rule.conditions) + // shallow flat + .reduce((prev, next) => prev.concat(next), []) + + // do not process rule with enforce + if (!rawRule.enforce) { + const ruleUse = rules[0].rules + .map(rule => rule.effects + .filter(effect => effect.type === 'use') + .map(effect => effect.value) + ) + // shallow flat + .reduce((prev, next) => prev.concat(next), []) + + // fix conflict with config.loader and config.options when using config.use + delete rawRule.loader + delete rawRule.options + rawRule.use = ruleUse + } + + const res = Object.assign({}, rawRule, { + resource: resources => { + currentResource = resources + return true + }, + resourceQuery: query => { + const parsed = qs.parse(query.slice(1)) + if (parsed.vue == null) { + return false + } + if (!conditions) { + return false + } + const fakeResourcePath = `${currentResource}.${parsed.lang}` + for (const condition of conditions) { + // add support for resourceQuery + const request = condition.property === 'resourceQuery' ? query : fakeResourcePath + if (condition && !condition.fn(request)) { + return false + } + } + return true + } + }) + + delete res.test + + if (rawRule.oneOf) { + res.oneOf = rawRule.oneOf.map(rule => cloneRule(rule, refs)) + } + + return res +} + +VueLoaderPlugin.NS = NS +module.exports = VueLoaderPlugin diff --git a/lib/plugin.js b/lib/plugin.js index a5d91a2f2..87848bf6b 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -1,163 +1,12 @@ -const qs = require('querystring') -const RuleSet = require('webpack/lib/RuleSet') - -const id = 'vue-loader-plugin' -const NS = 'vue-loader' - -class VueLoaderPlugin { - apply (compiler) { - // add NS marker so that the loader can detect and report missing plugin - if (compiler.hooks) { - // webpack 4 - compiler.hooks.compilation.tap(id, compilation => { - let normalModuleLoader - if (Object.isFrozen(compilation.hooks)) { - // webpack 5 - normalModuleLoader = require('webpack/lib/NormalModule').getCompilationHooks(compilation).loader - } else { - normalModuleLoader = compilation.hooks.normalModuleLoader - } - normalModuleLoader.tap(id, loaderContext => { - loaderContext[NS] = true - }) - }) - } else { - // webpack < 4 - compiler.plugin('compilation', compilation => { - compilation.plugin('normal-module-loader', loaderContext => { - loaderContext[NS] = true - }) - }) - } - - // use webpack's RuleSet utility to normalize user rules - const rawRules = compiler.options.module.rules - const { rules } = new RuleSet(rawRules) - - // find the rule that applies to vue files - let vueRuleIndex = rawRules.findIndex(createMatcher(`foo.vue`)) - if (vueRuleIndex < 0) { - vueRuleIndex = rawRules.findIndex(createMatcher(`foo.vue.html`)) - } - const vueRule = rules[vueRuleIndex] - - if (!vueRule) { - throw new Error( - `[VueLoaderPlugin Error] No matching rule for .vue files found.\n` + - `Make sure there is at least one root-level rule that matches .vue or .vue.html files.` - ) - } - - if (vueRule.oneOf) { - throw new Error( - `[VueLoaderPlugin Error] vue-loader 15 currently does not support vue rules with oneOf.` - ) - } - - // get the normlized "use" for vue files - const vueUse = vueRule.use - // get vue-loader options - const vueLoaderUseIndex = vueUse.findIndex(u => { - return /^vue-loader|(\/|\\|@)vue-loader/.test(u.loader) - }) - - if (vueLoaderUseIndex < 0) { - throw new Error( - `[VueLoaderPlugin Error] No matching use for vue-loader is found.\n` + - `Make sure the rule matching .vue files include vue-loader in its use.` - ) - } - - // make sure vue-loader options has a known ident so that we can share - // options by reference in the template-loader by using a ref query like - // template-loader??vue-loader-options - const vueLoaderUse = vueUse[vueLoaderUseIndex] - vueLoaderUse.ident = 'vue-loader-options' - vueLoaderUse.options = vueLoaderUse.options || {} - - // for each user rule (expect the vue rule), create a cloned rule - // that targets the corresponding language blocks in *.vue files. - const clonedRules = rules - .filter(r => r !== vueRule) - .map(cloneRule) - - // global pitcher (responsible for injecting template compiler loader & CSS - // post loader) - const pitcher = { - loader: require.resolve('./loaders/pitcher'), - resourceQuery: query => { - const parsed = qs.parse(query.slice(1)) - return parsed.vue != null - }, - options: { - cacheDirectory: vueLoaderUse.options.cacheDirectory, - cacheIdentifier: vueLoaderUse.options.cacheIdentifier - } - } - - // replace original rules - compiler.options.module.rules = [ - pitcher, - ...clonedRules, - ...rules - ] - } -} - -function createMatcher (fakeFile) { - return (rule, i) => { - // #1201 we need to skip the `include` check when locating the vue rule - const clone = Object.assign({}, rule) - delete clone.include - const normalized = RuleSet.normalizeRule(clone, {}, '') - return ( - !rule.enforce && - normalized.resource && - normalized.resource(fakeFile) - ) - } -} - -function cloneRule (rule) { - const { resource, resourceQuery } = rule - // Assuming `test` and `resourceQuery` tests are executed in series and - // synchronously (which is true based on RuleSet's implementation), we can - // save the current resource being matched from `test` so that we can access - // it in `resourceQuery`. This ensures when we use the normalized rule's - // resource check, include/exclude are matched correctly. - let currentResource - const res = Object.assign({}, rule, { - resource: { - test: resource => { - currentResource = resource - return true - } - }, - resourceQuery: query => { - const parsed = qs.parse(query.slice(1)) - if (parsed.vue == null) { - return false - } - if (resource && parsed.lang == null) { - return false - } - const fakeResourcePath = `${currentResource}.${parsed.lang}` - if (resource && !resource(fakeResourcePath)) { - return false - } - if (resourceQuery && !resourceQuery(query)) { - return false - } - return true - } - }) - - if (rule.oneOf) { - res.oneOf = rule.oneOf.map(cloneRule) - } - - return res +const webpack = require('webpack') +let VueLoaderPlugin = null + +if (webpack.version[0] > 4) { + // webpack5 and upper + VueLoaderPlugin = require('./plugin-webpack5') +} else { + // webpack4 and lower + VueLoaderPlugin = require('./plugin-webpack4') } -VueLoaderPlugin.NS = NS module.exports = VueLoaderPlugin From 9f75bf31b145054d67985b6b9c37f0088ddca13b Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Wed, 11 Dec 2019 21:16:46 +0800 Subject: [PATCH 020/146] chore: remove unreachable branch --- lib/plugin-webpack4.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/plugin-webpack4.js b/lib/plugin-webpack4.js index a5d91a2f2..77fb65681 100644 --- a/lib/plugin-webpack4.js +++ b/lib/plugin-webpack4.js @@ -10,13 +10,7 @@ class VueLoaderPlugin { if (compiler.hooks) { // webpack 4 compiler.hooks.compilation.tap(id, compilation => { - let normalModuleLoader - if (Object.isFrozen(compilation.hooks)) { - // webpack 5 - normalModuleLoader = require('webpack/lib/NormalModule').getCompilationHooks(compilation).loader - } else { - normalModuleLoader = compilation.hooks.normalModuleLoader - } + const normalModuleLoader = compilation.hooks.normalModuleLoader normalModuleLoader.tap(id, loaderContext => { loaderContext[NS] = true }) From 759b07d20667a24876d8c1c5b19f621071f4d2cf Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 12 Dec 2019 11:12:05 -0500 Subject: [PATCH 021/146] chore: add How It Workds to README [ci skip] --- README.md | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/README.md b/README.md index 5828ac012..35291c56a 100644 --- a/README.md +++ b/README.md @@ -42,3 +42,79 @@ There are many cool features provided by `vue-loader`: - State-preserving hot-reloading during development. In a nutshell, the combination of webpack and `vue-loader` gives you a modern, flexible and extremely powerful front-end workflow for authoring Vue.js applications. + +## How It Works + +> The following section is for maintainers and contributors who are interested in the internal implementation details of `vue-loader`, and is **not** required knowledge for end users. + +`vue-loader` is not a simple source transform loader. It handles each language blocks inside an SFC with its own dedicated loader chain (you can think of each block as a "virtual module"), and finally assembles the blocks together into the final module. Here's a brief overview of how the whole thing works: + +1. `vue-loader` parses the SFC source code into an *SFC Descriptor* using `@vue/compiler-sfc`. It then generates an import for each language block so the actual returned module code looks like this: + + ``` js + // code returned from the main loader for 'source.vue' + + // import the