Created
December 10, 2017 22:19
-
-
Save zerobias/16c781285fd465ed5da13edad1530139 to your computer and use it in GitHub Desktop.
Node.js microservice as single file w/o dependencies with babel 7 and rollup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//@flow | |
module.exports = { | |
"presets": [ | |
"@babel/preset-flow", | |
["@babel/preset-env", { | |
"targets": { | |
"node": "8.9" | |
}, | |
// "shippedProposals": true, | |
"loose": true, | |
"modules": false, | |
"useBuiltIns": "usage", | |
"ignoreBrowserslistConfig": true | |
}] | |
], | |
"plugins": [ | |
["@babel/plugin-proposal-object-rest-spread", { "useBuiltIns": true }], | |
"transform-commonjs-es2015-modules" | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Koa from 'koa' | |
export const app = new Koa() | |
app.listen(7000) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "@@node-microservice", | |
"version": "1.0.0", | |
"description": "Node.js service as single unit", | |
"main": "server.js", | |
"scripts": { | |
"build": "rollup -c rollup.config.js", | |
"start": "node server.js" | |
}, | |
"dependencies": { | |
"koa": "^2.4.1", | |
"koa-basic-auth": "^2.0.0", | |
"koa-body": "^2.5.0", | |
"koa-helmet": "^3.3.0", | |
"koa-mount": "^3.0.0", | |
"koa-router": "^7.3.0", | |
"koa-static": "^4.0.2" | |
}, | |
"devDependencies": { | |
"@babel/cli": "^7.0.0-beta.34", | |
"@babel/core": "^7.0.0-beta.34", | |
"@babel/node": "^7.0.0-beta.34", | |
"@babel/plugin-proposal-object-rest-spread": "^7.0.0-beta.34", | |
"@babel/polyfill": "^7.0.0-beta.34", | |
"@babel/preset-env": "^7.0.0-beta.34", | |
"@babel/preset-flow": "^7.0.0-beta.34", | |
"babel-plugin-transform-commonjs-es2015-modules": "^4.0.1", | |
"rollup": "^0.52.1", | |
"rollup-plugin-babel": "^4.0.0-beta.0", | |
"rollup-plugin-commonjs": "^8.2.6", | |
"rollup-plugin-json": "^2.3.0", | |
"rollup-plugin-node-resolve": "^3.0.0", | |
"rollup-plugin-replace": "^2.0.0", | |
"rollup-plugin-uglify": "^2.0.1", | |
"uglify-es": "^3.2.2" | |
}, | |
"license": "MIT", | |
"author": { | |
"name": "Zero Bias", | |
"email": "[email protected]", | |
"url": "https://github.com/zerobias" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json from 'rollup-plugin-json' | |
import resolve from 'rollup-plugin-node-resolve' | |
import commonjs from 'rollup-plugin-commonjs' | |
import babel from 'rollup-plugin-babel' | |
import replace from 'rollup-plugin-replace' | |
import uglify from 'rollup-plugin-uglify' | |
import { minify } from 'uglify-es' | |
export default { | |
input: 'index.js', | |
output: { | |
file: 'server.js', | |
format: 'cjs' | |
}, | |
name: 'server', | |
extensions: ['.js', '.json'], | |
plugins: [ | |
json({ | |
preferConst: true, | |
include: '../../node_modules/**/**/**/**/**/*', | |
}), | |
replace({ | |
include: [ | |
'../../node_modules/formidable/**/**/**/**/**/*', | |
'../../node_modules/helmet-csp/**/**/**/**/**/*' | |
], | |
values: { | |
'if (global.GENTLY) require = GENTLY.hijack(require);': '', | |
"var config = require('../../config')": "var config = require('../../config.json')" | |
} | |
}), | |
babel({ include: ['**/node_modules/**/**/**/**/**/*', './index.js'], exclude: ['**/node_modules/formidable/**'] }), | |
resolve({ | |
main: true, | |
jsnext: true, | |
browser: false, | |
preferBuiltins: true, | |
customResolveOptions: { | |
moduleDirectory: '../../node_modules' | |
}, | |
extensions: ['.js', '.json'], | |
}), | |
commonjs({ | |
ignore: ['morgan'], | |
ignoreGlobal: false, | |
}), | |
uglify({ | |
ecma: 8, | |
mangle: false, | |
output: { | |
indent_level: 2, | |
quote_style: 1, | |
semicolons: false, | |
beautify: true, | |
ecma: 8, | |
}, | |
}, minify) | |
], | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment