Giter VIP home page Giter VIP logo

webpack-watch-server's Introduction

webpack-watch-server

npm version CI status

A single webpack-watch-server command to add to your package scripts that fires up Webpack in watch mode and restarts your server each build. Webpack and server logs stream in a unified console with clear formatting and pretty colors.

By using a Webpack build callback under the hood, this package is much more efficient than using a seperate watcher (such as Nodemon or Forever) to restart the server.

webpack-watch-server demo

Setup

To install from npm run:

npm install webpack-watch-server --save-dev

Usage

  1. Add "dev": "webpack-watch-server" to your package.json scripts. To specify a custom Webpack config file path use webpack-watch-server --config path/to/custom-webpack-config.js. The file will be transpiled with Babel if it’s name ends with .config.babel.js.
  2. Run npm run dev to start Webpack in watch mode. The server automatically starts and restarts after each build.

Caveats

  • It is assumed your server file is the default Node finds at the Webpack config output.path – index.js works.
  • For now, only plain object Webpack configs are supported.

Support

  • Node.js ^10.17.0 || ^12.0.0 || >= 13.7.0.

webpack-watch-server's People

Contributors

jaydenseric avatar kayakyakr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

webpack-watch-server's Issues

"Error: Cannot find module xxx" while it seems to be working fine

Hello,
Everything seems to be working OK, but I get this error at every build/start:

 module.js:557
     throw err;
    ^
 Error: Cannot find module '/usr/src/app/dist'
     at Function.Module._resolveFilename (module.js:555:15)
     at Function.Module._load (module.js:482:25)
     at Function.Module.runMain (module.js:701:10)
     at startup (bootstrap_node.js:190:16)
    at bootstrap_node.js:662:3

Here is my package.json

"scripts": {
    "dev": "webpack-watch-server --config webpack.dev.xeapi.js"
  },
(...)
  "devDependencies": {
    "babel-loader": "^7.1.4",
    "config-webpack": "^1.0.4",
    "eslint": "^4.19.0",
    "grunt": "^1.0.2",
    "grunt-contrib-clean": "^1.1.0",
    "grunt-env": "^0.4.4",
    "grunt-shell": "^2.1.0",
    "json-loader": "^0.5.7",
    "mocha": "^4.0.1",
    "request": "^2.85.0",
    "request-promise": "^4.2.2",
    "start-server-webpack-plugin": "^2.2.5",
    "webpack": "^4.5.0",
    "webpack-bundle-analyzer": "^2.11.1",
    "webpack-cli": "^2.0.14",
    "webpack-merge": "^4.1.2",
    "webpack-node-externals": "^1.7.2",
    "webpack-watch-server": "^1.2.1"
  }
(...)

Here is webpack.dev.xeapi.js

var path = require('path');
var webpack = require('webpack');
const merge = require('webpack-merge');
const common = require('./webpack.common.xeapi.js');
module.exports = merge(common, {
	mode : 'development',
	cache : true,
	stats: {
		// Nice colored output
		colors: true
	},
	// Create Sourcemaps for the bundle
	devtool: 'inline-source-map'
});

...and the required webpack.common.xeapi.js

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

module.exports = {
    entry: {
	main: ['./src/index.js']
    },
    output: {
        path: path.join(__dirname,'dist/'),
        filename: 'server-app.js'
    },
    module: {
	    rules: [
	      {
	        test: /\.js$/,
	        use: [{
	          loader: 'babel-loader',
	          options: { presets: ['es2015'] }
	        }],
	      },
	    ],
	  },
  // Keep node_modules out of the generated bundle
  target: 'node',
  externals: [nodeExternals()],
};

Does that ring a bell?

Thanks in advance,

Vince

Add an option to disable clearConsole()

Hello,

Thank you for this very useful plugin.
I'm running webpack-watch-server in a Docker container and I would like to keep track of the console logs:

  • at startup
  • every time a new build occurs

It would be nice to have a --preserveConsole option or equivalent.

Best regards,

Vince.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.