Giter VIP home page Giter VIP logo

broccoli-dist-es6-module's People

Contributors

ryanflorence avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

broccoli-dist-es6-module's Issues

Any pointers on how I can consume CJS modules

I want to browserify a node module and use it in my ES6 code, which I'm then transpiling using broccoli-dist-es6-module. I can use globals to access the node code, but that feels gross. Can you offer any suggestions/pointers on how I can do this in a nicer way?

Cannot support both globals and named-amd when building ember components

I wanted to start a discussion regarding imports, multiple distribution targets, and side-effects.

Consider a library of components that you want to include in your ember-cli project. These components would be used in your application in the templates. This alone is achievable.

Import the library in the Brocfile

app.import('vendor/third-party-components/dist/named-amd/main.js', {
  'third-party-components': [
    'ThirdPartyComponentOne',
    'ThirdPartyComponentTwo'
  ]
});

Then it needs to be initialized in an initializer file.

import { 
  ThirdPartyComponentOne, 
  ThirdPartyComponentTwo 
} from 'third-party-components';

export default {
  name: 'thirdPartyComponents',
  initialize: function(container) {
    container.register('component:component-one', ThirdPartyComponentOne,
    container.register('component:component-two', ThirdPartyComponentTwo
  }
};

Perfect. This will work. In fact we can go one step further and introduce a default initializer for people who want to quickly use everything the way we named it.

import { initializer } from 'third-party-components';
export default initializer;

This is great for people using ember-cli and named-amd.

As the author of this library of components, I want to support people who are building ember apps with globals.

To do this, I would have to change the way I am authoring my main.js file.

import { 
  ThirdPartyComponentOne, 
  ThirdPartyComponentTwo 
} from 'third-party-components';
import Ember from 'ember';

Ember.Application.initializer({
  name: 'thirdPartyComponents',
  initialize: function(container) {
    container.register('component:component-one', ThirdPartyComponentOne,
    container.register('component:component-two', ThirdPartyComponentTwo
  }
});

This way, when the file is imported in the Brocfile, it will automatically be initialized.

This is great for people using globals.

The problem comes when I want to support both named-amd and globals.

The globals method works by initializing on evaluation. This doesn't jive well with the import export nature of modules. The initialization then happens as a side-effect of importing. This is an issue since ember apps throw errors when the same initializer is initialized twice.

I have currently settled on an unhappy compromise favoring globals. It looks like this:

// Components are initialized as a side-effect of import
// This is necessary for exporting components for both
// Globals and named-amd support
window.console.log('HACK!', BooleanInputComponent);

The build will only pass if I use that which I am importing. However, I am actually using what I am importing simply by importing it.

So here are the questions:

  1. Should initializing these components even be a part of what I am exporting?
  2. Is this es6 module the correct place to facilitate the need for differences between named-amd, globals, etc. builds?
  3. Is there a popular opinion regarding modules and side-effects?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.