package: rename browser to client and main to server
This commit is contained in:
parent
fd2f6b8af7
commit
263eb84780
123 changed files with 43 additions and 42 deletions
95
scripts/build-client.js
Normal file
95
scripts/build-client.js
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
var build = require('./build'),
|
||||
babelify = require('babelify'),
|
||||
watch = process.argv.includes('--watch'),
|
||||
prod = process.argv.includes('--prod'),
|
||||
through = require('through'),
|
||||
minimatch = require('minimatch').Minimatch
|
||||
|
||||
|
||||
var ignores = ['**/*.min.js', '**/jquery.ui.js', 'gyronorm.complete.min.js'],
|
||||
transformWrapper = function(transform){
|
||||
return function(file, opts){
|
||||
if (ignores.some(pattern => minimatch(pattern).match(file))) {
|
||||
return through()
|
||||
} else {
|
||||
return transform(file, opts)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var transforms = [
|
||||
[transformWrapper(babelify), {presets: ['env']}]
|
||||
]
|
||||
|
||||
if (prod) {
|
||||
console.warn('\x1b[36m%s\x1b[0m', 'Building minified js bundle for production... This may take a while... ')
|
||||
transforms.push([transformWrapper(require('uglifyify')), {global: true}])
|
||||
}
|
||||
|
||||
var bundle = build({
|
||||
input: '../src/client/index.js',
|
||||
output: '../app/client/index.js',
|
||||
options: {
|
||||
debug: true,
|
||||
insertGlobals: false,
|
||||
noParse: ['**/*.min.js', '**/jquery.ui.js'],
|
||||
cache: {},
|
||||
packageCache: {}
|
||||
},
|
||||
plugins: watch ? [require('watchify')] : [],
|
||||
transforms: transforms
|
||||
})
|
||||
|
||||
if (watch) {
|
||||
|
||||
var ansiHTML = require('ansi-html'),
|
||||
WS = require('../node_modules/ws')
|
||||
|
||||
function send(msg, data){
|
||||
var ipc = new WS('ws://127.0.0.1:8080/dev')
|
||||
ipc.on('error', ()=>{})
|
||||
ipc.on('open', ()=>{
|
||||
ipc.send(JSON.stringify([msg, data]))
|
||||
ipc.close()
|
||||
})
|
||||
}
|
||||
|
||||
bundle.b.on('update', hotBundle)
|
||||
bundle.b.on('log', function(msg) {console.warn('\x1b[36m%s\x1b[0m', msg)})
|
||||
|
||||
function hotBundle() {
|
||||
|
||||
var output = bundle()
|
||||
|
||||
output.on('end', (err)=> {
|
||||
console.log('Build successful reloading...')
|
||||
send('reload')
|
||||
})
|
||||
|
||||
output.on('error', (err)=> {
|
||||
|
||||
console.error(err.stack)
|
||||
send('errorPopup',
|
||||
'<div class="error-stack">' +
|
||||
ansiHTML(
|
||||
err.stack
|
||||
.replace(/^ at .*/gm, '') // remove useless stack
|
||||
.replace(new RegExp(path.resolve(__dirname + '/..'), 'g'),'.') // shorten file path
|
||||
.trim()
|
||||
.replace('\n','\n\n') // add 1 new line after 1st line
|
||||
) +
|
||||
'</div>'
|
||||
)
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
hotBundle()
|
||||
|
||||
} else {
|
||||
|
||||
bundle()
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue