Skip to content

Commit 3adda7b

Browse files
committed
Added webpack sample. Closes #38.
1 parent dbf46d0 commit 3adda7b

File tree

11 files changed

+160
-0
lines changed

11 files changed

+160
-0
lines changed

.jshintignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ appengine/kraken/public/components/**
22
appengine/sails/config/**
33
appengine/sails/tasks/**
44
appengine/sails/assets/**
5+
appengine/webpack/dist/**
56
**/node_modules/**
67
coverage/

appengine/webpack/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/

appengine/webpack/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## Express.js + Webpack on Google App Engine
2+
3+
> [Webpack][1] is a module bundler
4+
>
5+
> – webpack.github.io
6+
7+
This sample application demonstrates how to use [Webpack][1] to bundle frontend
8+
code and then serve it with [Express.js][2] on Google App Engine.
9+
10+
[1]: http://webpack.github.io/
11+
[2]: http://expressjs.com/

appengine/webpack/app.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2015, Google, Inc.
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
runtime: nodejs
14+
vm: true

appengine/webpack/package.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "appengine-webpack",
3+
"description": "An example of using Webpack with Node.js on Google App Engine.",
4+
"version": "0.0.1",
5+
"private": true,
6+
"license": "Apache Version 2.0",
7+
"engines": {
8+
"node": "~4.2"
9+
},
10+
"scripts": {
11+
"bundle": "webpack --config webpack.config.js",
12+
"prestart": "npm run bundle",
13+
"start": "node server.js",
14+
"deploy": "gcloud preview app deploy app.yaml"
15+
},
16+
"dependencies": {
17+
"express": "^4.13.3",
18+
"jade": "^1.11.0",
19+
"webpack": "^1.12.6"
20+
}
21+
}

appengine/webpack/public/app.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2015, Google, Inc.
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
/* global document:true */
15+
'use strict';
16+
17+
var foo = require('./foo.js');
18+
19+
document.getElementById('module-name').innerText = foo.name;

appengine/webpack/public/foo.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2015, Google, Inc.
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
'use strict';
15+
16+
module.exports = {
17+
name: 'foo'
18+
};

appengine/webpack/server.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2015, Google, Inc.
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
'use strict';
15+
16+
var express = require('express');
17+
var path = require('path');
18+
19+
var app = express();
20+
21+
// Setup view engine
22+
app.set('view engine', 'jade');
23+
24+
app.use(express.static(__dirname + '/dist'));
25+
26+
app.get('/', function(req, res) {
27+
res.render('index');
28+
});
29+
30+
var server = app.listen(
31+
process.env.PORT || 8080,
32+
'0.0.0.0',
33+
function () {
34+
var address = server.address().address;
35+
var port = server.address().port;
36+
console.log('App listening at http://%s:%s', address, port);
37+
console.log('Press Ctrl+C to quit.');
38+
}
39+
);

appengine/webpack/views/index.jade

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2015, Google, Inc.
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
doctype html
15+
html
16+
head
17+
title= title
18+
body
19+
h1 Hello World!
20+
p Express.js + Webpack on Google App Engine.
21+
hr
22+
p Loaded module <span id="module-name"></span> via Webpack.
23+
script(type='text/javascript', src='app.js')

appengine/webpack/webpack.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
entry: './public/app.js',
3+
output: {
4+
filename: './dist/app.js'
5+
}
6+
};

test/appengine/all.test.js

+7
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ var sampleTests = [
102102
args: ['server.js'],
103103
msg: 'Hello World! Restify.js on Google App Engine.',
104104
TRAVIS_NODE_VERSION: 'stable'
105+
},
106+
{
107+
dir: 'webpack',
108+
deploy: false,
109+
cmd: 'node',
110+
args: ['server.js'],
111+
msg: 'Loaded module <span>foo</span> via Webpack.'
105112
}
106113
];
107114

0 commit comments

Comments
 (0)