Famous/framework

Support for module loading

Open

#19 建立於 2015年6月19日

在 GitHub 查看
 (5 留言) (0 反應) (0 負責人)JavaScript (397 star) (69 fork)batch import
enhancementhelp wanted

描述

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.

貢獻者指南

Support for module loading · Famous/framework#19 | Good First Issue