Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
vue-template-loader
Advanced tools
Vue.js 2.0 template loader for webpack
This loader is just pre-compile a template by using vue-template-compiler and provide a function that can inject render function to a component options object.
In most cases, you should use vue-loader.
Just add a loader option for vue-template-loader to your webpack configuration.
module.exports = {
module: {
rules: [
{ test: /\.html$/, use: 'vue-template-loader' }
]
}
}
You can transform an asset path in template to require
expression that the webpack can handle. For example, if you would like to process image file specified on src
attributes of <img>
element, you should set transformToRequire
option.
module.exports = {
module: {
rules: [
{
test: /\.html$/,
loader: 'vue-template-loader',
options: {
transformToRequire: {
// The key should be element name,
// the value should be attribute name or its array
img: 'src'
}
}
},
// Make sure to add the loader that can process the asset files
{
test: /\.(png|jpg)/,
loader: 'file-loader',
options: {
// ...
}
}
]
}
}
You need to specify scoped flag and loaders for style files such as style-loader
and css-loader
. Note that they must be enforce: post
to inject scope id into styles before they are processed by them.
module.exports = {
module: {
rules: [
{
test: /\.html$/,
loader: 'vue-template-loader',
options: {
scoped: true // add `scoped` flag
}
},
{
enforce: 'post', // required
test: /\.css$/,
use: ['style-loader', 'css-loader']
}
]
}
}
All what you have to do is enable modules
flag of css-loader
. vue-template-loader will add $style
property and you can use hashed classes through it.
module.exports = {
module: {
rules: [
{
test: /\.html$/,
use: 'vue-template-loader'
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader?modules'] // Enable CSS Modules
}
]
}
}
Write a template of Vue component as html.
<!-- app.html -->
<div class="app">
<p>{{ text }}</p>
<button type="button" @click="log">Log</button>
</div>
Import it as a function and pass a component option to the function. If you also would like to load a style file, add style
query and specify the style file path.
// app.js
import withRender from './app.html?style=./app.css'
export default withRender({
data () {
return {
text: 'Example text'
}
},
methods: {
log () {
console.log('output log')
}
}
})
You can use decorator syntax for any class style components.
import Vue from 'vue'
import Component from 'vue-class-component'
import WithRender from './app.html'
@WithRender
@Component
export default class App extends Vue {
text = 'Example text'
log () {
console.log('output log')
}
}
If you use this loader with TypeScript, make sure to add a declaration file for html file into your project.
declare module '*.html' {
import Vue = require('vue')
interface WithRender {
<V extends Vue>(options: Vue.ComponentOptions<V>): Vue.ComponentOptions<V>
<V extends typeof Vue>(component: V): V
}
const withRender: WithRender
export = withRender
}
MIT
FAQs
Vue.js 2.0 template loader for webpack
The npm package vue-template-loader receives a total of 2,363 weekly downloads. As such, vue-template-loader popularity was classified as popular.
We found that vue-template-loader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.