Answer the question
In order to leave comments, you need to log in
[Webpack] How to extract html from js string?
After execution, html files are created from pug, but in them all html is exported through the js variable, how can I fix this (get html as output)?
Output html file content:
Run with this command:module.exports = "<div class=\"abc\">...</div>";
NODE_ENV=development webpack --config webpack/dev.config.js
'use strict';
const NODE_ENV = process.env.NODE_ENV || 'development';
const webpack = require('webpack');
const path = require('path');
const glob = require('glob');
module.exports = {
mode: NODE_ENV,
entry: {
pug: glob.sync(path.resolve(__dirname, '../src-ng/**/*.pug'))
},
output: {
path: path.resolve(__dirname, "../dist-ng"),
publicPath: "dist/"
},
devtool: "source-map",
module: {
rules: [
{
test: /\.pug$/,
use: [
{ loader: "file-loader", options: { name: "[name].html" } },
{ loader: "html-loader" },
{
loader: 'pug-html-loader',
options: {
basedir: path.resolve(__dirname, '../src-ng')
}
},
],
}
]
},
plugins: [
new webpack.EnvironmentPlugin([
'NODE_ENV',
])
]
};
Answer the question
In order to leave comments, you need to log in
module: {
rules: [
{
test: /\.pug$/,
use: [
{ loader: 'file-loader', options: { name: '[name].html' } },
{ loader: 'extract-loader' },
{
loader: 'html-loader',
options: {
minimize: true,
removeComments: true
}
},
{
loader: 'pug-html-loader',
options: {
basedir: path.resolve(__dirname, '../src-ng')
}
}
],
}
]
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question