Skip to content

Commit

Permalink
feature(dist): implements a workaround for webpack/webpack#5316
Browse files Browse the repository at this point in the history
fixes #45
  • Loading branch information
sverweij committed Jan 3, 2018
1 parent 932289c commit 5460306
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 6 deletions.
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ GIT=git
NPM=npm
MAKEDEPEND=node_modules/.bin/js-makedepend --output-to jsdependencies.mk --exclude "node_modules|doc"
LODASH=node_modules/.bin/lodash
RJS=node_modules/requirejs/bin/r.js

PARSERS=parse/mscgenparser.js \
parse/msgennyparser.js \
Expand All @@ -14,7 +15,7 @@ GENERATED_SOURCES=$(PARSERS) \
render/graphics/csstemplates.js
LIBDIRS=lib/lodash

.PHONY: help dev-build install deploy-gh-pages check fullcheck mostlyclean clean lint cover prerequisites report test update-dependencies run-update-dependencies depend bower-package
.PHONY: help dist dev-build install deploy-gh-pages check fullcheck mostlyclean clean lint cover prerequisites report test update-dependencies run-update-dependencies depend bower-package

help:
@echo " --------------------------------------------------------"
Expand Down Expand Up @@ -94,6 +95,16 @@ prerequisites:

dev-build: $(GENERATED_SOURCES) .npmignore

dist: dev-build node_modules/almond/almond.js
mkdir -p dist
$(RJS) -o baseUrl=. \
name=node_modules/almond/almond \
include=index \
out=dist/mscgen.js \
wrap.startFile=almond.start.frag \
wrap.endFile=almond.end.frag \
preserveLicenseComments=true

lint:
$(NPM) run lint

Expand Down
6 changes: 6 additions & 0 deletions almond.end.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//The modules for your project will be inlined above
//this snippet. Ask almond to synchronously require the
//module value for 'main' here and return it as the
//value to use for the public API for the built file.
return require('index');
}));
14 changes: 14 additions & 0 deletions almond.start.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
//Allow using this built library as an AMD module
//in another project. That other project will only
//see this AMD call, not the internal modules in
//the closure below.
define([], factory);
} else {
//Browser globals case. Just assign the
//result to a property on the global.
root.mscgen = factory();
}
}(this, function () {
//almond, and your modules will be inlined here
37 changes: 37 additions & 0 deletions dist/mscgen.js

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions doc/samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ with mscgenjs.

- [`sample-webpack.html`](sample-webpack.html)
a page with a textarea, a few buttons and a div for
putting the output in.
putting the output in.
- [`sample-webpack.js`](sample-webpack.js)
Sets up some listeners that (a.o.) call mscgenjs' render function with
the textarea as input
the textarea as input.
> Note that this does not `require` the root module
but `dist/mscgen.js` in stead. This is a workaround for
[webpack issue #5316](https://github.com/webpack/webpack/issues/5316),
which makes that webpack 3 can't work with amdefine.
- `sample-webpack.bundle.js`
The webpack bundle actually included in _sample-webpack.html_. It's not
included in the repo but it's easy to generate it from app.js:
Expand All @@ -21,8 +25,11 @@ with mscgenjs.
# when you don't have webpack installed yet do that first:
npm install --global webpack

# generate the bundle
webpack --optimize-minimize sample-webpack.js sample-webpack.bundle.js
# change to this directory
cd doc/samples

# generate the bundle; it'll now use the webpack.config.js in doc/samples
webpack
```

## An AMD example (using requirejs)
Expand Down
3 changes: 2 additions & 1 deletion doc/samples/sample-webpack.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var mscgenjs = require('../../');
// var mscgenjs = require('../../dist/mscgen').mscgen;
var mscgenjs = require('../../dist/mscgen');

function render(){
// clear the target area before rendering on it
Expand Down
11 changes: 11 additions & 0 deletions doc/samples/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

module.exports = (pEnv = 'prod') => {
const lRetval = {
entry: './sample-webpack.js'
};

lRetval.output = {filename : './sample-webpack.bundle.js'}
lRetval.devtool = "source-map";

return lRetval;
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"requirejs": "2.3.5"
},
"devDependencies": {
"almond": "0.3.3",
"chai": "4.1.2",
"chai-xml": "0.3.1",
"dependency-cruiser": "2.9.0",
Expand Down

0 comments on commit 5460306

Please sign in to comment.