From 4d70b20ee931b1f04818a90ef4e13c7a1e94d53e Mon Sep 17 00:00:00 2001 From: Matthew Evans Date: Mon, 28 May 2018 16:25:44 -0600 Subject: [PATCH] Allow post loaders for template blocks This also sets a default 'lang="html"' query for template blocks. --- docs/migrating.md | 4 ++++ docs/options.md | 7 +++++++ lib/index.js | 2 +- lib/loaders/pitcher.js | 1 + lib/loaders/stylePostLoader.js | 2 +- lib/plugin.js | 5 ++++- test/fixtures/template-post.js | 3 +++ test/fixtures/template-post.vue | 5 +++++ test/template.spec.js | 14 ++++++++++++++ 9 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/template-post.js create mode 100644 test/fixtures/template-post.vue diff --git a/docs/migrating.md b/docs/migrating.md index 73586d5de..f2d281a37 100644 --- a/docs/migrating.md +++ b/docs/migrating.md @@ -251,6 +251,10 @@ The following options have been deprecated and should be configured using normal - `extractCSS` - `template` +:::tip +Template render functions cannot be post-processed by Webpack Rules because the `enforce: 'post'` option is not preserved for Vue Loader to interact with. `templatePostLoaders` now exists to accommodate these use cases. +::: + The following options have been deprecated and should be configured using the new `compilerOptions` option: - `preserveWhitespace` (use `compilerOptions.preserveWhitespace`) diff --git a/docs/options.md b/docs/options.md index c10180561..70b0e2c69 100644 --- a/docs/options.md +++ b/docs/options.md @@ -81,3 +81,10 @@ 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). + +## templatePostLoaders + +- type: `Array` +- default: `[]` + +Attach an array of loaders to post-process a template's render function. This option only exists because Webpack's `enforce: 'post'` option is not preserved and cannot be used to determine whether loaders defined as Rules within a Webpack configuration should be attached after the `template-compiler`. \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index 6225a2aa7..e82e145e5 100644 --- a/lib/index.js +++ b/lib/index.js @@ -85,7 +85,7 @@ module.exports = function (source) { const src = descriptor.template.src || resourcePath const idQuery = `&id=${id}` const scopedQuery = hasScoped ? `&scoped=true` : `` - const attrsQuery = attrsToQuery(descriptor.template.attrs) + const attrsQuery = attrsToQuery(descriptor.template.attrs, 'html') const query = `?vue&type=template${idQuery}${scopedQuery}${attrsQuery}` const request = templateRequest = stringifyRequest(src + query) templateImport = `import { render, staticRenderFns } from ${request}` diff --git a/lib/loaders/pitcher.js b/lib/loaders/pitcher.js index 9ed4ceece..bd32e0a62 100644 --- a/lib/loaders/pitcher.js +++ b/lib/loaders/pitcher.js @@ -79,6 +79,7 @@ module.exports.pitch = function (remainingRequest) { : [] const request = genRequest([ ...cacheLoader, + ...options.templatePostLoaders, templateLoaderPath + `??vue-loader-options`, ...loaders ]) diff --git a/lib/loaders/stylePostLoader.js b/lib/loaders/stylePostLoader.js index de8d09eba..8e1e6d5e7 100644 --- a/lib/loaders/stylePostLoader.js +++ b/lib/loaders/stylePostLoader.js @@ -2,7 +2,7 @@ const qs = require('querystring') const { compileStyle } = require('@vue/component-compiler-utils') // This is a post loader that handles scoped CSS transforms. -// Injected right before css-loader by the global pitcher (../pitch.js) +// Injected right before css-loader by the global pitcher (./pitcher.js) // for any