npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

grunt-re-define

v0.5.3

Published

anything to anything converter

Downloads

9

Readme

grunt-redefine

Grunt task for re-define

Usage

var includeExternal = require('re-define-include-external')
  , redefine = require('re-define')
  , fs = require('fs')

module.exports = function(grunt) {

  grunt.registerTask('default', ['demo'])
  grunt.registerTask('demo', ['redefine:my-component'])

  grunt.initConfig({
    redefine: {
      "my-component": {
          project: 'demo' //optional, when not defined target (i.e. my-component) will be taken
        , returns : 'demo/main.js'
        , wrapper: 'umd'
        , base: '/lib'
        , names: { amd:"ns/my-component", global:"ns.my_component"}

        //import namespaces and exclude internal modules
        //when object { 'window': ['d3'], 'custom.ns': ['custom/**'] }
        //or an array ['window', etc...]
        //namespace - global, reachable by internal require function within module
        , imports: { "window": ['d3'] } 

        //if you've got some AMD plugins which need to be removed when trying to make lib cross compatibile
        , excludeAMDModules: ['\.css$', 'domReady!']

        //mapping, internal require('jquery') -> (to) global = parent.core.jquery
        //by default everything is attached to parent, in most cases window
        , globals: {jquery:"core.jquery"}

        //safe global for internal modules
        //var my = my || {}; my.component = ...
        , namespace: "my.component"

        , showWarnings: false
        , development: true//enable/disable cache for faster builds
        , transforms: [
            includeExternal({
                skip: ['d3', 'jquery']
              , external: { external1:"/external/external1.js" }
            }),
            wrap({
              './examples/first/lib/one.js': '(function () {})()'
            })
        ]
        , src: ['./lib/main.js']
        , cwd: './examples/first'
        , dest : './examples/first/out.js'
      },
    }
  })

  grunt.loadTasks('tasks')
}

Conditional builds

To run conditional builds / config overrides, you have to provide builds params as follows (keys are arbitrary)

  'my-component': {
    ...
    builds: {
      development: {
        development: true//enable/disable cache for faster builds
      , showWarnings: true
      , wrapper: 'custom'
      , dest: './examples/first/out.development.js'
      },
      production: {
        development: false
      , showWarnings: false
      , wrapper: 'umd'
      , dest: './examples/first/out.production.js'
      }
    }
  }

Normal mode is run by default, to define normal mode as grunt task we would go with 'redefine:my-component', however to run custom build you have to add extra parameter to grunt task name, like redefine:my-component:development' or redefine:my-component:production'

Configuration

  { names         : { amd: 'amd/name', global: 'global.name' }
  , project       : '' //project name, adding a prefix to internal module name
  , returns       : ''
  , globals      : {} //external {lib:global}

  //working directory
  , cwd           : '.'
  //define cutting points for modules { glob_pattern: file, ... }
  , slice         : {"**/**": "bundle.js"}
  //could be a folder (in case of many files) or just file, when not defined print output to console
  , output        : ''
  //base folder, all modules will be aligned to this one, like cwd: a, file: a/b/c, base: a/b, file -> c
  , base          : ''
  //wrapper file 
  , wrapper       : 'default'
  //attach all bundled modules to namespace, foo.baz.bar is allowed
  , namespace: '' 
  //skip dependencies from externals (won't be included in wrapper as external for all module definition, assume that dep will be taken from namespace)
  , exclude: []
  //exclude specific AMD dependencies
  , excludeAMDModules : ['\.css$', 'require', 'modules', 'exports']
  //regexp to detect an AMD plugins, first we need to remove the plugin prefix to get a path
  , plugins      : ['^(text\/?)*!']
  //when name for dependency will resolved it will treat modules inside those folders as external
  , discoverable : ['bower_components', 'node_modules']
  //import namespaces, if you need to take some deps from exported namespace
  , imports: []
  //remap require calls, helpful when some libs have different reference to the same module
  , map: {}
  //js extensions, needed for filename.with.dots.js
  , jsExt: ['.js']
  //check existence of main/dir file when referencing a dir, like require('folder') = folder/index.js
  , dirExpanders: ['index.js']
  //when project is missing, inserting current folder as a prefix for modules
  , autoInsertFolder: true
  //format for escodegen
  , format: {
      indent: { style: '  ', base: 2 },
      space: ' ',
      compact: false,
      safeConcatenation: false
    }
  //export __filename, __dirname
  , exportPaths: false 
  , showWarnings: false
  , tempFolder: './.tmp'
  , autoCacheClean: false
  , development: true
  }

Custom template

Here you can find predefined ones.

module.exports = function(grunt) {

  grunt.initConfig({
    redefine: {
      options: { 
        wrappers: { 
          custom: fs.readFileSync('./examples/first/custom.tmpl')
        }
      }
      ...
    }
  })
}

Debug

DEBUG=re-define:* grunt