From 818d8e75b2aca551f6a10f050d1b17bcc7c994c0 Mon Sep 17 00:00:00 2001 From: ULIVZ <472590061@qq.com> Date: Sat, 2 Jun 2018 01:07:39 +0800 Subject: [PATCH 1/3] fix: throw error when options of cache-loader contains ! --- 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 9ed4ceece..a05d00bc9 100644 --- a/lib/loaders/pitcher.js +++ b/lib/loaders/pitcher.js @@ -74,7 +74,7 @@ module.exports.pitch = function (remainingRequest) { const cacheLoader = cacheDirectory && cacheIdentifier ? [`cache-loader?${JSON.stringify({ cacheDirectory, - cacheIdentifier: cacheIdentifier + '-vue-loader-template' + cacheIdentifier: cacheIdentifier.replace(/!/g, '') + '-vue-loader-template' })}`] : [] const request = genRequest([ From a729c2edce5bd60b966f020bda96ca7cc6a770e8 Mon Sep 17 00:00:00 2001 From: ULIVZ <472590061@qq.com> Date: Sat, 2 Jun 2018 01:12:55 +0800 Subject: [PATCH 2/3] docs: add some tips --- docs/options.md | 4 ++++ docs/zh/options.md | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/docs/options.md b/docs/options.md index c10180561..2be9e0314 100644 --- a/docs/options.md +++ b/docs/options.md @@ -81,3 +81,7 @@ Compiled the component for usage inside Shadow DOM. In this mode, the styles of - default: `undefined` When both options are specified, enables file-system-based template compilation caching (requires `cache-loader` to be installed in the same project). + +::: tip + Interaction between `vue-loader` and `cache-loader` uses [inline loader import syntax](https://webpack.js.org/concepts/loaders/#inline) under the hook, the `!` will be treated as the separator between different loaders, so please ensure `cacheDirectory` doesn't contain `!`. +::: diff --git a/docs/zh/options.md b/docs/zh/options.md index b8bfbfcbb..1cf0dc684 100644 --- a/docs/zh/options.md +++ b/docs/zh/options.md @@ -81,3 +81,7 @@ sidebar: auto - 默认值:`undefined` 当这两个选项同时被设置时,开启基于文件系统的模板编译缓存 (需要在工程里安装 `cache-loader`)。 + +::: tip 注意 + 在内部,`vue-loader` 和 `cache-loader` 之间的交互使用了 [loader 的内联 import 语法](https://webpack.js.org/concepts/loaders/#inline),`!` 将会被认为是不同 loaders 之间的分隔符,所以请确保你的 `cacheDirectory` 路径中不包含 `!`。 +::: From 448e5b953a649171ce3e73dcabd0f85dbce93931 Mon Sep 17 00:00:00 2001 From: ULIVZ <472590061@qq.com> Date: Sat, 2 Jun 2018 01:45:44 +0800 Subject: [PATCH 3/3] chore: hash the cacheIdentifier --- lib/loaders/pitcher.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/loaders/pitcher.js b/lib/loaders/pitcher.js index a05d00bc9..184e8fd09 100644 --- a/lib/loaders/pitcher.js +++ b/lib/loaders/pitcher.js @@ -1,5 +1,6 @@ const qs = require('querystring') const loaderUtils = require('loader-utils') +const hash = require('hash-sum') const selfPath = require.resolve('../index') const templateLoaderPath = require.resolve('./templateLoader') const stylePostLoaderPath = require.resolve('./stylePostLoader') @@ -74,7 +75,7 @@ module.exports.pitch = function (remainingRequest) { const cacheLoader = cacheDirectory && cacheIdentifier ? [`cache-loader?${JSON.stringify({ cacheDirectory, - cacheIdentifier: cacheIdentifier.replace(/!/g, '') + '-vue-loader-template' + cacheIdentifier: hash(cacheIdentifier) + '-vue-loader-template' })}`] : [] const request = genRequest([