Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added webpack sample. Closes #38. #39

Merged
merged 1 commit into from
Nov 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we looking to explain this stuff in the readme, or moving it all to c.g.c/nodejs now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to make a page for it in c.g.c./nodejs

"start": "node server.js",
"deploy": "gcloud preview app deploy app.yaml"
},
"dependencies": {
"express": "^4.13.3",
"jade": "^1.11.0",
"webpack": "^1.12.6"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this as a runtime dependency or dev dependency?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the runtime doesn't install dev deps, afaik.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep...kind of a funky part of the runtime when users are used to installing development dependencies as devDependencies, but with MVMs everything has to be in dependencies.

}
}
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');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mr. t

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who are these foo's, and why is everyone fighting them


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