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

'request' cannot be tree-shaken out of a webpack bundle #424

Closed
jgravois opened this issue Dec 26, 2018 · 1 comment
Closed

'request' cannot be tree-shaken out of a webpack bundle #424

jgravois opened this issue Dec 26, 2018 · 1 comment

Comments

@jgravois
Copy link
Contributor

jgravois commented Dec 26, 2018

git checkout doc/webpack && npm i && npx webpack 🤔

https://webpack.js.org/guides/tree-shaking/

src/index.js

import { requiresFormData } from "@esri/arcgis-rest-request";

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

const options = {
  params: {
    baz: "bar"
  }
}

element.innerHTML = requiresFormData(options); // false

package.json

{
  "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": "ISC",
  "devDependencies": {
    "webpack": "^4.28.2",
    "webpack-cli": "^3.1.2"
  },
  "dependencies": {
    "@esri/arcgis-rest-request": "^1.14.3"
  },
  "sideEffects": false
}

webpack.config.js

const path = require('path');

module.exports = {
  entry: './src/index.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist')
  },
  mode: 'development',
  optimization: {
    usedExports: true
  }
};
jgravois added a commit that referenced this issue Mar 15, 2019
AFFECTS PACKAGES:
@esri/arcgis-rest-webpack-demo

ISSUES CLOSED: #424
jgravois added a commit that referenced this issue Mar 15, 2019
AFFECTS PACKAGES:
@esri/arcgis-rest-webpack-demo

ISSUES CLOSED: #424
jgravois added a commit that referenced this issue Mar 28, 2019
AFFECTS PACKAGES:
@esri/arcgis-rest-webpack-demo

ISSUES CLOSED: #424
@jgravois
Copy link
Contributor Author

a demo that shows webpack tree shaking in action can now be found in the repo

https://github.com/Esri/arcgis-rest-js/tree/master/demos/tree-shaking

disclaimer: there are still some gotcha's here related to the fact that our compilation target is es5 and we include tslib as a dependency.

that said, we'd love to hear from users to try and make additional improvements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant