Skip to content

Commit

Permalink
Basic install of webpack+react lightly over the top of the default gr…
Browse files Browse the repository at this point in the history
…unt process.
  • Loading branch information
ashleysimons committed May 22, 2017
1 parent 8183b6a commit e862788
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 80 deletions.
16 changes: 16 additions & 0 deletions assets/js/index.jsx
@@ -0,0 +1,16 @@
import React from 'react';
import ReactDOM from 'react-dom';

const { render } = ReactDOM;

class HelloWorld extends React.Component {
render() {
return (
<div>Hello World</div>
);
};
}

render (
<HelloWorld/>, document.getElementById("react-container")
);
15 changes: 13 additions & 2 deletions package.json
Expand Up @@ -5,6 +5,7 @@
"description": "a Sails application",
"keywords": [],
"dependencies": {
"babel-polyfill": "^6.23.0",
"ejs": "2.3.4",
"grunt": "1.0.1",
"grunt-contrib-clean": "1.0.0",
Expand All @@ -20,6 +21,8 @@
"grunt-sync": "0.5.2",
"include-all": "^1.0.0",
"rc": "1.0.1",
"react": "^15.5.4",
"react-dom": "^15.5.4",
"sails": "~0.12.13",
"sails-disk": "~0.10.9"
},
Expand All @@ -33,5 +36,13 @@
"url": "git://github.com/admin/sails-react-example.git"
},
"author": "admin",
"license": ""
}
"license": "",
"devDependencies": {
"babel-core": "^6.24.1",
"babel-loader": "^7.0.0",
"babel-preset-env": "^1.4.0",
"babel-preset-react": "^6.24.1",
"grunt-webpack": "^3.0.0",
"webpack": "^2.5.1"
}
}
5 changes: 3 additions & 2 deletions tasks/config/copy.js
Expand Up @@ -26,9 +26,9 @@ module.exports = function(grunt) {
files: [{
expand: true,
cwd: './assets',
src: ['**/*.!(coffee|less)'],
src: ['**/*.!(coffee|less|jsx)'],
dest: '.tmp/public'
}]
}],
},
build: {
files: [{
Expand All @@ -42,3 +42,4 @@ module.exports = function(grunt) {

grunt.loadNpmTasks('grunt-contrib-copy');
};

33 changes: 33 additions & 0 deletions tasks/config/webpack.js
@@ -0,0 +1,33 @@
const path = require('path');
const BASE_DIR = path.resolve(__dirname, '../..');
const BUILD_DIR = path.resolve(__dirname, '../../', '.tmp/public/js');
const APP_DIR = path.resolve(__dirname, '../../', 'assets/js');

module.exports = function(grunt) {

grunt.config.set('webpack', {
dev: {
context: BASE_DIR,
entry: ['babel-polyfill', APP_DIR + '/index.jsx'],
output: {
path: BUILD_DIR,
filename: 'bundle.js'
},
module: {
loaders: [
{
test: /\.jsx?/,
include: APP_DIR,
loader: 'babel-loader',
options: {
presets: ["env", "react"]
}
}
]
}
}
});

grunt.loadNpmTasks('grunt-webpack');

};
3 changes: 2 additions & 1 deletion tasks/register/compileAssets.js
Expand Up @@ -17,6 +17,7 @@ module.exports = function(grunt) {
'jst:dev',
'less:dev',
'copy:dev',
'coffee:dev'
'coffee:dev',
'webpack:dev'
]);
};
3 changes: 2 additions & 1 deletion tasks/register/syncAssets.js
Expand Up @@ -15,6 +15,7 @@ module.exports = function(grunt) {
'jst:dev',
'less:dev',
'sync:dev',
'coffee:dev'
'coffee:dev',
'webpack:dev'
]);
};
75 changes: 1 addition & 74 deletions views/homepage.ejs
@@ -1,74 +1 @@
<!-- Default home page -->
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400italic,600' rel='stylesheet' type='text/css'>
<style>
/* Styles included inline since you'll probably be deleting this page anyway */
html,body{text-align:left;font-size:1em}html,body,img,form,textarea,input,fieldset,div,p,div,ul,li,ol,dl,dt,dd,h1,h2,h3,h4,h5,h6,pre,code{margin:0;padding:0}ul,li{list-style:none}img{display:block}a img{border:0}a{text-decoration:none;font-weight:normal;font-family:inherit}*:active,*:focus{outline:0;-moz-outline-style:none}h1,h2,h3,h4,h5,h6{font-weight:normal}div.clear{clear:both}.clearfix:after{clear:both;content:".";display:block;font-size:0;height:0;line-height:0;visibility:hidden}body{font-family:"Open Sans",Arial,sans-serif;font-weight:300;}.top-bar {width: 100%; background-color: #e4f0f1; padding: 15px 0;}.top-bar .container img {float: left;}.top-bar .container ul {float: right; padding-top: 25px;}.top-bar .container li {float: left; width: 125px; text-align: center; font-size: 15px; color:#000; font-weight: 600;}.top-bar .container a li:hover {color: #118798; -webkit-transition:color 200ms; -moz-transition:color 200ms; -o-transition:color 200ms;transition:color 200ms;}.container{width: 80%; max-width: 1200px; margin: auto;}div.header {-webkit-transition: 6s; -moz-transition: 6s; -o-transition: 6s;transition: 6s; background: rgba(4, 36, 41, 0.89) url(http://sailsjs.org/images/img_sailsShadow.png) no-repeat 42% bottom; padding: 100px 0 65px;}.header h1#main-title{color: #fff; font-weight: 300; font-size: 2.5em;}.header h3{color: #b1eef7; font-style: italic; font-weight: 300;}.header h3 code{font-style: normal!important; background-color: rgba(255,255,255,0.5); font-weight: 300; color:#0e6471; margin: 0px 5px;}div.main.container{padding: 50px 0;}h1 {color: #118798; font-weight: 300;}code {font-size: inherit; font-family: 'Consolas', 'Monaco', monospace; padding:4px 5px 1px; background-color: #f3f5f7}a{color: #118798; font-weight: 300; text-decoration: underline;}a:hover {color: #0e6471; -webkit-transition:color 200ms; -moz-transition:color 200ms; -o-transition:color 200ms;transition:color 200ms;}p{line-height: 1.5em;}blockquote{background-color: #e4f0f1; padding: 25px; line-height: 1.5em; margin: 15px 0;}blockquote span{font-weight: 600; padding-right: 5px;}ul.getting-started{padding: 25px 75px 25px 0; width: 70%; float: left; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;}ul.getting-started li{padding: 25px 0;}ul.getting-started li h3 {padding-bottom: 10px; font-size: 25px; font-weight: 300;}.sprite{background:url(http://sailsjs.org/images/newapp.sprite.png) no-repeat; position: absolute; left: 0; top:0;}.getting-started .sprite{margin-left:10px;padding-left:60px;height:42px;width:0; float: left;}.getting-started .one{background-position:0 0}.getting-started .two{background-position:0 -42px}.getting-started .three{background-position:0 -83px}div.step {position: relative; padding-left: 70px; opacity: 0.9;}div.step:hover{ opacity: 1;}div.links {float: left; width: 30%; max-width: 325px; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; background-color: #f3f5f7; border: 1px solid #ebebeb; padding: 25px 45px 35px;}div.links h3 {color: #727272; text-align: center; font-size: 28px; font-weight: 300;}div.links h4 {color: #727272; font-size: 17px; font-weight: 600; padding: 15px 0 10px;}div.links .link-list a {text-decoration: none; font-weight: 400;}div.links .link-list a li {padding: 0px 0px 5px 10px;}div.default-page{min-width: 1200px;}.pocket{display:none;}
</style>
<script type="text/javascript">
setTimeout(function sunrise () {
document.getElementsByClassName('header')[0].style.backgroundColor = '#118798';
}, 0);
</script>

<div class="default-page">
<div class="header">
<h1 id="main-title" class="container"><%= __('A brand new app.') %></h1>
<h3 class="container">You're looking at: <code><%= view.pathFromApp + '.' +view.ext %></code></h3>
</div>
<div class="main container clearfix">
<!-- <h1>Getting started</h1>
<p>Don't worry, we've got your back.</p> -->
<ul class="getting-started">
<li class="clearfix">
<div class="step">
<div class="sprite one"></div>
<h3>Generate a REST API.</h3>
<p>
Run <code>sails generate api user</code>. This will create two files: a <a href="http://sailsjs.org/#!/documentation/concepts/ORM/Models.html">model</a> <code class="pocket">api/models/User.js</code> and a <a href="http://sailsjs.org/#!/documentation/concepts/Controllers">controller</a><code class="pocket">api/controllers/UserController.js</code>.
</p>
</div>
</li>
<li class="clearfix">
<div class="step">
<div class="sprite two"></div>
<h3>
Lift your app.
</h3>
<p>
Run <code>sails lift</code> to start up your app server. If you visit <a target="_blank" href="http://localhost:<%= sails.config.port || 1337%>/user"><code>http://localhost:<%= sails.config.port || 1337%>/user</code></a> in your browser, you'll see a <a href="http://sailsjs.org/#!/documentation/reference/blueprint-api">WebSocket-compatible</a> user API.
</p>
</div>
</li>
<li class="clearfix">
<div class="step">
<div class="sprite three"></div>
<h3>
Dive in.
</h3>
<p>Blueprints are just the beginning. You'll probably also want to learn how to customize your app's <a href="http://sailsjs.org/#!/documentation/concepts/Routes">routes</a>, set up <a href="http://sailsjs.org/#!/documentation/concepts/Policies">security policies</a>, configure your <a href="http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.connections.html">data sources</a>, and build custom <a target="_blank" href="http://sailsjs.org/#!/documentation/concepts/Controllers?q=actions">controller actions</a>. For more help getting started, check out the links on this page.</p>

</div>
</li>
</ul>
<div class="links">
<!-- <h3>Links</h3> -->
<ul class="link-list">

<h4>Docs</h4>
<a target="_blank" href="http://sailsjs.org/#!/documentation/anatomy/myApp"><li>App Structure</li></a>
<a target="_blank" href="http://sailsjs.org/#!/documentation/reference"><li>Reference</li></a>
<a target="_blank" href="http://sailsjs.org/#!/documentation/concepts/extending-sails/Adapters/adapterList.html"><li>Supported Databases</li></a>

<h4>Tutorials</h4>
<a target="_blank" href="https://github.com/sails101"><li>Sails 101</li></a>

<h4>Community</h4>
<a target="_blank" href="http://stackoverflow.com/search?q=sails.js"><li>StackOverFlow</li></a>
<a target="_blank" href="https://github.com/balderdashy/sails"><li>GitHub</li></a>
<a target="_blank" href="https://groups.google.com/forum/#!forum/sailsjs"><li>Google Group</li></a>
<a target="_blank" href="http://webchat.freenode.net/"><li>IRC (#sailsjs on freenode)</li></a>

</ul>
</div>
</div>
</div>
<div id="react-container"></div>
1 change: 1 addition & 0 deletions views/layout.ejs
Expand Up @@ -89,6 +89,7 @@

<!--SCRIPTS-->
<script src="/js/dependencies/sails.io.js"></script>
<script src="/js/bundle.js"></script>
<!--SCRIPTS END-->
</body>
</html>

0 comments on commit e862788

Please sign in to comment.