Famous/framework

Support for module loading

Open

#19 opened on Jun 19, 2015

View on GitHub
 (5 comments) (0 reactions) (0 assignees)JavaScript (397 stars) (69 forks)batch import
enhancementhelp wanted

Description

Most developers will expect to be able to do this:

// In jon-doe/example/example.js

var _ = require('lodash');

FamousFramework.scene('jon-doe:example', {
    // etc.    
});

Although we don't restrict _against_using require etc., we don't currently have automatic support for it through our build process, meaning that the bundles generated by our build process won't actually have the required packages loaded in.

The current workaround

The current workaround is to pre-bundle your entrypoint file before feeding it through the framework's build process. E.g.:

  1. Create a pre-build entrypoint file, jon-doe/example/_example.js
  2. Install packages into your component directory
  3. Browserify your pre-build entrypoint, with the output file being your actual entrypoint file, jon-doe/example/example.js
  4. Let the framework build tool take over from there

That's annoying though, so...

The eventual solution(s)?

1.) We could include Browserify as part of our build process. Basically, check if the project directory has a package.json, then check for node_modules, npm i if necessary, and then browserify the necessary files before (or after) the main steps of our build. This is similar to what the Famous CLI deploy task does.

2.) More flexibly, we could allow the user to specify their own build hooks. I.e., a user could put this in their package.json:

"scripts": {
    "build-famous": "foobar"
}

Our build process would check for a package.json, and if the "build-famous" script is present in the "scripts" object, then we would run that prior to our build process. This seems like perhaps the most flexible approach.

Open to other suggestions here.

Contributor guide