I am using Vue CLI 3 with built in Webpack and I am trying to use index.pug
as source index template instead of default HTML. I want to output a index.pug
file as a result of webpack process for further population by Node server with dynamic data.
Here is my vue.config.js
:
'use strict'
const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const resolve = (dir) => {
return path.join(__dirname, '.', dir)
}
module.exports = {
outputDir: path.resolve(__dirname, 'server/app'),
baseUrl: process.env.ENV === 'production' ? process.env.VUE_APP_CDN_URL + 'app/' : '/',
configureWebpack: {
context: path.resolve(__dirname, './'),
entry: {
app: './client/main.js'
},
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
'vue$': 'vue/dist/vue.esm.js',
'@': resolve('client')
}
},
plugins: [
new HtmlWebpackPlugin({
template: './public/index.pug',
inject: true
}),
]
},
chainWebpack: config => {
config.module
.rule('pug')
.test(/\.pug$/)
.use('pug-loader')
.loader('pug-loader')
}
}
Unfortunately, above fails with:
Error: Child compilation failed:
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
Some thoughts and assumptions:
configureWebpack
seems to be setup correctly (https://cli.vuejs.org/guide/webpack.html#chaining-advanced)- HtmlWebpackPlugin might not be the plugin to use since its purpose is to generate HTML file as output, but I cant even get that to complete successfully
Unfortunately, there is not a whole lot of documentation online on this topic, so hoping for help here. Thanks.