2.0.5 • Published 3 years ago

qp-define v2.0.5

Weekly downloads
6
License
MIT
Repository
github
Last release
3 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

3 years ago

2.0.4

4 years ago

2.0.2

6 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.2.19

7 years ago

1.2.18

7 years ago

1.2.17

8 years ago

1.2.16

8 years ago

1.2.15

8 years ago

1.2.14

8 years ago

1.2.13

8 years ago

1.2.12

8 years ago

1.2.11

8 years ago

1.2.10

8 years ago

1.2.9

8 years ago

1.2.8

8 years ago

1.2.7

8 years ago

1.2.6

8 years ago

1.2.5

8 years ago

1.2.4

8 years ago

1.2.2

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago