Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add webpack demo app to show how to tree shake out only the methods in use #490

Merged
merged 1 commit into from
Mar 28, 2019
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
11 changes: 11 additions & 0 deletions demos/tree-shaking/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Running this demo

This demo shows how to have a tool like webpack [tree shake](https://rollupjs.org/guide/en#tree-shaking) `@esri/rest-js` and only include methods that are actually being called in its output bundle.

Since webpack loads raw [es modules](https://www.sitepoint.com/understanding-es6-modules/), something like babel can be used to transpile more backwards compatible code.

1. Make sure you run `npm run bootstrap` in the root folder to setup the dependencies
1. cd into `/demos/tree-shaking/`
1. Run `npm run build`


11 changes: 11 additions & 0 deletions demos/tree-shaking/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>shaking the tree</title>
</head>
<body>
<script src="dist/bundle.js"></script>
</body>
</html>
4,630 changes: 4,630 additions & 0 deletions demos/tree-shaking/package-lock.json

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions demos/tree-shaking/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "@esri/arcgis-rest-webpack-demo",
"version": "1.0.0",
"private": true,
"description": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack"
},
"keywords": [],
"author": "",
"license": "Apache-2.0",
"devDependencies": {
"@babel/core": "^7.3.4",
"@babel/preset-env": "^7.3.4",
"babel-loader": "^8.0.5",
"webpack": "^4.29.6",
"webpack-cli": "^3.3.0"
},
"dependencies": {
"@esri/arcgis-rest-request": "^1.18.0",
"@esri/arcgis-rest-items": "^1.18.0"
}
}
10 changes: 10 additions & 0 deletions demos/tree-shaking/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { searchItems } from "@esri/arcgis-rest-items";

let element = document.createElement('div');
document.body.appendChild(element);

searchItems("water")
.then(response => {
element.innerHTML = JSON.stringify(response); // false
})

27 changes: 27 additions & 0 deletions demos/tree-shaking/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const path = require('path');

module.exports = {
entry: './src/index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
},
mode: 'production',
optimization: {
usedExports: true
},
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
]
}
};
45 changes: 33 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/arcgis-rest-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"unpkg": "dist/umd/auth.umd.js",
"module": "dist/esm/index.js",
"js:next": "dist/esm/index.js",
"sideEffects": true,
"types": "dist/esm/index.d.ts",
"license": "Apache-2.0",
"files": [
Expand Down
5 changes: 3 additions & 2 deletions packages/arcgis-rest-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"unpkg": "dist/umd/common.umd.js",
"module": "dist/esm/index.js",
"js:next": "dist/esm/index.js",
"sideEffects": false,
"types": "dist/esm/index.d.ts",
"license": "Apache-2.0",
"files": [
Expand All @@ -17,9 +18,9 @@
"scripts": {
"prepare": "npm run build",
"build": "npm run build:node && npm run build:umd && npm run build:esm",
"build:esm": "tsc -p ./tsconfig.json --module es2015 --outDir ./dist/esm --declaration",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its not necessary to call out the location of the tsconfig.json file explicitly.

the compiler searches for the tsconfig.json file starting in the current directory and continuing up the parent directory chain. - (reference)

"build:esm": "tsc --module es2015 --outDir ./dist/esm --declaration",
"build:umd": "rollup -c ../../umd-base-profile.js && rollup -c ../../umd-production-profile.js",
"build:node": "tsc -p ./tsconfig.json --module commonjs --outDir ./dist/node",
"build:node": "tsc --module commonjs --outDir ./dist/node",
"dev:esm": "tsc -w --module es2015 --outDir ./dist/esm --declaration",
"dev:umd": "rollup -w -c ../../umd-base-profile.js",
"dev:node": "tsc -w --module commonjs --outDir ./dist/node"
Expand Down
5 changes: 3 additions & 2 deletions packages/arcgis-rest-feature-service-admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"unpkg": "dist/umd/feature-service-admin.umd.js",
"module": "dist/esm/index.js",
"js:next": "dist/esm/index.js",
"sideEffects": false,
"types": "dist/esm/index.d.ts",
"license": "Apache-2.0",
"files": [
Expand All @@ -29,9 +30,9 @@
"scripts": {
"prepare": "npm run build",
"build": "npm run build:node && npm run build:umd && npm run build:esm",
"build:esm": "tsc -p ./tsconfig.json --module es2015 --outDir ./dist/esm --declaration",
"build:esm": "tsc --module es2015 --outDir ./dist/esm --declaration",
"build:umd": "rollup -c ../../umd-base-profile.js && rollup -c ../../umd-production-profile.js",
"build:node": "tsc -p ./tsconfig.json --module commonjs --outDir ./dist/node",
"build:node": "tsc --module commonjs --outDir ./dist/node",
"dev:esm": "tsc -w --module es2015 --outDir ./dist/esm --declaration",
"dev:umd": "rollup -w -c ../../umd-base-profile.js",
"dev:node": "tsc -w --module commonjs --outDir ./dist/node"
Expand Down
5 changes: 3 additions & 2 deletions packages/arcgis-rest-feature-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"unpkg": "dist/umd/feature-service.umd.js",
"module": "dist/esm/index.js",
"js:next": "dist/esm/index.js",
"sideEffects": false,
"types": "dist/esm/index.d.ts",
"license": "Apache-2.0",
"files": [
Expand All @@ -25,9 +26,9 @@
"scripts": {
"prepare": "npm run build",
"build": "npm run build:node && npm run build:umd && npm run build:esm",
"build:esm": "tsc -p ./tsconfig.json --module es2015 --outDir ./dist/esm --declaration",
"build:esm": "tsc --module es2015 --outDir ./dist/esm --declaration",
"build:umd": "rollup -c ../../umd-base-profile.js && rollup -c ../../umd-production-profile.js",
"build:node": "tsc -p ./tsconfig.json --module commonjs --outDir ./dist/node",
"build:node": "tsc --module commonjs --outDir ./dist/node",
"dev:esm": "tsc -w --module es2015 --outDir ./dist/esm --declaration",
"dev:umd": "rollup -w -c ../../umd-base-profile.js",
"dev:node": "tsc -w --module commonjs --outDir ./dist/node"
Expand Down
5 changes: 3 additions & 2 deletions packages/arcgis-rest-geocoder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"unpkg": "dist/umd/geocoder.umd.js",
"module": "dist/esm/index.js",
"js:next": "dist/esm/index.js",
"sideEffects": false,
"types": "dist/esm/index.d.ts",
"license": "Apache-2.0",
"files": [
Expand All @@ -27,9 +28,9 @@
"scripts": {
"prepare": "npm run build",
"build": "npm run build:node && npm run build:umd && npm run build:esm",
"build:esm": "tsc -p ./tsconfig.json --module es2015 --outDir ./dist/esm --declaration",
"build:esm": "tsc --module es2015 --outDir ./dist/esm --declaration",
"build:umd": "rollup -c ../../umd-base-profile.js && rollup -c ../../umd-production-profile.js",
"build:node": "tsc -p ./tsconfig.json --module commonjs --outDir ./dist/node",
"build:node": "tsc --module commonjs --outDir ./dist/node",
"dev:esm": "tsc -w --module es2015 --outDir ./dist/esm --declaration",
"dev:umd": "rollup -w -c ../../umd-base-profile.js",
"dev:node": "tsc -w --module commonjs --outDir ./dist/node"
Expand Down
5 changes: 3 additions & 2 deletions packages/arcgis-rest-groups/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"unpkg": "dist/umd/groups.umd.js",
"module": "dist/esm/index.js",
"js:next": "dist/esm/index.js",
"sideEffects": false,
"types": "dist/esm/index.d.ts",
"license": "Apache-2.0",
"files": [
Expand All @@ -27,9 +28,9 @@
"scripts": {
"prepare": "npm run build",
"build": "npm run build:node && npm run build:umd && npm run build:esm",
"build:esm": "tsc -p ./tsconfig.json --module es2015 --outDir ./dist/esm --declaration",
"build:esm": "tsc --module es2015 --outDir ./dist/esm --declaration",
"build:umd": "rollup -c ../../umd-base-profile.js && rollup -c ../../umd-production-profile.js",
"build:node": "tsc -p ./tsconfig.json --module commonjs --outDir ./dist/node",
"build:node": "tsc --module commonjs --outDir ./dist/node",
"dev:esm": "tsc -w --module es2015 --outDir ./dist/esm --declaration",
"dev:umd": "rollup -w -c ../../umd-base-profile.js",
"dev:node": "tsc -w --module commonjs --outDir ./dist/node"
Expand Down
Loading