1.0.1 • Published 4 years ago
attribute-template-loader v1.0.1
attribute-template-loader
Webpack Loader. Adds a template with attribute variables.
Install
$ npm install --save-dev attribute-template-loader
Usage
// Webpack config
const path = require('path');
module.exports = {
module: {
rules: [
{
test: /\.pug$/, // Pug for example
loader: 'attribute-template-loader',
options: {
list:[
{
tag: 'include',
template: path.join(__dirname, '../utils/template-for-svg.tmpl')
},
{
tag: 'import',
template: `
<svg class='$[class]'>
<use xlink:href='$[name]'></use>
</svg>`
}
]
}
}
]
}
}
// template-for-svg.tmpl
<svg class="$[className]">
<use xlink:href="$[customName]"></use>
</svg>
// Your source file
include(className='your-class-name', customName='your-name')
import(class='your-second-class-name', name='#your-second-name')
// Your output
<svg class="your-class-name"><use xlink:href="your-name"></use></svg>
<svg class="your-second-class-name"><use xlink:href="#your-second-name"></use></svg>
License
MIT