Skip to content

Commit

Permalink
Merge pull request #39 from GoogleCloudPlatform/webpack
Browse files Browse the repository at this point in the history
Added webpack sample. Closes #38.
  • Loading branch information
jmdobry committed Nov 20, 2015
2 parents 8b8cd98 + 3adda7b commit 9e0d3d8
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 0 deletions.
1 change: 1 addition & 0 deletions .jshintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ appengine/kraken/public/components/**
appengine/sails/config/**
appengine/sails/tasks/**
appengine/sails/assets/**
appengine/webpack/dist/**
**/node_modules/**
coverage/
1 change: 1 addition & 0 deletions appengine/webpack/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
11 changes: 11 additions & 0 deletions appengine/webpack/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Express.js + Webpack on Google App Engine

> [Webpack][1] is a module bundler
>
> – webpack.github.io
This sample application demonstrates how to use [Webpack][1] to bundle frontend
code and then serve it with [Express.js][2] on Google App Engine.

[1]: http://webpack.github.io/
[2]: http://expressjs.com/
14 changes: 14 additions & 0 deletions appengine/webpack/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2015, Google, Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
runtime: nodejs
vm: true
21 changes: 21 additions & 0 deletions appengine/webpack/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "appengine-webpack",
"description": "An example of using Webpack with Node.js on Google App Engine.",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"engines": {
"node": "~4.2"
},
"scripts": {
"bundle": "webpack --config webpack.config.js",
"prestart": "npm run bundle",
"start": "node server.js",
"deploy": "gcloud preview app deploy app.yaml"
},
"dependencies": {
"express": "^4.13.3",
"jade": "^1.11.0",
"webpack": "^1.12.6"
}
}
19 changes: 19 additions & 0 deletions appengine/webpack/public/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2015, Google, Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/* global document:true */
'use strict';

var foo = require('./foo.js');

document.getElementById('module-name').innerText = foo.name;
18 changes: 18 additions & 0 deletions appengine/webpack/public/foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2015, Google, Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

module.exports = {
name: 'foo'
};
39 changes: 39 additions & 0 deletions appengine/webpack/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2015, Google, Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

var express = require('express');
var path = require('path');

var app = express();

// Setup view engine
app.set('view engine', 'jade');

app.use(express.static(__dirname + '/dist'));

app.get('/', function(req, res) {
res.render('index');
});

var server = app.listen(
process.env.PORT || 8080,
'0.0.0.0',
function () {
var address = server.address().address;
var port = server.address().port;
console.log('App listening at http://%s:%s', address, port);
console.log('Press Ctrl+C to quit.');
}
);
23 changes: 23 additions & 0 deletions appengine/webpack/views/index.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2015, Google, Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
doctype html
html
head
title= title
body
h1 Hello World!
p Express.js + Webpack on Google App Engine.
hr
p Loaded module <span id="module-name"></span> via Webpack.
script(type='text/javascript', src='app.js')
6 changes: 6 additions & 0 deletions appengine/webpack/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
entry: './public/app.js',
output: {
filename: './dist/app.js'
}
};
7 changes: 7 additions & 0 deletions test/appengine/all.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ var sampleTests = [
args: ['server.js'],
msg: 'Hello World! Restify.js on Google App Engine.',
TRAVIS_NODE_VERSION: 'stable'
},
{
dir: 'webpack',
deploy: false,
cmd: 'node',
args: ['server.js'],
msg: 'Loaded module <span>foo</span> via Webpack.'
}
];

Expand Down

0 comments on commit 9e0d3d8

Please sign in to comment.