macdonst opened a new issue #156: Make it easier to use webpack with JS actions
URL: https://github.com/apache/openwhisk-runtime-nodejs/issues/156
 
 
   <!--
   We use the issue tracker for bugs and feature requests. For general 
questions and discussion please use http://slack.openwhisk.org/ or 
https://openwhisk.apache.org/contact.html instead.
   
   Do NOT share passwords, credentials or other confidential information.
   
   Before creating a new issue, please check if there is one already open that
   fits the defect you are reporting.
   If you open an issue and realize later it is a duplicate of a pre-existing
   open issue, please close yours and add a comment to the other.
   
   Issues can be created for either defects or enhancement requests. If you are 
a committer than please add the labels "bug" or "feature". If you are not a 
committer please make clear in the comments which one it is, so that committers 
can add these labels later.
   
   If you are reporting a defect, please edit the issue description to include 
the
   information shown below.
   
   If you are reporting an enhancement request, please include information on 
what you are trying to achieve and why that enhancement would help you.
   
   For more information about reporting issues, see
   
https://github.com/apache/incubator-openwhisk/blob/master/CONTRIBUTING.md#raising-issues
   
   Use the commands below to provide key information from your environment:
   You do not have to include this information if this is a feature request.
   -->
   
   ## Environment details:
   
   * all deployments   
   * all versions
   
   ## Steps to reproduce the issue:
   
   1.   Create a JS action following [Package an action as a single 
bundle](https://github.com/apache/incubator-openwhisk/blob/master/docs/actions-node.md#package-an-action-as-a-single-bundle)
 instructions.
   2.   Include a package like `request-promise` that's [already 
included](https://github.com/apache/incubator-openwhisk/blob/master/docs/actions-node.md#nodejs-version-6-environment)
 in the OpenWhisk container.
   3.   Build the action
   
   
   ## Provide the expected results and outputs:
   
   It would be great if right out of the box your JS action would exclude any 
packages in the container. For instance when I exclude `request-promise` the 
action is 2kb.
   
   ```
   webpack v4.13.0
   
   1e71fd7ad002a3195f86
     size     name  module                      status
     167 B    0     ./src/config.js             built
     42 B     1     external "request-promise"  built
     1.42 kB  2     ./src/stockAPI.js           built
     992 B    3     ./src/index.js              built
   
     size     name  asset                       status
     2.05 kB  main  bundle.js                   emitted
   
     Δt 106ms
   ```
   
   
   ## Provide the actual results and outputs:
   
   But when I don't specify `request-promise` as an external the action is 
770kb:
   
   ```
   webpack v4.13.0
   
   2dfdb6782288d2371fc3
     size     name  module                  status
     42 B     1     external "util"         built
     42 B     3     external "crypto"       built
     42 B     9     external "url"          built
     42 B     16    external "stream"       built
     42 B     20    external "http"         built
     42 B     31    external "querystring"  built
     42 B     35    external "https"        built
     42 B     47    external "net"          built
     42 B     63    external "fs"           built
     42 B     65    external "tls"          built
     167 B    87    ./src/config.js         built
     42 B     88    external "os"           built
     42 B     174   external "zlib"         built
     1.42 kB  224   ./src/stockAPI.js       built
     992 B    225   ./src/index.js          built
   
     size     name  asset                   status
     733 kB   main  bundle.js               emitted
   
     Δt 6940ms (211 modules hidden)
   ```
   
   ## Additional information you deem important:
   
   Yes, I know I can go into webpack and list the pre-installed node packages 
as externals like so:
   
   ```javascript
   module.exports = {
     entry: './src/index.js',
     output: {
       path: path.resolve(__dirname, '..', 'dist'),
       filename: 'bundle.js'
     },
     target: 'node',
     externals: [ 'request-promise' ]
   };
   ```
   
   but wouldn't life be so much easier if all the packages that are installed 
in the node container were in a single npm package? This way you could easily 
exclude all the dependent packages in webpack and it would make maintenance of 
the packages in the container easier.
   
   For instance I created a package 
[simon-runtime-deps](https://www.npmjs.com/package/simon-runtime-deps) which 
includes all 55 dependencies from the node 6 container. This allows me to 
create a quick script to externalize those dependencies in webpack:
   
   ```javascript
   var path = require('path');
   var nodeExternals = require('simon-runtime-deps');
   
   module.exports = {
     entry: './src/index.js',
     output: {
       path: path.resolve(__dirname, '..', 'dist'),
       filename: 'bundle.js'
     },
     target: 'node',
     externals: [nodeExternals()]
   };
   ```
   
   This approach could also have the added benefit of simplifying the 
`package.json` or `Dockerfile` so you wouldn't have some many dependencies to 
maintain.
   
   We could have an `openwhisk-node8-dependencies` package as a base and 
vendors can add their own packages `bluemix-node8-dependencies` for example.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to