How to configure the plugin for both Vue and non-Vue usage? #16
-
For the case when we need the Vue template and for the case when we just need to import pre-processed by Pug HTML code to JS/TS file, different pre-processing is required. I don't know the details about this pre-processings, but before use pug-loader, the working setup was: {
// ...
module: {
rules: [
{
test: /\.pug$/u,
oneOf: [
// For the Vue Singe File Component
{
resourceQuery: /^\?vue/u,
use: [ "pug-plain-loader" ]
},
// For other cases
{
use: [
{
loader: "html-loader",
options: {
/* [ Theory ] Without this option, all capital cases tags (invalid HTML5 vue normal for the Vue
* templates loaded externally) will be converted to lower cased.
* [ Reference ] https://stackoverflow.com/q/63164597/4818123 */
minimize: {
caseSensitive: true
}
}
},
"pug-html-loader"
]
}
]
}
]
}
} What it the equivalent configuration for pug-plugin and which loaders will become redundant after migration? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
Setup for VueChange your const { defineConfig } = require('@vue/cli-service');
module.exports = defineConfig({
transpileDependencies: true,
chainWebpack: (config) => {
const pugRule = config.module.rule('pug');
// IMPORTANT: clear all existing pug loader settings
// defaults pug loader in Vue is `pug-plain-loader`
pugRule.uses.clear();
pugRule.oneOfs.clear();
},
configureWebpack: {
module: {
rules: [
{
test: /\.pug$/,
oneOf: [
// allow <template lang="pug"> in Vue components
{
resourceQuery: /^\?vue/u,
loader: '@webdiscus/pug-loader',
options: {
method: 'html', // render Pug into pure HTML string
},
},
// allow import of Pug in JS/TS and for "other cases", if a file hasn't the extension `.vue`
{
loader: '@webdiscus/pug-loader',
options: {
method: 'compile', // compile Pug into template function
},
},
],
},
],
},
},
});
Usage Pug in VueAn indent for Pug code in Vue template is allowed: <template lang='pug'>
h1 Hello Pug!
</template> Usage Pug in JS/TS with
|
Beta Was this translation helpful? Give feedback.
-
The Keep your Webpack config clear and clean. The For Vue, the |
Beta Was this translation helpful? Give feedback.
Setup for Vue
Change your
vue.config.js
according to the following minimal configuration: