Skip to content

Commit 07fa657

Browse files
committed
feature: allow custom result types
adds built-in result types: html, jsx and plain. Default is html. new example using react.js Fixes #9
1 parent ea2a5a4 commit 07fa657

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1066
-193
lines changed

bin/startExpressApp.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
__DIRNAME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
3+
$__DIRNAME/../examples/express-app-using-result-json/bin/www

bin/startReactTutorial.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
__DIRNAME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
3+
node "$__DIRNAME/../examples/react-tutorial/server.js"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// default result type is "html"
2+
3+
module.exports = {
4+
bundle: {
5+
base: {
6+
scripts: './scripts/base.js',
7+
styles: './styles/base.css',
8+
options: {
9+
rev: false,
10+
uglify: false, // this has to be false, otherwise uglify will blow up when trying to parse a .jsx file
11+
result: {
12+
type: {
13+
scripts: 'jsx',
14+
styles: 'html'
15+
}
16+
}
17+
}
18+
},
19+
default: {
20+
scripts: './scripts/default.js',
21+
styles: './styles/default.css',
22+
options: {
23+
rev: false,
24+
result: {
25+
type: 'html' // applies to both scripts and styles
26+
}
27+
}
28+
},
29+
plain: {
30+
scripts: './scripts/plain.js',
31+
styles: './styles/plain.css',
32+
options: {
33+
rev: false,
34+
result: {
35+
type: 'plain'
36+
}
37+
}
38+
},
39+
custom: {
40+
scripts: './scripts/custom.js',
41+
styles: './styles/custom.css',
42+
options: {
43+
rev: false,
44+
result: {
45+
type: {
46+
scripts: function xJavascript(path) {
47+
return "<script async src='" + path + "' type='application/javascript'></script>";
48+
},
49+
styles: function html(path) {
50+
return "<link href='" + path + "' type='text/html'/>";
51+
}
52+
}
53+
}
54+
}
55+
}
56+
}
57+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"base": {
3+
"scripts": "<script src='/public/base.js' type='text/jsx'></script>",
4+
"styles": "<link href='/public/base.css' media='screen' rel='stylesheet' type='text/css'/>"
5+
},
6+
"plain": {
7+
"scripts": "/public/plain.js",
8+
"styles": "/public/plain.css"
9+
},
10+
"default": {
11+
"styles": "<link href='/public/default.css' media='screen' rel='stylesheet' type='text/css'/>",
12+
"scripts": "<script src='/public/default.js' type='text/javascript'></script>"
13+
},
14+
"custom": {
15+
"scripts": "<script async src='/public/custom.js' type='application/javascript'></script>",
16+
"styles": "<link href='/public/custom.css' type='text/html'/>"
17+
}
18+
}

examples/custom-result/gulpfile.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var gulp = require('gulp'),
2+
rimraf = require('gulp-rimraf'),
3+
bundle = require('../../');
4+
5+
gulp.task('bundle', ['clean'], function () {
6+
return gulp.src('./bundle.config.js')
7+
.pipe(bundle())
8+
.pipe(bundle.results({
9+
pathPrefix: '/public/'
10+
}))
11+
.pipe(gulp.dest('./public'));
12+
});
13+
14+
gulp.task('clean', function () {
15+
return gulp.src('./public', { read: false })
16+
.pipe(rimraf());
17+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "custom-result",
3+
"version": "0.0.0",
4+
"description": "",
5+
"main": "",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "MIT",
11+
"devDependencies": {
12+
"gulp": "^3.8.7",
13+
"gulp-rimraf": "^0.1.0"
14+
}
15+
}

examples/custom-result/public/base.css

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/custom-result/public/base.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/custom-result/public/custom.css

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/custom-result/public/custom.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)