NODE.JS:为什么我不能通过网络包重新加载?

时间:2017-04-24 05:21:14

标签: node.js livereload

现在,我已经花了一天时间,我花了一整天的时间试图让webpack工作,但是每个教程或文档都很糟糕......不应该这么难......如果这些包真的让你花更多钱时间尝试配置它们然后节省时间。

我只想让实时重新加载工作。我已经尝试了内联方法,iframe,热模块,带有express的中间件。它都不起作用......我在原子上使用Node.js,使用safari浏览器。

我希望它能与快递合作。

有人能指点我一个好的教程......或者一步一步地解释一下......

需要帮助。请。没人回复这些事情!谢谢

GITHUB REPO LINK

webpack.config.js

const nodeExternals = require('webpack-node-externals');

module.exports =
{
  entry: './app.js',
  target: 'node',
  externals: [nodeExternals()],
  output: {
    path: __dirname + '/dist',
    filename: 'app.bundle.js',
  },
  devServer: {
    port: 8000,
    open: true,
    inline: true
  },
  module: {
    loaders: [
      {
        loader: 'babel-loader',
        test: /\.js$/,
        exclude: /node_modules/
      }
    ]
  }
}

的package.json

{
  "name": "clinic8beauty",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "b": "webpack",
    "s": "webpack-dev-server",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "babel": {
    "presets": [
      "es2015"
    ]
  },
  "author": "Kosta Pontidas",
  "license": "ISC",
  "dependencies": {
    "body-parser": "^1.17.1",
    "events": "^1.1.1",
    "express": "^4.15.2",
    "jquery": "^3.2.1",
    "pug": "^2.0.0-beta.12",
    "twilio": "^2.11.1",
    "validator": "^7.0.0"
  },
  "devDependencies": {
    "babel-core": "^6.24.1",
    "babel-loader": "^7.0.0",
    "babel-polyfill": "^6.23.0",
    "babel-preset-es2015": "^6.24.1",
    "node-sass": "^4.5.2",
    "pug-html-loader": "^1.1.4",
    "sass-loader": "^6.0.3",
    "webpack": "^2.4.1",
    "webpack-dev-server": "^2.4.4",
    "webpack-hot-middleware": "^2.18.0",
    "webpack-node-externals": "^1.5.4"
  }
}

app.js需要

const express = require('express'),
      app = express(),
      events = require('events'),
      eventEmitter = new events.EventEmitter(),
      bodyParser = require('body-parser'),
      validator = require('validator'),
      client = require('twilio')('AC3cdbdc7ecb720d5521f41243450343e8',
                             '8f76c52d839dc25aa17ddc72b3b9d781');

3 个答案:

答案 0 :(得分:0)

您的配置中有目标节点将其更改为网络或删除它,因为默认为网络。它应该解决你的问题。

答案 1 :(得分:0)

您可以尝试以下方法吗?

const nodeExternals = require('webpack-node-externals');
const path = require('webpack'); // <== added

module.exports =
{
  entry: './app.js',
 // target: 'node', <== deleted
  externals: [nodeExternals()],
  output: {
    path: path.resolve(__dirname, 'dist'), //<== added
    filename: 'app.bundle.js'
  },
  devServer: {
    port: 8000,
    open: true,
    inline: true,
    contentBase: [path.resolve(__dirname, 'dist')/* add other directories if needed */]
  },
  module: {
    loaders: [
      {
        loader: 'babel-loader',
        test: /\.js$/,
        exclude: /node_modules/
      }
    ]
  }
}

并运行webpack-dev-server --progress而非webpack来启动服务器

答案 2 :(得分:0)

为什么不使用nodemon global和webpack来编译