Concat de rutas JS con Gulp, servidor express sirve routes.js

This commit is contained in:
Juan Ferrer Toribio 2016-10-07 11:44:24 +02:00
parent 9fb4b55c6b
commit 5a4a41d630
8 changed files with 35 additions and 64 deletions

View File

@ -1 +1 @@
export * from './src/app'
export * from './src/app'

View File

@ -1,4 +1,4 @@
import * as core from '@salix/core'
import * as vendors from '@salix/vendor'
import * as crud from '@salix/crud'
console.log('compras');
console.log('compras');

View File

@ -1,16 +1,13 @@
var gulp = require ('gulp');
var jsoncombine = require ('gulp-jsoncombine');
function combineFunc (data)
{
return new Buffer (JSON.stringify (data));
}
var concat = require ('gulp-concat');
var babel = require ('gulp-babel');
gulp.task ('default', function ()
{
var json = gulp.src ('./@salix/**/routes.json')
.pipe (jsoncombine ('salix.routes.json', combineFunc))
.pipe (gulp.dest ('./build'));
var js = gulp.src ('./@salix/crud/**/routes.js')
.pipe (concat ('salix.routes.js'))
.pipe (babel ({presets: ['es2015']}))
.pipe (gulp.dest ('./build/private'));
});

View File

@ -13,9 +13,8 @@
</div>
<script
type="text/javascript"
src="build/salix.app.js"
selector="#app"
routes-cdn="http://localhost:8080/routes">
</script>
src="build/public/salix.app.js"
selector="#app">
</script>
</body>
</html>

View File

@ -1,27 +0,0 @@
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/Cellar/node/6.3.1/bin/node',
1 verbose cli '/usr/local/bin/npm',
1 verbose cli 'run',
1 verbose cli 'dev' ]
2 info using npm@3.10.3
3 info using node@v6.3.1
4 verbose stack Error: missing script: dev
4 verbose stack at run (/usr/local/lib/node_modules/npm/lib/run-script.js:151:19)
4 verbose stack at /usr/local/lib/node_modules/npm/lib/run-script.js:61:5
4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:356:5
4 verbose stack at checkBinReferences_ (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:320:45)
4 verbose stack at final (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:354:3)
4 verbose stack at then (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:124:5)
4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:311:12
4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:78:16
4 verbose stack at tryToString (fs.js:455:3)
4 verbose stack at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:442:12)
5 verbose cwd /Users/nelo/Documents/node/salix
6 error Darwin 16.0.0
7 error argv "/usr/local/Cellar/node/6.3.1/bin/node" "/usr/local/bin/npm" "run" "dev"
8 error node v6.3.1
9 error npm v3.10.3
10 error missing script: dev
11 error If you need help, you may report this error at:
11 error <https://github.com/npm/npm/issues>
12 verbose exit [ 1, true ]

View File

@ -11,24 +11,28 @@
"dependencies": {
"angular": "^1.5.8",
"angular-ui-router": "^1.0.0-beta.3",
"cors": "^2.8.1",
"express": "^4.14.0",
"material-design-lite": "^1.2.1",
"oclazyload": "^0.6.3"
},
"devDependencies": {
"gulp": "^3.9.1",
"gulp-jsoncombine": "^1.0.3",
"webpack": "*",
"webpack-dev-server": "*",
"raw-loader": "*",
"css-loader": "^0.25.0",
"style-loader": "^0.13.1",
"babel-loader": "*",
"babel-core": "*",
"babel-preset-es2015": "*"
"babel-loader": "*",
"babel-preset-es2015": "*",
"cors": "^2.8.1",
"css-loader": "^0.25.0",
"gulp": "^3.9.1",
"gulp-babel": "^6.1.2",
"gulp-concat": "^2.6.0",
"raw-loader": "*",
"style-loader": "^0.13.1",
"webpack": "*",
"webpack-dev-server": "*"
},
"scripts": {
"build": "webpack --progress --colors --watch"
"build": "webpack --progress --colors --watch",
"dev": "webpack-dev-server --progress --colors --inline --hot",
"gulp": "gulp",
"express": "node server.js"
}
}

View File

@ -2,11 +2,8 @@
var express = require ('express');
var cors = require ('cors');
function getRoutes (req, res)
{
var routes = require ('./build/salix.routes.json');
res.send (JSON.stringify (routes));
}
var port = 3000;
var routesUrl = '/private/salix.routes.js';
function getDefault (res, res)
{
@ -15,11 +12,11 @@ function getDefault (res, res)
function onListen ()
{
console.log ('HTTP server started.');
console.log ('HTTP server started on port '+ port);
}
var app = express ();
app.get ('/routes', cors (), getRoutes);
app.use ('/private', cors (), express.static (__dirname +'/build/private'));
app.all (/.*/, cors (), getDefault);
app.listen (8080, onListen);
app.listen (port, onListen);

View File

@ -8,9 +8,9 @@ module.exports =
'salix.app': ['@salix/app']
},
output: {
path: path.join(__dirname, 'build'),
path: path.join(__dirname, 'build', 'public'),
filename: '[name].js',
publicPath: 'build/',
publicPath: 'build/public/',
chunkFilename: "[name].js"
},
module: {
@ -39,5 +39,6 @@ module.exports =
__dirname,
'node_modules'
]
}
},
devtool: 'cheap-module-eval-source-map' // 'source-map'
};