-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7d35d7e
Showing
8 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.DS_Store | ||
.idea | ||
node_modules | ||
|
||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Axel Rauschmayer | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Demo: tree-shaking | ||
|
||
This project demonstrates how to do tree-shaking (removal of unused exports) with webpack 2 and Babel 6. | ||
|
||
Installation: | ||
|
||
``` | ||
cd tree-shaking-demo/ | ||
npm install | ||
``` | ||
|
||
There are three ways in which you can build and run the web app: | ||
|
||
* Build once: | ||
* `npm run build` | ||
* Open `build/index.html` | ||
* Watch files continuously, rebuild incrementally, whenever one of them changes: | ||
* `npm run watch` | ||
* Open `build/index.html`, manually reload page in browser whenever there was a change | ||
* Hot reloading via webpack dev server: | ||
* `npm start` | ||
* Go to `http://localhost:8080/`, page reloads automatically when there are changes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>webpack Babel demo</title> | ||
</head> | ||
<body> | ||
|
||
<h1>webpack Babel demo</h1> | ||
|
||
<div id="output"></div> | ||
|
||
<script src="bundle.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export function foo() { | ||
return 'foo'; | ||
} | ||
export function bar() { | ||
return 'bar'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import 'babel-polyfill'; | ||
import {foo} from './helpers'; | ||
|
||
document.getElementById('output').innerHTML = `Output: ${foo()}`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"devDependencies": { | ||
"babel-loader": "^6.2.0", | ||
"babel-preset-es2015": "^6.3.13", | ||
"babel-polyfill": "^6.3.14", | ||
|
||
"webpack": "^2.0.1-beta", | ||
"webpack-dev-server": "^1.14.0", | ||
"copy-webpack-plugin": "^0.3.3" | ||
}, | ||
"scripts": { | ||
"build": "webpack --optimize-minimize", | ||
"watch": "webpack --optimize-minimize --watch", | ||
"start": "webpack-dev-server --hot --inline" | ||
}, | ||
"author": "Axel Rauschmayer", | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* global __dirname */ | ||
|
||
var path = require('path'); | ||
|
||
var webpack = require('webpack'); | ||
var CopyWebpackPlugin = require('copy-webpack-plugin'); | ||
|
||
var dir_js = path.resolve(__dirname, 'js'); | ||
var dir_html = path.resolve(__dirname, 'html'); | ||
var dir_build = path.resolve(__dirname, 'build'); | ||
|
||
module.exports = { | ||
entry: path.resolve(dir_js, 'main.js'), | ||
output: { | ||
path: dir_build, | ||
filename: 'bundle.js' | ||
}, | ||
devServer: { | ||
contentBase: dir_build, | ||
}, | ||
module: { | ||
loaders: [ | ||
{ | ||
loader: 'babel-loader', | ||
test: dir_js, | ||
query: { | ||
//presets: ['es2015'], | ||
|
||
// All of the plugins of babel-preset-es2015, | ||
// minus babel-plugin-transform-es2015-modules-commonjs | ||
plugins: [ | ||
'transform-es2015-template-literals', | ||
'transform-es2015-literals', | ||
'transform-es2015-function-name', | ||
'transform-es2015-arrow-functions', | ||
'transform-es2015-block-scoped-functions', | ||
'transform-es2015-classes', | ||
'transform-es2015-object-super', | ||
'transform-es2015-shorthand-properties', | ||
'transform-es2015-computed-properties', | ||
'transform-es2015-for-of', | ||
'transform-es2015-sticky-regex', | ||
'transform-es2015-unicode-regex', | ||
'check-es2015-constants', | ||
'transform-es2015-spread', | ||
'transform-es2015-parameters', | ||
'transform-es2015-destructuring', | ||
'transform-es2015-block-scoping', | ||
'transform-es2015-typeof-symbol', | ||
['transform-regenerator', { async: false, asyncGenerators: false }], | ||
], | ||
}, | ||
} | ||
] | ||
}, | ||
plugins: [ | ||
// Simply copies the files over | ||
new CopyWebpackPlugin([ | ||
{ from: dir_html } // to: output.path | ||
]), | ||
// Avoid publishing files when compilation fails | ||
new webpack.NoErrorsPlugin() | ||
], | ||
stats: { | ||
// Nice colored output | ||
colors: true | ||
}, | ||
// Create source maps for the bundle | ||
devtool: 'source-map', | ||
}; |