Git Product home page Git Product logo

Comments (14)

CaryLandholt avatar CaryLandholt commented on May 10, 2024

Hi @jwall,

Using ngShim you no longer need an app file. It's created for you.
So you no longer need to do angular.module 'app', <%= config.modules %>.

When including modules other than app, you will need to add them to the modules section of ngShim.

As for constants, they can be treated just like any other module type.

# file:  src/scripts/constants/version.coffee
angular.module('app').constant 'version', '0.1'

Let me know if this works. I may need to tweak the ngShim grunt task a bit.
If you're interested, here it is.

Thanks,
Cary

from angularfun.

jwall avatar jwall commented on May 10, 2024

In order to get my code to work I modified ngShim so that it grabs my app template with the constants defined. If I don't do it that way the app.config module isn't loaded at the right time. I have tried a version.coffee and also putting the constants in the routes.coffee file, but both fail. (Follow-up: I can use a constants.coffee and not modify the app template, but I still need the additionalModules as described below to include app.config)

Also, because I have external js files loaded via a cdn, the modules array didn't work for me, i.e., I only have a key and no value. So, I added an additionalModules array to make sure the app gets the external js module dependencies.

Lastly, I have a js file that extends a module so there is no module but there is a js dependency.

All, very dirty for your clean setup, but I guess when you rely on third party source this can happen :-)

My ngShim:

ngShim:
  scripts:
    cwd: './.temp/scripts/'
    angular: 'libs/angular.min.js'
    angularFire: 'libs/angular-fire.js'
    appTemplatePath: '../../../src/scripts/libs/templates/app.tpl'
    additionalModules: ['app.config', 'firebase']
    modules: [
      'ngAnimate': 'libs/angular-animate.min.js'
      'ngResource': 'libs/angular-resource.min.js'
      'ngRoute': 'libs/angular-route.min.js'
    ]
    src: '**/*.coffee'
    dest: 'main.coffee'

where

angularFire: 'libs/angular-fire.js'

is the module extension (extends the firebase module).

appTemplatePath: '../../../src/scripts/libs/templates/app.tpl'

is to add the constants into the app directly.

additionalModules: ['app.config', 'firebase']

is to handle the external js modules.

from angularfun.

jwall avatar jwall commented on May 10, 2024

I refactored the ngShim portion a bit so now it looks like so:

ngShim:
  scripts:
    cwd: './.temp/scripts/'
    angular: 'libs/angular.min.js'
    externalModules: ['app.config', 'firebase']
    externalLibs: ['libs/angular-fire.js']
    modules: [
      'ngAnimate': 'libs/angular-animate.min.js'
      'ngResource': 'libs/angular-resource.min.js'
      'ngRoute': 'libs/angular-route.min.js'
      'ui.bootstrap': 'libs/ui-bootstrap-tpls.min.js'
    ]
    src: '**/*.coffee'
    dest: 'main.coffee'

so this lets you use modules that are externally loaded (and also my constants issue) and libs that extend a module.

from angularfun.

CaryLandholt avatar CaryLandholt commented on May 10, 2024

Can you clarify what you mean by "modules that are externally loaded"?

from angularfun.

jwall avatar jwall commented on May 10, 2024

I meant in the index.html as:

<script src="http://somecdn.com/somejavascriptmodule.js"></script>

or even referenced locally as:

<script src="/scripts/libs/somejavascriptmodule.js"></script>

from angularfun.

CaryLandholt avatar CaryLandholt commented on May 10, 2024

Neither non AngularJS nor external references are supported.
This would need to be added.

You should be able to do the following, however.

ngShim:
    scripts:
        cwd: './.temp/scripts/'
        angular: 'libs/angular.js'
        modules: [
            'ngAnimate': 'libs/angular-animate.min.js'
            'ngResource': 'libs/angular-resource.min.js'
            'ngRoute': 'libs/angular-route.min.js'
            'firebase': 'libs/angular-fire.js' # firebase is just another module and can be incorporated as such
        ]
        src: '**/*.coffee'
        dest: 'main.coffee'

from angularfun.

jwall avatar jwall commented on May 10, 2024

