Giter Site home page Giter Site logo

errors with webpack about shopify-api-node HOT 5 CLOSED

monei avatar monei commented on May 18, 2024
errors with webpack

from shopify-api-node.

Comments (5)

lpinca avatar lpinca commented on May 18, 2024

This is a bit problematic.

The first issue is fs.readdirSync. I'm not familiar with webpack but with browserify you can use the brfs transform and get the list of resources as expected in the bundle. I guess the same can be achieved in webpack.

The second issue is that resources are required and instantiated lazily. This will not work with bundlers because AFAIK they can only read require() calls that are statically analyzable.

So I think that right now there is no way to use the lib in the browser unless we remove the lazy require feature.

from shopify-api-node.

lpinca avatar lpinca commented on May 18, 2024

Actually it seems that webpack supports dynamic requires. I'll see if I can find a way to make it work.

from shopify-api-node.

lpinca avatar lpinca commented on May 18, 2024

I managed to make it work with webpack. Here is the configuration and the required dependencies:

'use strict';

module.exports = {
  entry: './index.js',
  output: {
    filename: 'bundle.js',
    libraryTarget: 'umd',
    library: 'Shopify'
  },
  module: {
    loaders: [
      {
        test: /\.json$/,
        loader: 'json-loader'
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        query: {
          presets: ['es2015']
        }
      },
      {
        test: /\.js$/,
        loader: 'transform?brfs'
      }
    ]
  }
};
babel-core
babel-loader
babel-preset-es2015
brfs
json-loader
transform-loader
webpack

It seems to work but the generated bundle is ~750 KB 😄 (~180 KB when minimized).
As said above, I'm not a webpack expert so maybe it can be improved.

from shopify-api-node.

lpinca avatar lpinca commented on May 18, 2024

With 5f83632 the size of the generated bundle is ~380 KB (~130 KB minimized). We can reduce it further by removing the lodash dependency and using some lightweight alternatives for _.pick and _.omit, but I don't know if it makes sense as the library has not been designed for the browser.

from shopify-api-node.

Jan-Jan avatar Jan-Jan commented on May 18, 2024

Thanks for this!

from shopify-api-node.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.