vihanb / babel-plugin-wildcard

Wildcard imports import a directories JS files
MIT License
186 stars 27 forks source link

using it in jspm setup? #6

Open sookoll opened 7 years ago

sookoll commented 7 years ago

Have you tried it on jspm setup? For me it doesn't work, as I got:

Uncaught (in promise) Error: (SystemJS) Unknown plugin "babel-plugin-wildcard"

My config.js looks like this:

System.config({
...
babelOptions: {
    "optional": [
      "runtime",
      "optimisation.modules.system"
    ],
    "plugins": [
      "babel-plugin-wildcard"
    ]
  },
map: {
    "babel": "npm:babel-core@5.8.38",
    "babel-plugin-wildcard": "npm:babel-plugin-wildcard@2.1.2",
...
vihanb commented 7 years ago

Could this be related to jspm/jspm-cli#778? Also, does this occur with other plugins? I think you might have to file an issue w/ JSPM about this because it seems like it cannot even locate the module.

sookoll commented 7 years ago

Yes, You are right, jspm 0.16 does not support babel plugins. jspm@beta will. Tried that, plugin are loaded but it doesn't work (got 404 for modules_directory.js). JSPM by default load babel and es6 modules into browser and then transpile. I guess that wildcard plugin needs to access file system to determine modules, right? So only option would be server-side transpiling also in development mode.

UPDATE: Tried development bundling as described here: https://jspm.io/0.17-beta-guide/development-bundling.html with no luck.

$ jspm install --dev npm:babel-plugin-wildcard
SystemJS.config({
  ...
  meta: {
    '*.js': {
      babelOptions: {
        plugins: ['babel-plugin-wildcard']
      }
    }
  }
});

command to transpile bundle:

$ jspm bundle src/main.js src/build.js -id

It never recognize, that it should use wildcard plugin for imports.

drgould commented 7 years ago

I think the problem is babel auto-prepends "babel-plugin-" when searching for the plugin, e.g. try simply: plugins: ['wildcard']