There are many cool features provided by
- ES2015 enabled by default;
- Allows using other Webpack loaders for each part of a Vue component, for example SASS for
<style>and Jade for
- Allows custom sections in a .vue file that can have custom loader chains applied to them
- Treat static assets referenced in
<template>as module dependencies and handle them with Webpack loaders;
- Can simulate scoped CSS for each component;
- Supports component 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.
What is Webpack?
If you are already familiar with Webpack, feel free to skip the following explanation. But for those of you who are new to Webpack, here's a quick intro:
Webpack is a module bundler. It takes a bunch of files, treating each as a module, figuring out the dependencies between them, and bundle them into static assets that are ready for deployment.
For a basic example, imagine we have a bunch of CommonJS modules. They cannot run directly inside the browser, so we need to "bundle" them into a single file that can be included via a
<script> tag. Webpack can follow the dependencies of the
require() calls and do that for us.
But Webpack can do more than that. With "loaders", we can teach Webpack to transform all types of files in any way we want before outputting the final bundle. Some examples include:
- Transpile ES2015, CoffeeScript or TypeScript modules into plain ES5 CommonJS modules;
- Optionally you can pipe the source code through a linter before doing the compilation;
- Process an image file referenced in HTML or CSS, moved it to the desired destination based on the path configurations, and naming it using its md5 hash.
Webpack is so powerful that when you understand how it works, it can dramatically improve your front-end workflow. Its primary drawback is its verbose and complex configuration; but with this guide you should be able to find solutions for most common issues when using Webpack with Vue.js and