All Projects → vuejs → Vue Loader

vuejs / Vue Loader

Licence: mit
📦 Webpack loader for Vue.js components

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects
Vue
7211 projects
HTML
75241 projects

Projects that are alternatives of or similar to Vue Loader

Reactly Starter Kit
Deployable React + Webpack 2 starter kit
Stars: ✭ 122 (-97.45%)
Mutual labels:  webpack, hot-reload
Angular Electron
Ultra-fast bootstrapping with Angular and Electron (Typescript + SASS + Hot Reload) 🚤
Stars: ✭ 4,914 (+2.85%)
Mutual labels:  webpack, hot-reload
Hot Reload All The Things
Starter project for HMR with backend routes and server/client-side react.
Stars: ✭ 127 (-97.34%)
Mutual labels:  webpack, hot-reload
Node Hot Loader
Hot module replacement (hot reload) for Node.js applications. Develop without server restarting.
Stars: ✭ 111 (-97.68%)
Mutual labels:  webpack, hot-reload
React Webpack Boilerplate
Minimalistic ES6+ React boilerplate with Hot Reloading using Webpack 4 and Babel 7
Stars: ✭ 336 (-92.97%)
Mutual labels:  webpack, hot-reload
Sass Vars Loader
Use Sass variables defined in Webpack config or in external Javascript or JSON files
Stars: ✭ 112 (-97.66%)
Mutual labels:  webpack, hot-reload
Awesome Chrome Extension Boilerplate
Use react + typescript + webpack to enhance your chrome extension development experience
Stars: ✭ 146 (-96.94%)
Mutual labels:  webpack, hot-reload
Webpack Dev Server
Serves a webpack app. Updates the browser on changes. Documentation https://webpack.js.org/configuration/dev-server/.
Stars: ✭ 7,250 (+51.74%)
Mutual labels:  webpack, hot-reload
React Redux Universal Boilerplate
An Universal ReactJS/Redux Boilerplate
Stars: ✭ 165 (-96.55%)
Mutual labels:  webpack, hot-reload
Template Rwb
A full-featured Webpack setup with hot-reload
Stars: ✭ 165 (-96.55%)
Mutual labels:  webpack, hot-reload
Molecule
⚛️ – :atom: – ⚛️ Boilerplate for cross platform web/native react apps with electron.
Stars: ✭ 95 (-98.01%)
Mutual labels:  webpack, hot-reload
Angular Hmr
🔥 Angular Hot Module Replacement for Hot Module Reloading
Stars: ✭ 490 (-89.74%)
Mutual labels:  webpack, hot-reload
Extracted Loader
It reloads extracted stylesheets extracted with ExtractTextPlugin
Stars: ✭ 67 (-98.6%)
Mutual labels:  webpack, hot-reload
Universal React Redux
🧐 A sensible universal starter kit for React + Redux
Stars: ✭ 112 (-97.66%)
Mutual labels:  webpack, hot-reload
React Pwa Webpack Starter
Boilerplate to build a React PWA with Webpack + Workbox
Stars: ✭ 38 (-99.2%)
Mutual labels:  webpack, hot-reload
React Pages Boilerplate
Deliver react + react-router application to gh-pages
Stars: ✭ 134 (-97.2%)
Mutual labels:  webpack, hot-reload
Svelte Redux Shopping Cart
Example Shopping Cart App using Svelte, Redux, and Webpack
Stars: ✭ 13 (-99.73%)
Mutual labels:  webpack, hot-reload
Reactql
Universal React+GraphQL starter kit: React 16, Apollo 2, MobX, Emotion, Webpack 4, GraphQL Code Generator, React Router 4, PostCSS, SSR
Stars: ✭ 1,833 (-61.64%)
Mutual labels:  webpack, hot-reload
Vueniverse
Full stack, user based, PWA, Vue template.
Stars: ✭ 339 (-92.9%)
Mutual labels:  webpack, hot-reload
Webpack Pwa Manifest
Progressive Web App Manifest Generator for Webpack, with auto icon resizing and fingerprinting support.
Stars: ✭ 447 (-90.64%)
Mutual labels:  webpack, hot-reload

vue-loader ci

webpack loader for Vue Single-File Components

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'
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].