stealjs / steal-tools

Build easy. Load fast.
https://stealjs.com/docs/steal-tools.html
MIT License
67 stars 23 forks source link

Make it possible to export `.mjs` packages that would work against canjs's core.mjs #1088

Open justinbmeyer opened 5 years ago

justinbmeyer commented 5 years ago

can-crud is built similar to how canjs's packages are built:

var Component = require("can-component");

Component.extend({
    tag: "can-crud",
    ...
})

While this is great for npm and a module loader, this doesn't make it easy to use on something like a codepen. I'd like something like the following to work:

import "//unpgk.com/can-crud@1";
import {Component} from "//unpgk.com/can@5";

Where //unpgk.com/can-crud@1 is importing canjs from //unpgk.com/can@5.

I'm not sure how this could work. Possibly via some mapping, including being able to import a mapping from can:

var importMapping = require("can/import-map.json");
importMapping //-> {"can-component": {package: "can", name: "Component"}}

stealTools.export({
    ...
    outputs: {
        "something es6": {
            map: importMapping
        }
    }
});
justinbmeyer commented 5 years ago
matthewp commented 5 years ago

I think steal-tools should have some new builds, for CDN and for native module usage. I would want something like:

dist/
  es/
    unpkg/
      can-component.js
    local/
      can-component.js

In the "local" build module specifiers have been rewritten to be point to the node modules. For example the above might do `import stache from "../../../../node_modules/can-stache/dist/local/can-stache.js". This is nice because you can work locally and things will be generally fast. The downside here would be that it expects a "flat" node_modules, so you if have multiple versions of any packages that will not work.

In the "unpkg" build module specifiers have been rewritten to point to a CDN (unpkg or maybe configurable). It will be like import stache from "https://unpkg.com/can-stache@^4.0.0/dist/unpkg/can-stache.js.