Skip to content

Instantly share code, notes, and snippets.

@ViktorAndonov
Last active March 14, 2017 22:39
Show Gist options
  • Save ViktorAndonov/d7327651c7b6475993d497ec937621a5 to your computer and use it in GitHub Desktop.
Save ViktorAndonov/d7327651c7b6475993d497ec937621a5 to your computer and use it in GitHub Desktop.
Webpack

Instalaltion

npm i -g webpack this will install it globally on your system, use (sudo) if there is a problems.

Usage - small projects

You can use the npm scripts for small project to compile wabpack:

"scripts": {
    "build": "webpack src/main.js dist/bundle.js",
    "watch": "npm run build -- --watch"
 }

Then in the terminal run: npm run build [for the first command]
or: npm run watch [for the second command, to watch for future updates]

Usage - config file

In the project root create file: webpack.config.js webpack will look here for the comand webpack.
Check docs how to's for other locations.

Simplest config file, that executes with webpack terminal command:

var webpack = require('webpack');
var path = require('path'); // needed for absolute path

module.exports = {
	entry: './src/main.js',
	output: { 
		path: path.resolve(__dirname, './dist'), // absolute path
		filename: 'bundle.js'
	}
};

then the npm scripts in package.json can be modified to math that file:

    "build": "webpack",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment