Skip to content

Commit eb7da02

Browse files
skipjackTheDutchCoder
authored andcommitted
chore(examples): add tree-shaking example (#24)
Add tree shaking example that corresponds with: webpack/webpack.js.org#1508
1 parent e98ebf2 commit eb7da02

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

examples/tree-shaking/package.json

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "tree-shaking",
3+
"version": "0.1.0",
4+
"description": "Code examples for the tree-shaking guide.",
5+
"main": "n/a",
6+
"scripts": {
7+
"build": "webpack",
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "git+https://github.com/TheDutchCoder/webpack-guides-code-examples.git"
13+
},
14+
"keywords": [
15+
"tree",
16+
"shaking",
17+
"webpack",
18+
"dead",
19+
"code",
20+
"removal"
21+
],
22+
"author": "Greg Venech",
23+
"license": "ISC",
24+
"bugs": {
25+
"url": "https://github.com/TheDutchCoder/webpack-guides-code-examples/issues"
26+
},
27+
"homepage": "https://github.com/TheDutchCoder/webpack-guides-code-examples#readme",
28+
"devDependencies": {
29+
"uglifyjs-webpack-plugin": "^0.4.6",
30+
"webpack": "^3.5.5"
31+
}
32+
}

examples/tree-shaking/src/index.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { cube } from './math.js';
2+
3+
function component() {
4+
var element = document.createElement('div');
5+
6+
element.innerHTML = [
7+
'Hello webpack!',
8+
'5 cubed is equal to ' + cube(5)
9+
].join('\n\n');
10+
11+
return element;
12+
}
13+
14+
document.body.appendChild(component());

examples/tree-shaking/src/math.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export function square(x) {
2+
return x * x;
3+
}
4+
5+
export function cube(x) {
6+
return x * x * x;
7+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const path = require('path');
2+
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
3+
4+
module.exports = {
5+
entry: './src/index.js',
6+
output: {
7+
filename: 'bundle.js',
8+
path: path.resolve(__dirname, 'dist')
9+
},
10+
plugins: [
11+
new UglifyJSPlugin()
12+
]
13+
};

0 commit comments

Comments
 (0)