I got a errors,
"Error: Cannot find module 'events'"
"TypeError: undefined is not a constructor (evaluating 'new BpmnViewer({ container: '#canvas' })')"
And the code,
package.json
{
"name": "bpmn-js-custom-bundle",
"version": "0.0.0",
"description": "Create custom bower bundles of bpmn-js",
"devDependencies": {
"grunt": "^0.4.4",
"grunt-browserify": "^3.3.0"
},
"dependencies": {
"bpmn-js": "^0.15.0",
"diagram-js": "^0.15.0",
"bpmn-js-properties-panel": "^0.7.0"
}
}
index.js
// get bpmn-js
var BpmnViewer = require('bpmn-js/lib/Viewer');
// load additional modules
var additionalModules = [
require('bpmn-js-properties-panel'),
require('bpmn-js-properties-panel/lib/provider/bpmn'),
];
// add additional (default!) modules to bpmn-js
BpmnViewer.prototype._modules = BpmnViewer.prototype._modules.concat(additionalModules);
// export
module.exports = BpmnViewer;
Gruntfile.js
'use strict';
module.exports = function(grunt) {
// project configuration
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
browserify: {
// create customized bower bundle
bower: {
files: {
'dist/bpmn-viewer-custom.js': [ 'index.js' ]
},
options: {
browserifyOptions: {
standalone: 'BpmnJS',
// make sure we do not include browser shims unnecessarily
builtins: false,
insertGlobalVars: {
process: function () {
return 'undefined';
},
Buffer: function () {
return 'undefined';
}
}
}
}
}
}
});
grunt.loadNpmTasks('grunt-browserify');
grunt.registerTask('default', [ 'browserify:bower' ]);
};
app.js
'use strict';
// we use $.ajax to load the diagram.
// make sure you run the application via web-server (ie. connect (node) or asdf (ruby))
// require the viewer, make sure you added the bpmn-js bower distribution
// along with all its dependencies to the web site
var BpmnViewer = window.BpmnJS;
var viewer = new BpmnViewer({ container: '#canvas' });
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
viewer.importXML(xhr.response, function(err) {
if (!err) {
console.log('success!');
viewer.get('canvas').zoom('fit-viewport');
} else {
console.log('something went wrong:', err);
}
});
}
};
xhr.open('GET', 'pizza-collaboration.bpmn', true);
xhr.send(null);
app.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<style>
html, body, #canvas {
height: 100%
}
</style>
<!--
this is an example of how to use bpmn-js in a standalone application built with
bower-bpmn-js
-->
<title>bpmn-js bower example - bpmn-js-examples</title>
</head>
<body>
<h1>Pizza Collaboration Viewer</h1>
<div id="canvas"></div>
<!-- viewer -->
<script src="dist/bpmn-viewer-custom.js"></script>
<!-- app -->
<script src="./app.js"></script>
</body>
</html>
Have any mistakes in the code? anybody help me, thank you!