Skip to content

Commit d26d6dd

Browse files
author
Ashwin Hegde
committed
Merge pull request #6 from hegdeashwin/develop
Develop
2 parents 9342c5b + 6600bbe commit d26d6dd

32 files changed

+173
-37
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ logs
66
pids
77
*.pid
88
*.seed
9+
*.map
910

1011
# Directory for instrumented libs generated by jscoverage/JSCover
1112
lib-cov
@@ -15,7 +16,7 @@ lib-cov
1516

1617
# Compiled binary addons (http://nodejs.org/api/addons.html)
1718
build/Release
18-
bundle.js
19+
bundle*.js
1920

2021
# Dependency directory
2122
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git

README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
# Learning WEBPACK - MODULE BUNDLER
22

3-
|Example No.|Execution Command|Comments|
4-
|-----------|-----------------|--------|
5-
|1, 2| ```webpack entry.js bundle.js``` | |
6-
|3| |we need the ```css-loader``` to process CSS files. We also need the ```style-loader``` to apply the styles in the CSS file. They need to be installed locally, without ```-g```|
7-
|4|```webpack entry.js bundle.js --module-bind 'css=style!css'``` | if you are using ```bash``` then use single quotes in Command. Please see https://github.com/webpack/webpack/issues/1453 for more information|
8-
|5|```webpack``` **OR** ```webpack --progress --colors``` **OR** ```webpack --progress --colors --watch``` | |
9-
|6|```webpack-dev-server --progress --colors --watch```|webpack-dev-server is a development server, it binds a small express server on localhost:8080 which serves your static assets as well as the bundle |
3+
|Eg.No.|Execution Command|Comments|
4+
|------|-----------------|--------|
5+
|1|```webpack entry.js bundle.js```|Webpack will read entry.js file to build bundle.js|
6+
|2|```webpack entry.js bundle.js -p``` |```-p``` is used for bundle minification|
7+
|2|```webpack entry.js bundle.js -d```|```-d``` is used for bundle with source maps|
8+
|3|```webpack entry.js bundle.js --progress```|Know the progress of building the bundle|
9+
|3|```webpack entry.js bundle.js --colors```|Display text in colors|
10+
|4|```webpack entry.js bundle.js```|we need the ```css-loader``` to process CSS files. We also need the ```style-loader``` to apply the styles in the CSS file. They need to be installed locally, without ```-g```|
11+
|5|```webpack entry.js bundle.js --module-bind 'css=style!css'``` | This will simplify the CSS require path. Note: If you are using ```bash``` then use single quotes in Command. Please see https://github.com/webpack/webpack/issues/1453 for more information|
12+
|6|```webpack```|Webpack will read ```webpack.config.js``` from the root directory to build bundle.js|
13+
|7|```webpack --watch```|Will keep a watch on files to automatically rebuild the bundle|
14+
|7|```webpack-dev-server```|webpack-dev-server is a development server, it binds a small express server on localhost:8080 which serves your static assets as well as the bundle|
15+
|8|```webpack```|Multiple entry files are allowed|
16+
|9|```webpack```|Code splitting and loading files on demand, Open browser and try ```localhost:8080``` see content-1 is loaded but not content-2, Now try execute ```localhost:8080/#load``` see content-1 and content-2 are both loaded|

codes/example-1/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
<html>
33
<head>
44
<meta charset="utf-8">
5-
<title>Example 1</title>
5+
<title>Eg1: initial bundle</title>
66
</head>
77
<body>
8+
<h1>Hello World</h1>
9+
810
<script type="text/javascript" src="bundle.js"></script>
911
</body>
1012
</html>

codes/example-2/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
<html>
33
<head>
44
<meta charset="utf-8">
5-
<title>Example 2</title>
5+
<title>Eg2: building minified bundle</title>
66
</head>
77
<body>
8+
<h1>Hello World</h1>
9+
810
<script type="text/javascript" src="bundle.js"></script>
911
</body>
1012
</html>

codes/example-3/content.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
console.log("Hello webpack");
1+
module.exports = "Hello webpack";

codes/example-3/entry.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
console.log("Hello World");
22

3-
require("!style!css!./style.css");
4-
5-
console.log(require("./content.js"));
3+
console.log(require('./content.js'));

codes/example-3/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
<html>
33
<head>
44
<meta charset="utf-8">
5-
<title>Example 3</title>
5+
<title>Eg3: building bundle with source map</title>
66
</head>
77
<body>
8+
<h1>Hello World</h1>
9+
810
<script type="text/javascript" src="bundle.js"></script>
911
</body>
1012
</html>

codes/example-3/style.css

Lines changed: 0 additions & 3 deletions
This file was deleted.

codes/example-4/entry.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
console.log("Hello World");
22

3-
require("./style.css");
3+
require("!style!css!./style.css");
44

55
console.log(require("./content.js"));

