From de779b8becefde21d5da8cfcb898ebcdce2421ff Mon Sep 17 00:00:00 2001 From: biodiscus Date: Tue, 28 Nov 2023 14:41:11 +0100 Subject: [PATCH] test: add serv mode test for change imported js file --- .../watch-dependencies-import-js/package.json | 11 +++++ .../src/index.html | 11 +++++ .../watch-dependencies-import-js/src/main.js | 4 ++ .../src/module.js | 1 + .../webpack.config.js | 43 +++++++++++++++++++ 5 files changed, 70 insertions(+) create mode 100644 test/manual/watch-dependencies-import-js/package.json create mode 100644 test/manual/watch-dependencies-import-js/src/index.html create mode 100644 test/manual/watch-dependencies-import-js/src/main.js create mode 100644 test/manual/watch-dependencies-import-js/src/module.js create mode 100644 test/manual/watch-dependencies-import-js/webpack.config.js diff --git a/test/manual/watch-dependencies-import-js/package.json b/test/manual/watch-dependencies-import-js/package.json new file mode 100644 index 00000000..cfa38ad2 --- /dev/null +++ b/test/manual/watch-dependencies-import-js/package.json @@ -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:../../.." + } +} diff --git a/test/manual/watch-dependencies-import-js/src/index.html b/test/manual/watch-dependencies-import-js/src/index.html new file mode 100644 index 00000000..9f165c97 --- /dev/null +++ b/test/manual/watch-dependencies-import-js/src/index.html @@ -0,0 +1,11 @@ + + + + Home + + + +

Hello World!

+

Change the content of an imported JS file.

+ + \ No newline at end of file diff --git a/test/manual/watch-dependencies-import-js/src/main.js b/test/manual/watch-dependencies-import-js/src/main.js new file mode 100644 index 00000000..856c0908 --- /dev/null +++ b/test/manual/watch-dependencies-import-js/src/main.js @@ -0,0 +1,4 @@ +// test in serv mode: change the content of the imported file +import str from './module'; + +console.log('>> main', { str }); diff --git a/test/manual/watch-dependencies-import-js/src/module.js b/test/manual/watch-dependencies-import-js/src/module.js new file mode 100644 index 00000000..3f090786 --- /dev/null +++ b/test/manual/watch-dependencies-import-js/src/module.js @@ -0,0 +1 @@ +module.exports = 'Test 123'; diff --git a/test/manual/watch-dependencies-import-js/webpack.config.js b/test/manual/watch-dependencies-import-js/webpack.config.js new file mode 100644 index 00000000..bb35f1f9 --- /dev/null +++ b/test/manual/watch-dependencies-import-js/webpack.config.js @@ -0,0 +1,43 @@ +const path = require('path'); +const HtmlBundlerPlugin = require('html-bundler-webpack-plugin'); + +module.exports = { + mode: 'production', + stats: 'minimal', + + output: { + path: path.join(__dirname, 'dist/'), + }, + + plugins: [ + new HtmlBundlerPlugin({ + // auto processing templates in the path + entry: { + index: './src/index.html', + }, + + // test: configure paths to watch file changes + // watchFiles: { + // paths: ['./src'], + // //files: [/\.(html|js|sc?ss)$/], + // //ignore: [], + // }, + + verbose: true, + }), + ], + + // enable live reload + devServer: { + //hot: false, + static: { + directory: path.join(__dirname, 'dist'), + }, + watchFiles: { + paths: ['src/**/*.*'], + options: { + usePolling: true, + }, + }, + }, +};