vue-loader
Vue single-file component loader for Webpack
Last updated 6 years ago by yyx990803 .
MIT · Bugs · Original npm · Tarball · package.json
$ npm install vue-loader 
SYNC missed versions from official npm registry.

vue-loader ci

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. use reactivityTransform instead.

  • customElement: boolean | RegExp: enable custom elements mode. An SFC loaded in custom elements mode inlines its <style> tags as strings under the component's styles option. When used with defineCustomElement 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.
  • enableTsInTemplate: boolean (16.8+): allow TS expressions in templates when <script> has lang="ts". Defaults to true.

    • When used with ts-loader, due to ts-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 to false (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).

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):

<template>
  <div class="example">{{ msg }}</div>
</template>

<script>
export default {
  data() {
    return {
      msg: 'Hello world!',
    }
  },
}
</script>

<style>
.example {
  color: red;
}
</style>

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:

  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:

    // code returned from the main loader for 'source.vue'
    
    // import the <template> block
    import render from 'source.vue?vue&type=template'
    // import the <script> block
    import script from 'source.vue?vue&type=script'
    export * from 'source.vue?vue&type=script'
    // import <style> blocks
    import 'source.vue?vue&type=style&index=1'
    
    script.render = render
    export default script
    

    Notice how the code is importing source.vue itself, but with different request queries for each block.

  2. We want the content in script block to be treated like .js files (and if it's <script lang="ts">, we want to to be treated like .ts files). Same for other language blocks. So we want webpack to apply any configured module rules that matches .js also to requests that look like source.vue?vue&type=script. This is what VueLoaderPlugin (src/plugins.ts) does: for each module rule in the webpack config, it creates a modified clone that targets corresponding Vue language block requests.

    Suppose we have configured babel-loader for all *.js files. That rule will be cloned and applied to Vue SFC <script> blocks as well. Internally to webpack, a request like

    import script from 'source.vue?vue&type=script'
    

    Will expand to:

    import script from 'babel-loader!vue-loader!source.vue?vue&type=script'
    

    Notice the vue-loader is also matched because vue-loader are applied to .vue files.

    Similarly, if you have configured style-loader + css-loader + sass-loader for *.scss files:

    <style scoped lang="scss">
    

    Will be returned by vue-loader as:

    import 'source.vue?vue&type=style&index=1&scoped&lang=scss'
    

    And webpack will expand it to:

    import 'style-loader!css-loader!sass-loader!vue-loader!source.vue?vue&type=style&index=1&scoped&lang=scss'
    
  3. When processing the expanded requests, the main vue-loader will get invoked again. This time though, the loader notices that the request has queries and is targeting a specific block only. So it selects (src/select.ts) the inner content of the target block and passes it on to the loaders matched after it.

  4. For the <script> block, this is pretty much it. For <template> and <style> blocks though, a few extra tasks need to be performed:

    • We need to compile the template using the Vue template compiler;
    • We need to post-process the CSS in <style scoped> blocks, after css-loader but before style-loader.

    Technically, these are additional loaders (src/templateLoader.ts and src/stylePostLoader.ts) that need to be injected into the expanded loader chain. It would be very complicated if the end users have to configure this themselves, so VueLoaderPlugin also injects a global Pitching Loader (src/pitcher.ts) that intercepts Vue <template> and <style> requests and injects the necessary loaders. The final requests look like the following:

    // <template lang="pug">
    import 'vue-loader/template-loader!pug-loader!source.vue?vue&type=template'
    
    // <style scoped lang="scss">
    import 'style-loader!vue-loader/style-post-loader!css-loader!sass-loader!vue-loader!source.vue?vue&type=style&index=1&scoped&lang=scss'
    

Current Tags

  • 17.1.0-beta.0                                ...           beta (2 years ago)
  • 17.4.2                                ...           latest (a year ago)
  • 15.11.1                                ...           legacy (a year ago)
  • 17.3.1                                ...           next (a year ago)
  • 15.10.0-beta.6                                ...           v15-beta (3 years ago)

304 Versions

  • 17.4.2                                ...           a year ago
  • 17.4.1                                ...           a year ago
  • 17.4.0                                ...           a year ago
  • 17.3.1                                ...           a year ago
  • 15.11.1                                ...           a year ago
  • 15.11.0                                ...           a year ago
  • 17.3.0                                ...           a year ago
  • 15.10.2                                ...           a year ago
  • 17.2.2                                ...           2 years ago
  • 17.2.1                                ...           2 years ago
  • 17.2.0                                ...           2 years ago
  • 17.1.2                                ...           2 years ago
  • 17.1.1                                ...           2 years ago
  • 17.1.0                                ...           2 years ago
  • 17.1.0-beta.0                                ...           2 years ago
  • 15.10.1                                ...           2 years ago
  • 17.0.1                                ...           2 years ago
  • 15.10.0                                ...           2 years ago
  • 15.10.0-beta.6                                ...           3 years ago
  • 15.10.0-beta.5                                ...           3 years ago
  • 15.10.0-beta.4                                ...           3 years ago
  • 15.10.0-beta.3                                ...           3 years ago
  • 15.10.0-beta.2                                ...           3 years ago
  • 15.10.0-beta.1                                ...           3 years ago
  • 17.0.0                                ...           3 years ago
  • 16.8.3                                ...           3 years ago
  • 16.8.2                                ...           3 years ago
  • 16.8.1                                ...           3 years ago
  • 16.8.0                                ...           3 years ago
  • 16.7.1                                ...           3 years ago
  • 16.7.0                                ...           3 years ago
  • 16.6.0                                ...           3 years ago
  • 16.5.0                                ...           3 years ago
  • 15.9.8                                ...           3 years ago
  • 16.4.1                                ...           3 years ago
  • 16.4.0                                ...           3 years ago
  • 16.3.3                                ...           3 years ago
  • 16.3.2                                ...           3 years ago
  • 16.3.1                                ...           3 years ago
  • 16.3.0                                ...           3 years ago
  • 15.9.7                                ...           4 years ago
  • 16.2.0                                ...           4 years ago
  • 15.9.6                                ...           4 years ago
  • 16.1.2                                ...           4 years ago
  • 16.1.1                                ...           4 years ago
  • 16.1.0                                ...           4 years ago
  • 16.0.0                                ...           4 years ago
  • 16.0.0-rc.2                                ...           4 years ago
  • 16.0.0-rc.1                                ...           4 years ago
  • 16.0.0-rc.0                                ...           4 years ago
  • 16.0.0-beta.10                                ...           4 years ago
  • 15.9.5                                ...           4 years ago
  • 15.9.4                                ...           4 years ago
  • 16.0.0-beta.9                                ...           4 years ago
  • 16.0.0-beta.8                                ...           4 years ago
  • 16.0.0-beta.7                                ...           4 years ago
  • 16.0.0-beta.6                                ...           4 years ago
  • 16.0.0-beta.5                                ...           4 years ago
  • 16.0.0-beta.4                                ...           5 years ago
  • 15.9.3                                ...           5 years ago
  • 16.0.0-beta.3                                ...           5 years ago
  • 16.0.0-beta.2                                ...           5 years ago
  • 16.0.0-beta.1                                ...           5 years ago
  • 15.9.2                                ...           5 years ago
  • 15.9.1                                ...           5 years ago
  • 15.9.0                                ...           5 years ago
  • 16.0.0-alpha.3                                ...           5 years ago
  • 16.0.0-alpha.2                                ...           5 years ago
  • 16.0.0-alpha.1                                ...           5 years ago
  • 16.0.0-alpha.0                                ...           5 years ago
  • 15.8.3                                ...           5 years ago
  • 15.8.2                                ...           5 years ago
  • 15.8.1                                ...           5 years ago
  • 15.8.0                                ...           5 years ago
  • 15.7.2                                ...           5 years ago
  • 15.7.1                                ...           5 years ago
  • 15.7.0                                ...           6 years ago
  • 15.6.4                                ...           6 years ago
  • 15.6.3                                ...           6 years ago
  • 14.2.4                                ...           6 years ago
  • 15.6.2                                ...           6 years ago
  • 15.6.1                                ...           6 years ago
  • 15.6.0                                ...           6 years ago
  • 15.5.1                                ...           6 years ago
  • 15.5.0                                ...           6 years ago
  • 15.4.2                                ...           6 years ago
  • 15.4.1                                ...           6 years ago
  • 13.7.3                                ...           6 years ago
  • 15.4.0                                ...           6 years ago
  • 15.3.0                                ...           6 years ago
  • 15.2.7                                ...           6 years ago
  • 15.2.6                                ...           6 years ago
  • 15.2.5                                ...           6 years ago
  • 15.2.4                                ...           7 years ago
  • 15.2.3                                ...           7 years ago
  • 15.2.2                                ...           7 years ago
  • 13.7.2                                ...           7 years ago
  • 14.2.3                                ...           7 years ago
  • 15.2.1                                ...           7 years ago
  • 15.2.0                                ...           7 years ago
  • 15.1.0                                ...           7 years ago
  • 15.0.12                                ...           7 years ago
  • 15.0.11                                ...           7 years ago
  • 15.0.10                                ...           7 years ago
  • 15.0.9                                ...           7 years ago
  • 15.0.8                                ...           7 years ago
  • 15.0.7                                ...           7 years ago
  • 15.0.6                                ...           7 years ago
  • 15.0.5                                ...           7 years ago
  • 15.0.4                                ...           7 years ago
  • 15.0.3                                ...           7 years ago
  • 15.0.2                                ...           7 years ago
  • 15.0.1                                ...           7 years ago
  • 15.0.0                                ...           7 years ago
  • 15.0.0-rc.2                                ...           7 years ago
  • 15.0.0-rc.1                                ...           7 years ago
  • 15.0.0-beta.7                                ...           7 years ago
  • 15.0.0-beta.6                                ...           7 years ago
  • 15.0.0-beta.5                                ...           7 years ago
  • 15.0.0-beta.4                                ...           7 years ago
  • 15.0.0-beta.3                                ...           7 years ago
  • 14.2.2                                ...           7 years ago
  • 15.0.0-beta.2                                ...           7 years ago
  • 15.0.0-beta.1                                ...           7 years ago
  • 14.2.1                                ...           7 years ago
  • 14.2.0                                ...           7 years ago
  • 8.7.1                                ...           7 years ago
  • 14.1.1                                ...           7 years ago
  • 14.1.0                                ...           7 years ago
  • 14.0.3                                ...           7 years ago
  • 14.0.2                                ...           7 years ago
  • 14.0.1                                ...           7 years ago
  • 13.7.1                                ...           7 years ago
  • 14.0.0                                ...           7 years ago
  • 13.7.0                                ...           7 years ago
  • 13.6.2                                ...           7 years ago
  • 13.6.1                                ...           7 years ago
  • 13.6.0                                ...           7 years ago
  • 13.5.1                                ...           7 years ago
  • 13.5.0                                ...           7 years ago
  • 13.4.0                                ...           7 years ago
  • 13.3.0                                ...           7 years ago
  • 13.2.1                                ...           7 years ago
  • 13.2.0 [deprecated]           ...           7 years ago
  • 13.1.0                                ...           7 years ago
  • 13.0.5                                ...           7 years ago
  • 13.0.4                                ...           7 years ago
  • 13.0.3                                ...           7 years ago
  • 12.2.2                                ...           7 years ago
  • 13.0.2                                ...           7 years ago
  • 13.0.1                                ...           7 years ago
  • 13.0.0                                ...           7 years ago
  • 12.2.1                                ...           8 years ago
  • 12.2.0                                ...           8 years ago
  • 12.1.1                                ...           8 years ago
  • 12.1.0                                ...           8 years ago
  • 12.0.4                                ...           8 years ago
  • 12.0.3                                ...           8 years ago
  • 12.0.2                                ...           8 years ago
  • 12.0.1 [deprecated]           ...           8 years ago
  • 12.0.0                                ...           8 years ago
  • 11.3.4                                ...           8 years ago
  • 11.3.3                                ...           8 years ago
  • 11.3.2                                ...           8 years ago
  • 11.3.1                                ...           8 years ago
  • 11.3.0                                ...           8 years ago
  • 11.2.0                                ...           8 years ago
  • 11.1.4                                ...           8 years ago
  • 11.1.3                                ...           8 years ago
  • 11.1.2                                ...           8 years ago
  • 11.1.1                                ...           8 years ago
  • 11.1.0                                ...           8 years ago
  • 11.0.0                                ...           8 years ago
  • 8.7.0                                ...           8 years ago
  • 10.3.0                                ...           8 years ago
  • 10.2.4                                ...           8 years ago
  • 10.2.3                                ...           8 years ago
  • 10.2.2                                ...           8 years ago
  • 10.2.1                                ...           8 years ago
  • 10.2.0                                ...           8 years ago
  • 10.1.2                                ...           8 years ago
  • 10.1.1                                ...           8 years ago
  • 8.6.1                                ...           8 years ago
  • 8.6.0                                ...           8 years ago
  • 10.1.0                                ...           8 years ago
  • 10.0.4                                ...           8 years ago
  • 10.0.3                                ...           8 years ago
  • 10.0.2                                ...           8 years ago
  • 10.0.1                                ...           8 years ago
  • 10.0.0                                ...           8 years ago
  • 9.9.5                                ...           8 years ago
  • 9.9.4                                ...           8 years ago
  • 9.9.3                                ...           8 years ago
  • 9.9.2                                ...           8 years ago
  • 9.9.1                                ...           8 years ago
  • 9.9.0                                ...           8 years ago
  • 9.8.1                                ...           8 years ago
  • 9.8.0                                ...           8 years ago
  • 9.7.0                                ...           8 years ago
  • 9.6.0                                ...           8 years ago
  • 9.5.3                                ...           8 years ago
  • 9.5.2                                ...           8 years ago
  • 9.5.1                                ...           8 years ago
  • 8.5.4                                ...           8 years ago
  • 9.5.0                                ...           8 years ago
  • 9.4.2                                ...           8 years ago
  • 9.4.1                                ...           8 years ago
  • 9.4.0                                ...           8 years ago
  • 9.3.2                                ...           8 years ago
  • 9.3.1                                ...           8 years ago
  • 9.3.0                                ...           8 years ago
  • 9.2.3                                ...           8 years ago
  • 9.2.2                                ...           8 years ago
  • 9.2.1                                ...           8 years ago
  • 9.2.0                                ...           8 years ago
  • 9.1.3                                ...           8 years ago
  • 9.1.2                                ...           8 years ago
  • 9.1.1                                ...           8 years ago
  • 9.1.0                                ...           8 years ago
  • 8.5.3                                ...           9 years ago
  • 9.0.3                                ...           9 years ago
  • 9.0.2                                ...           9 years ago
  • 9.0.1                                ...           9 years ago
  • 9.0.0                                ...           9 years ago
  • 8.5.2                                ...           9 years ago
  • 8.5.1                                ...           9 years ago
  • 8.5.0                                ...           9 years ago
  • 8.4.0                                ...           9 years ago
  • 8.3.1                                ...           9 years ago
  • 8.3.0                                ...           9 years ago
  • 8.2.3                                ...           9 years ago
  • 8.2.2                                ...           9 years ago
  • 8.2.1                                ...           9 years ago
  • 8.2.0                                ...           9 years ago
  • 8.1.4                                ...           9 years ago
  • 8.1.3                                ...           9 years ago
  • 8.1.2                                ...           9 years ago
  • 8.1.1                                ...           9 years ago
  • 8.1.0                                ...           9 years ago
  • 8.0.5                                ...           9 years ago
  • 8.0.4                                ...           9 years ago
  • 8.0.3                                ...           9 years ago
  • 8.0.2                                ...           9 years ago
  • 7.5.3                                ...           9 years ago
  • 8.0.1                                ...           9 years ago
  • 8.0.0                                ...           9 years ago
  • 7.5.2                                ...           9 years ago
  • 7.5.1                                ...           9 years ago
  • 7.5.0                                ...           9 years ago
  • 7.4.2                                ...           9 years ago
  • 7.4.1                                ...           9 years ago
  • 7.4.0                                ...           9 years ago
  • 7.3.0                                ...           9 years ago
  • 7.2.0                                ...           9 years ago
  • 7.1.8                                ...           9 years ago
  • 7.1.7                                ...           9 years ago
  • 7.1.6                                ...           9 years ago
  • 7.1.5                                ...           9 years ago
  • 7.1.4                                ...           9 years ago
  • 6.1.0                                ...           9 years ago
  • 7.1.3                                ...           9 years ago
  • 7.1.2                                ...           9 years ago
  • 7.1.1                                ...           9 years ago
  • 7.1.0                                ...           9 years ago
  • 7.0.3                                ...           9 years ago
  • 7.0.2                                ...           9 years ago
  • 7.0.1                                ...           9 years ago
  • 7.0.0                                ...           9 years ago
  • 6.0.5                                ...           9 years ago
  • 6.0.4                                ...           9 years ago
  • 6.0.3                                ...           9 years ago
  • 6.0.2                                ...           9 years ago
  • 6.0.1                                ...           9 years ago
  • 6.0.0                                ...           9 years ago
  • 5.0.0                                ...           9 years ago
  • 4.0.10                                ...           9 years ago
  • 4.0.9                                ...           9 years ago
  • 4.0.8                                ...           9 years ago
  • 4.0.7                                ...           9 years ago
  • 4.0.6                                ...           9 years ago
  • 4.0.5                                ...           9 years ago
  • 4.0.4                                ...           9 years ago
  • 4.0.3                                ...           9 years ago
  • 4.0.2                                ...           9 years ago
  • 4.0.1                                ...           9 years ago
  • 4.0.0                                ...           9 years ago
  • 3.0.4                                ...           9 years ago
  • 3.0.3                                ...           9 years ago
  • 3.0.2                                ...           9 years ago
  • 2.1.1                                ...           9 years ago
  • 2.1.0                                ...           9 years ago
  • 2.0.3 [deprecated]           ...           9 years ago
  • 2.0.2 [deprecated]           ...           9 years ago
  • 2.0.1                                ...           10 years ago
  • 2.0.0                                ...           10 years ago
  • 1.1.6                                ...           10 years ago
  • 1.1.5                                ...           10 years ago
  • 1.1.4                                ...           10 years ago
  • 1.1.3                                ...           10 years ago
  • 1.1.2                                ...           10 years ago
  • 1.1.0                                ...           10 years ago
  • 0.3.0                                ...           10 years ago
  • 0.2.0                                ...           10 years ago
  • 0.1.0                                ...           10 years ago
Maintainers (2)
Downloads
Total 64
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (5)
Dev Dependencies (42)

© 2010 - cnpmjs.org x YWFE | Home | YWFE