我使用gulp default来启动我的nodejs服务器并观察是否有任何更改。我想用webpack来做这个简单的例子。
gulpfile。js
var gulp = require('gulp');
var nodemon = require('gulp-nodemon');
var notify = require('gulp-notify');
var livereload = require('gulp-livereload');
gulp.task('default', function() {
livereload.listen();
nodemon({
script: 'index.js',
ext: 'js'
}).on('restart', function() {
gulp.src('index.js')
.pipe(livereload())
.pipe(notify('Reloading page, please wait...'));
});
});webpack.config.js
const path = require('path');
module.exports = {
entry: './index.js',
output: {
path: path.join(__dirname, 'dist'),
filename: 'index.bunde.js'
},
target: 'node',
};package.json
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"body-parser": "^1.17.2",
"cors": "^2.8.4",
"dotenv": "^4.0.0",
"express": "^4.15.4",
"express-validator": "^4.1.1",
"gulp": "^3.9.1",
"gulp-install": "^1.1.0",
"gulp-livereload": "^3.8.1",
"gulp-nodemon": "^2.2.1",
"gulp-notify": "^3.0.0",
"jsonwebtoken": "^8.0.0",
"mailgun-js": "^0.13.1",
"mongoose": "^4.11.9",
"morgan": "^1.8.2",
"passport": "^0.4.0",
"passport-jwt": "^2.2.1",
"passport-local": "^1.0.0",
"twilio": "^4.6.0",
"uuid": "^3.1.0"
},
"devDependencies": {
"gulp": "^3.9.1",
"webpack": "^3.5.6"
}
}我怎样才能将这个先前的吞咽设置转换为webpack?我只是简单地希望能够在index.js中的入口点处放置一个命令来启动我的节点服务器,并观察在任何.js文件中所做的任何更改。
发布于 2017-09-11 19:32:12
使用webpack bin构建您的应用程序并查看更改:
"scripts": {
"start-server": "node server",
"start-client": "webpack --config ./webpack.config --display-entrypoints --watch",
"start": "start-server && start-client"
...
}https://stackoverflow.com/questions/46154334
复制相似问题