codes/example-4/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
<html>
33
<head>
44
<meta charset="utf-8">
5-
<title>Example 4</title>
5+
<title>Eg4: CSS-Loader</title>
66
</head>
77
<body>
8+
<h1>Hello Webpack</h1>
9+
810
<script type="text/javascript" src="bundle.js"></script>
911
</body>
1012
</html>

codes/example-4/style.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
body {
2-
background: green;
2+
background: yellow;
3+
}
4+
5+
h1 {
6+
color: blue;
37
}

codes/example-5/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
<html>
33
<head>
44
<meta charset="utf-8">
5-
<title>Example 5</title>
5+
<title>Eg8: Multi entry files</title>
66
</head>
77
<body>
8+
<h1>Hello Webpack</h1>
9+
810
<script type="text/javascript" src="bundle.js"></script>
911
</body>
1012
</html>

codes/example-5/style.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
body {
2-
background: blue;
2+
background: green;
3+
}
4+
5+
h1 {
6+
color: black;
37
}

codes/example-6/index.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
<html>
33
<head>
44
<meta charset="utf-8">
5-
<title>Example 6</title>
5+
<title>Eg6: Add webpack.config</title>
66
</head>
77
<body>
8-
<h1>Hello World!</h1>
9-
<h2>Welcome to webpack!</h2>
10-
<h3>Learn by practice</h3>
8+
<h1>Hello Webpack</h1>
9+
1110
<script type="text/javascript" src="bundle.js"></script>
1211
</body>
1312
</html>

codes/example-6/style.css

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
body {
2-
background: black;
3-
font-family: arial;
2+
background: blue;
43
}
54

65
h1 {
7-
color: white;
8-
}
9-
10-
h2 {
116
color: yellow;
127
}
13-
14-
h3 {
15-
color: pink;
16-
}

codes/example-7/content.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("Hello webpack");

codes/example-7/entry.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
console.log("Hello World");
2+
3+
require("./style.css");
4+
5+
console.log(require("./content.js"));

codes/example-7/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Eg7: Enable Watch and Dev server</title>
6+
</head>
7+
<body>
8+
<h1>Hello World!</h1>
9+
<h2>Welcome to Webpack!</h2>
10+
<h3>Learn by practice</h3>
11+
12+
<script type="text/javascript" src="bundle.js"></script>
13+
</body>
14+
</html>

codes/example-7/style.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
body {
2+
background: black;
3+
font-family: arial;
4+
}
5+
6+
h1 {
7+
color: white;
8+
}
9+
10+
h2 {
11+
color: yellow;
12+
}
13+
14+
h3 {
15+
color: pink;
16+
}
File renamed without changes.

codes/example-8/content.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("Hello Ashwin");

codes/example-8/entry-1.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
console.log("Hello Webpack 1");
2+
3+
require("./style.css");
4+
5+
console.log(require("./content.js"));

codes/example-8/entry-2.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
console.log("Hello Webpack 2");
2+
3+
require("./style.css");
4+
5+
console.log(require("./content.js"));

codes/example-8/entry.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
console.log("Hello World");
2+
3+
require("./style.css");
4+
5+
console.log(require("./content.js"));

codes/example-8/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Example 6</title>
6+
</head>
7+
<body>
8+
<h1>Hello World!</h1>
9+
<h2>Welcome to webpack!</h2>
10+
<h3>Learn by practice</h3>
11+
<script type="text/javascript" src="bundle1.js"></script>
12+
<script type="text/javascript" src="bundle2.js"></script>
13+
</body>
14+
</html>

codes/example-8/style.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
body {
2+
background: black;
3+
font-family: arial;
4+
}
5+
6+
h1 {
7+
color: white;
8+
}
9+
10+
h2 {
11+
color: yellow;
12+
}
13+
14+
h3 {
15+
color: pink;
16+
}

codes/example-8/webpack.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = {
2+
entry: {
3+
bundle1: './entry-1.js',
4+
bundle2: './entry-2.js'
5+
},
6+
output: {
7+
path: __dirname,
8+
filename: '[name].js'
9+
},
10+
"module": {
11+
loaders: [{
12+
test: /\.css$/,
13+
loader: 'style!css'
14+
}]
15+
}
16+
};

codes/example-9/content-1.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "Content 1";

codes/example-9/content-2.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "Content 2";

codes/example-9/entry.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
console.log("Hello World");
2+
3+
console.log(require('./content-1.js'));
4+
5+
if(window.location.href.indexOf('load') !== -1 ) {
6+
console.log(require('./content-2.js'));
7+
}

codes/example-9/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Eg9: Code splitting and loading files on demand</title>
6+
</head>
7+
<body>
8+
<h1>Hello Webpack</h1>
9+
10+
<script type="text/javascript" src="bundle.js"></script>
11+
</body>
12+
</html>

codes/example-9/webpack.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
entry: './entry.js',
3+
output: {
4+
filename: 'bundle.js'
5+
}
6+
};

0 commit comments

Comments
 (0)