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

vue-loader@next Build Status Windows Build status

This is the WIP branch of the next version of vue-loader. It uses a fairly different new architecture that is able to apply whatever rules defined in the main webpack config to the language blocks inside a *.vue file.

Example Usage

// webpack.config.js
const path = require('path')
const { VueLoaderPlugin } = require('vue-loader')

module.exports = {
  mode: 'development',
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader'
      },
      // this will apply to both plain .js files
      // AND <script> blocks in vue files
      {
        test: /\.js$/,
        loader: 'babel-loader'
      },
      // this will apply to both plain .css files
      // AND <style> blocks in vue files
      {
        test: /\.css$/,
        use: [
          'vue-style-loader',
          'css-loader'
        ]
      },
      // this will apply to both plain .scss files
      // AND <style lang="scss"> blocks in vue files
      {
        test: /\.scss$/,
        use: [
          'vue-style-loader',
          'css-loader',
          {
            loader: 'sass-loader',
            options: {
              data: '$color: red;'
            }
          }
        ]
      }
    ]
  },
  plugins: [
    // make sure to include the plugin for the magic
    new VueLoaderPlugin()
  ]
}

Notable Breaking Changes

Loader Inference

vue-loader 15 now infers loaders to use for language blocks a bit differently.

Take <style lang="less"> as an example: in v14 and below, it will attempt to load the block with less-loader, and implicitly chains css-loader and vue-style-loader after it, all using inline loader strings.

In v15, <style lang="less"> will behave as if it's an actual *.less file being loaded. So, in order to process it, you need to provide an explicit rule in your main webpack config:

{
  module: {
    rules: [
      // ...other rules
      {
        test: /\.less$/,
        use: [
          'vue-style-loader',
          'css-loader',
          'less-loader'
        ]
      }
    ]
  }
}

The benefit is that this same rule also applies to plain *.less imports from JavaScript, and you can configure options for these loaders anyway you want. In v14 and below, if you want to provide custom options to an inferred loader, you'd have to duplicate it under vue-loader's own loaders option. In v15 it is no longer necessary.

v15 also allows using non-serializable options for loaders, which was not possible in previous versions.

Template Preprocessing

v14 and below uses consolidate to compile <template lang="xxx">. v15 now applies preprocessing for them using webpack loaders instead.

Note that some template loaders such as pug-loader exports a compiled templating function instead of plain HTML. In order to pass the correct content to Vue's template compiler, you must use a loader that outputs plain HTML instead. For example, to support <template lang="pug">, you can use pug-plain-loader:

{
  module: {
    rules: [
      {
        test: /\.pug$/,
        loader: 'pug-plain-loader'
      }
    ]
  }
}

If you also intend to use it to import .pug files as HTML strings in JavaScript, you will need to chain raw-loader after the preprocessing loader. Note however adding raw-loader would break the usage in Vue components, so you need to have two rules, one of them targeting Vue files using a resourceQuery, the other one (fallback) targeting JavaScript imports:

{
  module: {
    rules: [
      {
        test: /\.pug$/,
        oneOf: [
          // this applies to <template lang="pug"> in Vue components
          {
            resourceQuery: /^\?vue/,
            use: ['pug-plain-loader']
          },
          // this applies to pug imports inside JavaScript
          {
            use: ['raw-loader', 'pug-plain-loader']
          }
        ]
      }
    ]
  }
}

Style Injection

Client-side style injection now injects all styles upfront to ensure consistent behavior between development and extracted mode.

Note the injection order is still not guaranteed, so you should avoid writing CSS that relies on insertion order.

PostCSS

vue-loader no longer auto applies PostCSS transforms. To use PostCSS, configure postcss-loader the same way you would for normal CSS files.

CSS Modules

CSS Modules now need to be explicitly configured via css-loader options. The module attribute on <style> tags is still needed for locals injection into the component.

The good news is that you can now configure localIdentName in one place:

{
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          {
            loader: 'vue-style-loader'
          },
          {
            loader: 'css-loader',
            options: {
              modules: true,
              localIdentName: '[local]_[hash:base64:8]'
            }
          }
        ]
      }
    ]
  }
}

If you only want to use CSS Modules in some of your Vue components, you can use a oneOf rule and check for the module string in resourceQuery:

{
  test: /\.css$/,
  oneOf: [
    // this matches <style module>
    {
      resourceQuery: /module/,
      use: [
        'vue-style-loader',
        {
          loader: 'css-loader',
          options: {
            modules: true,
            localIdentName: '[local]_[hash:base64:5]'
          }
        }
      ]
    },
    // this matches plain <style> or <style scoped>
    {
      use: [
        'vue-style-loader',
        'css-loader'
      ]
    }
  ]
}

CSS Extraction

Works the same way as you'd configure it for normal CSS. Example usage with mini-css-extract-plugin:

{
  module: {
    rules: [
      {
        test: /\.vue$/,
        use: 'vue-loader'
      },
      {
        test: /\.css$/,
        // or ExtractTextWebpackPlugin.extract(...)
        use: [
          MiniCssExtractPlugin.loader,
          'css-loader'
        ]
      }
    ]
  },
  plugins: [
    new MiniCssExtractPlugin({
      filename: 'output.css'
    })
  ]
}

Options Deprecation

The following options have been deprecated and should be configured using normal webpack module rules:

  • loader
  • preLoaders
  • postLoaders
  • postcss
  • cssSourceMap
  • buble
  • extractCSS
  • template

The following options have been deprecated and should be configured using the new compilerOptions option:

  • preserveWhitespace (use compilerOptions.preserveWhitespace)
  • compilerModules (use compilerOptions.modules)
  • compilerDirectives (use compilerOptions.directives)

The following option has been renamed:

  • transformToRequire (now renamed to transformAssetUrls)

The following option has been changed to resourceQuery:

  • shadowMode (now use inline resource queries, e.g. foo.vue?shadow)

New Complete Options List

  • compiler
  • compilerOptions
  • transpileOptions
  • transformAssetUrls
  • optimizeSSR
  • hotReload
  • productionMode

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 (1)
Downloads
Total 64
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (5)
Dev Dependencies (34)

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