2.0.5 • Published 4 years ago

qp-define v2.0.5

Weekly downloads
6
License
MIT
Repository
github
Last release
4 years ago

npm license npm version dependency status

server

> npm install qp-define --save

browser

<script src="qp-define.min.js"></script>

why?

  • simple module system which works on both client and server
  • leaves dependency management alone
  • minimal additional syntax

usage

  • require('qp-define') to introduce a global define function.
  • define a module and call exports with the result.
  • require core modules in the normal way.
  • ensure modules are loaded in dependency order on the client.

optional

  • on the server add keys for other locations which contain modules you want to use.
  • local is predefined as path.dirname(require.main.filename), this is only useful for files in a node based project which won't be shared outside of the project. the define.path.local reference is useful for referencing the local project whilst keeping it externally available.
  • require works in the normal way with the addition of predefined paths. predefined paths are accessed by prefixing the path name, eg var my_module = require('pathname/my_module')

example

// ./main.js
var path = require('path');

define = require('qp-define');
define.path('project_a', define.path.local);
define.path('user_modules', path.join(__dirname, '..', 'user_modules'));

define(module, function(exports, require) {

  var example0 = require('local/example0');
  var example1 = require('project_a/example1');
  var example2 = require('user_modules/example2');

  example0.run();
  example1.run();
  example2.run();

});
// ./example0.js
define(module, function(exports, require) {

  exports('example0', {

    run: function() {
      console.log('example0.run');
    }

  });

});
// ./example1.js
define(module, function(exports, require) {

  exports('project_a/example1', {

    run: function() {
      console.log('example1.run');
    }

  });

});
// ./../user_modules/example2/index.js
define(module, function(exports, require) {

  var path = require('path');

  exports('user_modules/example2', {

    run: function() {
      console.log('example2.run');
    }

  });

});
2.0.5

4 years ago

2.0.4

5 years ago

2.0.2

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.2.19

8 years ago

1.2.18

8 years ago

1.2.17

9 years ago

1.2.16

9 years ago

1.2.15

9 years ago

1.2.14

9 years ago

1.2.13

9 years ago

1.2.12

9 years ago

1.2.11

9 years ago

1.2.10

9 years ago

1.2.9

9 years ago

1.2.8

9 years ago

1.2.7

9 years ago

1.2.6

10 years ago

1.2.5

10 years ago

1.2.4

10 years ago

1.2.2

10 years ago

1.2.1

10 years ago

1.2.0

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago