New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

define-commonjs

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

define-commonjs

Yet another CommonJS implementation

  • 1.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9
increased by28.57%
Maintainers
1
Weekly downloads
 
Created
Source

define-commonjs

NPM License Downloads

This is yet another CommonJS implementation.

Usage

<script src="define.js"></script>

<!-- Add define-async.js only if define.async is needed -->
<script src="define-async.js"></script>

<script src="bundle.js"></script>
// bundle.js is like this
define('a', function (require, exports, module) {
  module.exports = 'hello';
});

define('b', function (require, exports, module) {
  module.exports = 'world';
});

define('app', function (require, exports, module) {
  var a = require('a');
  var b = require('b');
  console.log(a + ', ' + b);
});

// define a dependency asynchronously, needs define-async.js
define.async('async/a', 'http://script/to/a.js');
define.async('async/b', function () {
  // should resolve the script code
  return getCodeFromSomewhereElse();
});

define.use('app');

Packing

Assume we have a project with three files:

// src/a.js
module.exports = 'hello';

// src/b.js
module.exports = 'world';

// src/app.js
var a = require('./a');
var b = require('./b');
console.log(a + ', ' + b);

Using gulp:

const pack = require('define-commonjs/pack/gulp');
const concat = require('gulp-concat');

gulp.task('pack', () => {
  const collect = pack();
  return gulp.src('src/*.js')
  .pipe(collect)
  .pipe(collect.pack({main: 'src/app.js'}))
  .pipe(concat())
  .pipe(gulp.dest('dist'));
});

gulp.task('pack-with-custom-paths', () => {
  const collect = pack();
  return gulp.src('src/*.js')
  .pipe(collect)
  .pipe(collect.pack({
    main: 'src/app.js',
    getPath(file) {
      // This is useful if we have changed files before packing, e.g. concat'ed.
      return file.relative === 'main.js' ? 'src/app.js' : file.path;
    },
  }))
  .pipe(concat())
  .pipe(gulp.dest('dist'));
});

Keywords

FAQs

Package last updated on 11 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc