[英]webpack -Error: Cannot find module 'pug' after hitting get-api
after configuring webpack in express and then an new folder fomed but when i run bundle.js it successfully give a meassage- server is running on port 3000 bout when i hit api http://localhost:3000/api/test it gives loads whole bundle.js 在控制台中并给出错误为
错误:在新 p (D:\wfh\Frontend-3.0) 的 t (D:\wfh\Frontend-3.0-20220119T061742Z-001\Frontend-3.0\compressed\bundle.js:2:840468) 处找不到模块 'pug' -20220119T061742Z-001\Frontend-3.0\compressed\bundle.js:2:839766)
或者谁能告诉我如何没有 index.html output 我想要 index.pug output
如果您需要通过 Webpack 文件将 pug 模板渲染到 static HTML 文件中,您可以使用 pug -plugin 。
npm install pug-plugin --save-dev
webpack.config.js中的最小配置
const path = require('path');
const PugPlugin = require('pug-plugin');
module.exports = {
output: {
path: path.join(__dirname, 'public/'), // define an output path
publicPath: '/', // define a path
},
entry: {
index: './src/pages/index.pug', // render pug file into public/index.html
},
plugins: [
new PugPlugin(), // add the plugin
],
module: {
rules: [
{
test: /\.pug$/,
loader: PugPlugin.loader, // add the pug-loader
},
],
},
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.