I thought they weren't supported which is why I made the ngShim modifications, but I wanted to make sure.

Thank you for your answers and for the great repo.

from angularfun.

CaryLandholt avatar CaryLandholt commented on May 10, 2024

There are two things not supported yet.

  1. Loading non AngularJS files (e.g. jQuery) in a specific order. For example, guarantee that jQuery loads prior to Angular.
  2. Loading files from a CDN (i.e. http://mycdn.com/angular.js).

If you are only consuming local Angular files, you're good. :)

Thanks!

from angularfun.

maru1034sk avatar maru1034sk commented on May 10, 2024

I want to use "restangular". It has "underscore" as a dependency. What's the correct way to load this module?

    modules: [
      'ngAnimate': 'libs/angular-animate.min.js'
      'ngResource': 'libs/angular-resource.min.js'
      'ngRoute': 'libs/angular-route.min.js'
      'underscore': 'libs/underscore-min.js'
      'restangular': 'libs/restangular.min.js'
    ]

This isn't working, because underscore isn't an angularjs-module.

from angularfun.

CaryLandholt avatar CaryLandholt commented on May 10, 2024

Hi Angelo,

I had to refactor the grunt plugin to allow for non-Angular dependencies.
Although ngShim was just introduced, some users are using it already.
So, here comes shimmer, which is an Angular-agnostic RequireJS main file builder. But there is a bit of Angular magic (see NGMODULES, NGAPP, NGBOOTSTRAP).

shimmer:
    scripts:
        cwd: './.temp/scripts/'
        src: [
            '**/*.{coffee,js}'
            '!libs/angular.{coffee,js}'
            '!libs/angular-animate.{coffee,js}'
            '!libs/angular-resource.{coffee,js}'
            '!libs/angular-route.{coffee,js}'
            '!libs/html5shiv-printshiv.{coffee,js}'
            '!libs/json3.min.{coffee,js}'
            '!libs/require.{coffee,js}'
        ]
        order: [
            [
                'libs/angular.min.js'
                'libs/lodash.min.js'
            ]
            'NGMODULES':
                'ngAnimate': 'libs/angular-animate.min.js'
                'ngResource': 'libs/angular-resource.min.js'
                'ngRoute': 'libs/angular-route.min.js'
                'restangular': 'libs/restangular.min.js'
            'NGAPP'
        ]
        require: 'NGBOOTSTRAP'

As you can see, lodash (underscore) was added to an array along with Angular. This allows lodash and Angular to load in any order. But the next object will load after both Angular and lodash.

For example, if the order configuration were as follows, Angular would load before lodash.

order: [
    'libs/angular.min.js'
    'libs/lodash.min.js'
    'NGMODULES':
        'ngAnimate': 'libs/angular-animate.min.js'
        'ngResource': 'libs/angular-resource.min.js'
        'ngRoute': 'libs/angular-route.min.js'
        'restangular': 'libs/restangular.min.js'
    'NGAPP'
]

Don't forget to add restangular to the bower.json file.

Don't forget to add restangular and lodash to the copy.app.files array.

    cwd: './bower_components/restangular/dist/'
    src: 'restangular.min.js'
    dest: './.temp/scripts/libs/'
    expand: true
,
    cwd: './bower_components/lodash/dist/'
    src: 'lodash.min.js'
    dest: './.temp/scripts/libs/'
    expand: true

I hope this helps,
Cary

from angularfun.

maru1034sk avatar maru1034sk commented on May 10, 2024

Hey Cary,

That sounds awesome. This new way looks very solid. I'll try it out as soon as I have some time.

Thank you very much :3

from angularfun.

CaryLandholt avatar CaryLandholt commented on May 10, 2024

Cool - please let me know if it does the trick!

from angularfun.

jwall avatar jwall commented on May 10, 2024

The new shimmer works well for me. I don't need my grunt-hustler fork anymore!

One other note is to remember to add dependencies to karma.unit.files array as well.

from angularfun.

CaryLandholt avatar CaryLandholt commented on May 10, 2024

@jwall, you're right - I'd like to create the main file for karma automatically as well.

from angularfun.

Related Issues (20)

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.