Skip to content

Commit

Permalink
feat: enable template compile caching
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed May 22, 2018
1 parent 11824a2 commit 28e0fd3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,10 @@ Force production mode, which prohibits the loader from emitting code (e.g. hot-r
- default: `false`

Compiled the component for usage inside Shadow DOM. In this mode, the styles of the component will be injected into `this.$root.$options.shadowRoot` instead of the document head.

## cacheDirectory / cacheIdentifier

- type: `string`
- default: `undefined`

When both options are specified, enables file-system-based template compilation caching (requires `cache-loader` to be installed in the same project).
8 changes: 7 additions & 1 deletion lib/loaders/pitcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ module.exports = code => code
// This pitching loader is responsible for intercepting all vue block requests
// and transform it into appropriate requests.
module.exports.pitch = function (remainingRequest) {
const options = loaderUtils.getOptions(this)
const { cacheDirectory, cacheIdentifier } = options
const query = qs.parse(this.resourceQuery.slice(1))

// if this is a language block request, remove eslint-loader to avoid
Expand Down Expand Up @@ -67,9 +69,13 @@ module.exports.pitch = function (remainingRequest) {
}
}

// for templates: inject the template compiler
// for templates: inject the template compiler & optional cache
if (query.type === `template`) {
const cacheLoader = cacheDirectory && cacheIdentifier
? [`cache-loader?${JSON.stringify(options)}`]
: []
const request = genRequest([
...cacheLoader,
templateLoaderPath + `??vue-loader-options`,
...loaders
])
Expand Down
4 changes: 4 additions & 0 deletions lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ class VueLoaderPlugin {
resourceQuery: query => {
const parsed = qs.parse(query.slice(1))
return parsed.vue != null
},
options: {
cacheDirectory: vueLoaderUse.options.cacheDirectory,
cacheIdentifier: vueLoaderUse.options.cacheIdentifier
}
}

Expand Down

0 comments on commit 28e0fd3

Please sign in to comment.