Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Support for watching outside cwd #242

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions examples/example-workspace/app1/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>App1</title>
</head>
<body>
<script type="module" src="/main.js"></script>
</body>
</html>
5 changes: 5 additions & 0 deletions examples/example-workspace/app1/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
document.body.textContent = 'Hello World - App1';

module.hot.accept(() => {
window.location.reload();
});
9 changes: 9 additions & 0 deletions examples/example-workspace/app2/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>App2</title>
</head>
<body>
<script type="module" src="/main.js"></script>
</body>
</html>
5 changes: 5 additions & 0 deletions examples/example-workspace/app2/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
document.body.textContent = 'Hello World - App2';

module.hot.accept(() => {
window.location.reload();
});
5 changes: 5 additions & 0 deletions examples/example-workspace/scripts/.nolluprc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
hot: true,
port: 9001,
contentBase: `../${process.env.APP_TARGET}/public`
};
11 changes: 11 additions & 0 deletions examples/example-workspace/scripts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"scripts": {
"dev:app1": "NODE_ENV=development APP_TARGET=app1 node ../../../lib/cli.js -c",
"dev:app2": "NODE_ENV=development APP_TARGET=app2 node ../../../lib/cli.js -c",
"build:app1": "NODE_ENV=production APP_TARGET=app1 rollup -c --watch",
"build:app2": "NODE_ENV=production APP_TARGET=app2 rollup -c --watch"
},
"devDependencies": {
"rollup": "^3.11.0"
}
}
8 changes: 8 additions & 0 deletions examples/example-workspace/scripts/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
input: `../${process.env.APP_TARGET}/src/main.js`,
output: {
dir: 'dist',
format: 'esm',
entryFileNames: '[name].js'
}
}
12 changes: 12 additions & 0 deletions lib/dev-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,19 @@ module.exports = function (app, config, options, server) {
}

(async function () {
function extraWatch() {
return {
buildEnd() {
let files = this.getWatchFiles();
watcher.add(files);
}
}
}

for (let i = 0; i < configs.length; i++) {
configs[i].plugins = configs[i].plugins || [];
configs[i].plugins.push(extraWatch());

let bundle = await nollup(configs[i]);
bundle.configure(options); // live-bindings config
bundles.push(bundle);
Expand Down
4 changes: 4 additions & 0 deletions test/cases/DevMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ let chokidar = {
return {
on: (event, callback) => {
this._callbacks.push({ event, callback });
},

add() {

}
}
},
Expand Down