Gathering detailed insights and metrics for vue-loader
Gathering detailed insights and metrics for vue-loader
Gathering detailed insights and metrics for vue-loader
Gathering detailed insights and metrics for vue-loader
npm install vue-loader
57.3
Supply Chain
70.7
Quality
79.7
Maintenance
100
Vulnerability
99.6
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
4,990 Stars
254 Commits
915 Forks
114 Watching
14 Branches
86 Contributors
Updated on 25 Nov 2024
TypeScript (91.35%)
JavaScript (6.67%)
Vue (1.87%)
HTML (0.1%)
Cumulative downloads
Total Downloads
Last day
-5.9%
505,493
Compared to previous day
Last week
-0.3%
2,566,507
Compared to previous week
Last month
15.4%
10,925,327
Compared to previous month
Last year
-16.1%
126,966,613
Compared to previous year
1
46
webpack loader for Vue Single-File Components
experimentalInlineMatchResource: boolean
: enable Inline matchResource for rule matching for vue-loader.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.
/\.ce\.vue$/
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
).
vue-loader
is a loader for webpack that allows you to author Vue components in a format called Single-File Components (SFCs):
1<template> 2 <div class="example">{{ msg }}</div> 3</template> 4 5<script> 6export default { 7 data() { 8 return { 9 msg: 'Hello world!', 10 } 11 }, 12} 13</script> 14 15<style> 16.example { 17 color: red; 18} 19</style>
There are many cool features provided by vue-loader
:
<style>
and Pug for <template>
;.vue
file that can have custom loader chains applied to them;<style>
and <template>
as module dependencies and handle them with webpack loaders;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.
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:
1// code returned from the main loader for 'source.vue' 2 3// import the <template> block 4import render from 'source.vue?vue&type=template' 5// import the <script> block 6import script from 'source.vue?vue&type=script' 7export * from 'source.vue?vue&type=script' 8// import <style> blocks 9import 'source.vue?vue&type=style&index=1' 10 11script.render = render 12export default script
Notice how the code is importing source.vue
itself, but with different request queries for each block.
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
1import script from 'source.vue?vue&type=script'
Will expand to:
1import 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:
1<style scoped lang="scss">
Will be returned by vue-loader
as:
1import 'source.vue?vue&type=style&index=1&scoped&lang=scss'
And webpack will expand it to:
1import 'style-loader!css-loader!sass-loader!vue-loader!source.vue?vue&type=style&index=1&scoped&lang=scss'
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.
For the <script>
block, this is pretty much it. For <template>
and <style>
blocks though, a few extra tasks need to be performed:
<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:
1// <template lang="pug">
2import 'vue-loader/template-loader!pug-loader!source.vue?vue&type=template'
3
4// <style scoped lang="scss">
5import 'style-loader!vue-loader/style-post-loader!css-loader!sass-loader!vue-loader!source.vue?vue&type=style&index=1&scoped&lang=scss'
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 6/30 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
63 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn Morevue-ts-loader
TypeScript loader for vue-loader
vux-loader
extended loader for vue-loader
@esm.sh/vue-loader
A `.vue` loader for esm.sh services.
vue-webpack-gettext
Extract and compile translations with vue-gettext and vue-loader, i.e. for .vue files with <template lang='pug'></template>