Skip to content

Commit

Permalink
test: add test for compile pug as template funciton imported in js
Browse files Browse the repository at this point in the history
  • Loading branch information
webdiscus committed Dec 17, 2023
1 parent 97daf4c commit cfcaaca
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/manual/watch-dependencies-import-js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"description": "IMPORTANT: don't install webpack here because the Webpack instance MUST be one, otherwise appear the error: The 'compilation' argument must be an instance of Compilation.",
"scripts": {
"start": "webpack serve --mode development",
"watch": "webpack watch --mode development",
"build": "webpack --mode=production --progress"
},
"devDependencies": {
"html-bundler-webpack-plugin": "file:../../.."
}
}
7 changes: 7 additions & 0 deletions test/manual/watch-dependencies-import-js/src/index.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
html
head
title Test
script(src=require("./main.js") defer="defer")
body
h1 Hello World!
p Change the content of an imported JS file.
4 changes: 4 additions & 0 deletions test/manual/watch-dependencies-import-js/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// test in serv mode: change the content of the imported file
import str from './module';

console.log('>> main', { str });
2 changes: 2 additions & 0 deletions test/manual/watch-dependencies-import-js/src/module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// TODO: fix error after change this file in serv mode
module.exports = 'Test 123';
47 changes: 47 additions & 0 deletions test/manual/watch-dependencies-import-js/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const path = require('path');
const PugPlugin = require('../../..');

module.exports = {
mode: 'production',

output: {
path: path.join(__dirname, 'dist/'),
clean: true,
},

entry: {
index: './src/index.pug',
},

plugins: [
new PugPlugin({
js: {
filename: '[name].[contenthash:8].js',
},
}),
],

module: {
rules: [
{
test: /\.pug$/,
loader: PugPlugin.loader,
options: {
method: 'render',
},
},
],
},

// enable HMR with live reload
devServer: {
//hot: false,
static: path.join(__dirname, 'dist'),
watchFiles: {
paths: ['src/**/*.*'],
options: {
usePolling: true,
},
},
},
};

0 comments on commit cfcaaca

Please sign in to comment.