ausi / cq-prolyfill

Prolyfill for CSS Container Queries
https://au.si/css-container-element-queries
MIT License
565 stars 39 forks source link

Support SystemJS as module loader #29

Closed lmaze closed 8 years ago

lmaze commented 8 years ago

Hi there,

Here we use SystemJS (with JSPM) as module loader to load ES6 modules. SystemJS also supports CommonJS and AMD modules but it's not working with cq-prolyfill.

The code I have is very simple :

import cq from 'cq-prolyfill';

cq.reevaluate(false, function() {
    // Do something after all elements were updated
});

The JS file for cq-prolyfill is well loaded by the browser but the cq variable does not contain the reevaluate method. So it seems that the export is not properly done.

Do you have an idea of what could be the problem?

It would be really interesting cq-prolyfill can be loaded with SystemJS and not just with Browserify or Webpack.

lmaze commented 8 years ago

After some research, I think SystemJS can not properly detect the cq-prolyfill format because of the way it defines its modules.

I have a working configuration file by modifying the jspm.config.js and declaring cq-prolyfill as a global module:

packages: {
    "npm:cq-prolyfill@0.3.2": {
      meta: {
        'cq-prolyfill.js': {
          format: 'global',
          exports: 'cqApi'
        }
      },
      .....
    }
}

However I do not know if this is the best way.

lmaze commented 8 years ago

I was wrong, SystemJS detects well automatically cq-prolyfill as CommonJS module.

I did not notice a factory was exported directly and not an object.

Here is my JS code corrected:

import cqFactory from 'cq-prolyfill';

const cq = cqFactory();
cq.reevaluate(false, function() {
    // Do something after all elements were updated
});

Sorry for my mistake. I hope it will help others :)

ausi commented 8 years ago

Nothing to be sorry about :) It’s great you could resolve the issue.