vue-loader (original) (raw)
17.3.1 • Public • Published 2 years ago
vue-loader 
webpack loader for Vue Single-File Components
v17.2.1+ Only Options
experimentalInlineMatchResource: boolean
: enable Inline matchResource for rule matching for vue-loader.
v16+ Only Options
reactivityTransform: boolean
: enable Vue Reactivity Transform (SFCs only).refSugar: boolean
: removed. usereactivityTransform
instead.customElement: boolean | RegExp
: enable custom elements mode. An SFC loaded in custom elements mode inlines its<style>
tags as strings under the component'sstyles
option. When used withdefineCustomElement
from Vue core, the styles will be injected into the custom element's shadow root.- Default is
/\.ce\.vue$/
- Setting to
true
will process all.vue
files in custom element mode.
- Default is
enableTsInTemplate: boolean
(16.8+): allow TS expressions in templates when<script>
haslang="ts"
. Defaults totrue
.- When used with
ts-loader
, due tots-loader
's cache invalidation behavior, it sometimes prevents the template from being hot-reloaded in isolation, causing the component to reload despite only the template being edited. If this is annoying, you can set this option tofalse
(and avoid using TS expressions in templates). - Alternatively, leave this option on (by default) and use esbuild-loader to transpile TS instead, which doesn't suffer from this problem (it's also a lot faster). However, do note you will need to rely on TS type checking from other sources (e.g. IDE or
vue-tsc
).
- When used with
What is Vue Loader?
vue-loader
is a loader for webpack that allows you to author Vue components in a format called Single-File Components (SFCs):
There are many cool features provided by vue-loader
:
- Allows using other webpack loaders for each part of a Vue component, for example Sass for
<style>
and Pug for<template>
; - Allows custom blocks in a
.vue
file that can have custom loader chains applied to them; - Treat static assets referenced in
<style>
and<template>
as module dependencies and handle them with webpack loaders; - Simulate scoped CSS for each component;
- 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:
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:
// code returned from the main loader for 'source.vue'
// import the block
import render from 'source.vue?vue&type=template'
// import the