This repository has been archived by the owner on Jan 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(webpack-backend): Nodemon for dev hook
- Loading branch information
Showing
3 changed files
with
384 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,36 @@ | ||
module.exports = clipped => clipped.use(require('clipped-preset-webpack-nodejs')) | ||
const path = require('path') | ||
const fs = require('fs') | ||
const nodemon = require('nodemon') | ||
|
||
module.exports = async clipped => { | ||
await clipped.use(require('clipped-preset-webpack-nodejs')) | ||
|
||
let mainFile = path.join(clipped.config.context, clipped.config.packageJson.main) | ||
try { | ||
require(mainFile) | ||
} catch (e) { | ||
mainFile = null | ||
} | ||
|
||
clipped.hook('dev') | ||
.add('watch and nodemon', [ | ||
clipped => clipped.execHook('watch'), | ||
clipped => new Promise((resolve, reject) => { | ||
nodemon({ | ||
// Main field in package.json or dist/index.js | ||
script: mainFile || clipped.config.main || path.join(clipped.config.dist, 'index.js'), | ||
ext: 'js json', | ||
ignore: ["test/*", "docs/*"] | ||
}) | ||
|
||
nodemon.on('start', function () { | ||
console.log('> App has started') | ||
}).on('quit', function () { | ||
console.log('> App has quit') | ||
process.exit(); | ||
}).on('restart', function (files) { | ||
console.log('> App restarted due to: ', files) | ||
}) | ||
}) | ||
]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.