Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions examples/tree-shaking/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "tree-shaking",
"version": "0.1.0",
"description": "Code examples for the tree-shaking guide.",
"main": "n/a",
"scripts": {
"build": "webpack",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/TheDutchCoder/webpack-guides-code-examples.git"
},
"keywords": [
"tree",
"shaking",
"webpack",
"dead",
"code",
"removal"
],
"author": "Greg Venech",
"license": "ISC",
"bugs": {
"url": "https://github.com/TheDutchCoder/webpack-guides-code-examples/issues"
},
"homepage": "https://github.com/TheDutchCoder/webpack-guides-code-examples#readme",
"devDependencies": {
"uglifyjs-webpack-plugin": "^0.4.6",
"webpack": "^3.5.5"
}
}
14 changes: 14 additions & 0 deletions examples/tree-shaking/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { cube } from './math.js';

function component() {
var element = document.createElement('div');

element.innerHTML = [
'Hello webpack!',
'5 cubed is equal to ' + cube(5)
].join('\n\n');

return element;
}

document.body.appendChild(component());
7 changes: 7 additions & 0 deletions examples/tree-shaking/src/math.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function square(x) {
return x * x;
}

export function cube(x) {
return x * x * x;
}
13 changes: 13 additions & 0 deletions examples/tree-shaking/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const path = require('path');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');

module.exports = {
entry: './src/index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
},
plugins: [
new UglifyJSPlugin()
]
};