Browse Source

Generic node production build (#869)

pull/1/head
jonyrock-back 5 years ago committed by GitHub
parent
commit
3f30c218c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      server/.babelrc
  2. 9
      server/.vscode/launch.json
  3. 5
      server/build/underscore-lodash-wrapper.js
  4. 31
      server/build/webpack.614.prod.conf.js
  5. 12
      server/build/webpack.base.conf.js
  6. 3
      server/build/webpack.dev.conf.js
  7. 26
      server/build/webpack.prod.conf.js
  8. 4
      server/package.json

9
server/.babelrc

@ -1,9 +0,0 @@
{
"presets": [
["env", {
"targets": {
"node": "6.14"
}
}]
]
}

9
server/.vscode/launch.json vendored

@ -4,6 +4,15 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/dist/server.js",
"skipFiles": [
"<node_internals>/**"
]
},
{ {
"type": "node", "type": "node",
"request": "attach", "request": "attach",

5
server/build/underscore-lodash-wrapper.js

@ -0,0 +1,5 @@
// we need this module because we can't avoid underscore lib usage in nedb
// missing `pluck` method added
var _ = require('lodash');
_.pluck = _.map;
module.exports = _;

31
server/build/webpack.614.prod.conf.js

@ -1,31 +0,0 @@
const path = require('path');
module.exports = {
mode: 'production',
target: 'node',
node: {
__dirname: false,
__filename: false,
},
entry: [ './dist/server-dev.js' ],
output: {
filename: "server.js",
path: path.join(__dirname, '../dist')
},
module: {
rules: [
{
test: /\.js$/,
use: [
{ loader: 'babel-loader' }
]
},
{
test: /\.node$/,
use: [
{ loader: './build/node-loader' }
]
}
]
}
}

12
server/build/webpack.base.conf.js

@ -1,10 +1,9 @@
const path = require('path');
const fs = require('fs');
const webpack = require('webpack'); const webpack = require('webpack');
const GitRevisionPlugin = require('git-revision-webpack-plugin'); const GitRevisionPlugin = require('git-revision-webpack-plugin');
const gitRevisionPlugin = new GitRevisionPlugin(); const gitRevisionPlugin = new GitRevisionPlugin();
const path = require('path');
function resolve(p) { function resolve(p) {
return path.resolve(__dirname, './../', p); return path.resolve(__dirname, './../', p);
@ -18,7 +17,6 @@ module.exports = {
}, },
entry: [ 'babel-polyfill', './src/index.ts' ], entry: [ 'babel-polyfill', './src/index.ts' ],
output: { output: {
filename: "server-dev.js",
path: resolve('dist') path: resolve('dist')
}, },
optimization: { optimization: {
@ -32,9 +30,13 @@ module.exports = {
}) })
], ],
resolve: { resolve: {
// default `modules` value is `["node_modules"]`
// we change it to resolve `underscore-lodash-wrapper`
modules: [__dirname, 'node_modules'],
extensions: [".ts", ".js"], extensions: [".ts", ".js"],
alias: { alias: {
'any-promise': 'es6-promise' 'any-promise': 'es6-promise',
'underscore': 'underscore-lodash-wrapper'
} }
}, },
stats: { stats: {

3
server/build/webpack.dev.conf.js

@ -4,6 +4,7 @@ const webpack = require('webpack');
base.mode = 'development'; base.mode = 'development';
base.watch = true; base.watch = true;
base.output.filename = "server-dev.js";
// https://webpack.js.org/configuration/devtool/ // https://webpack.js.org/configuration/devtool/
base.devtool = 'inline-source-map'; base.devtool = 'inline-source-map';
@ -24,4 +25,4 @@ base.plugins.push(new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development') 'process.env.NODE_ENV': JSON.stringify('development')
})); }));
module.exports = base; module.exports = base;

26
server/build/webpack.prod.conf.js

@ -4,8 +4,12 @@ const fs = require('fs');
var base = require('./webpack.base.conf'); var base = require('./webpack.base.conf');
const nodeVersion = 'node-' + /[0-9]+/.exec(process.versions.node)[0]; const TARGET_NODE_VERSION = process.versions.node;
const PLATFORM = `${process.platform}-${process.arch}-${nodeVersion}`; const PLATFORM = `${process.platform}-${process.arch}-node-${TARGET_NODE_VERSION.split('.')[0]}`;
console.log(`Target node version: ${TARGET_NODE_VERSION}`);
console.log(`Platform: ${PLATFORM}`);
const DEASYNC_NODE_MODULES_PATH = path.resolve( const DEASYNC_NODE_MODULES_PATH = path.resolve(
'node_modules', 'node_modules',
@ -21,6 +25,8 @@ if(!fs.existsSync(DEASYNC_NODE_MODULES_PATH)) {
} }
base.mode = 'production'; base.mode = 'production';
base.output.filename = "server.js";
base.optimization.minimize = true;
base.externals = base.externals ? base.externals : []; base.externals = base.externals ? base.externals : [];
base.externals.push( base.externals.push(
@ -34,6 +40,21 @@ base.externals.push(
); );
const prodRules = [ const prodRules = [
{
test: /\.js$/,
use: {
loader: 'babel-loader',
options: {
presets: [
["env", {
"targets": {
"node": TARGET_NODE_VERSION
}
}]
]
}
}
},
{ {
test: /\.node$/, test: /\.node$/,
use: [ use: [
@ -58,4 +79,3 @@ base.module.rules = [...base.module.rules, ...prodRules];
base.plugins = [...base.plugins, ...prodPlugins]; base.plugins = [...base.plugins, ...prodPlugins];
module.exports = base; module.exports = base;

4
server/package.json

@ -5,9 +5,7 @@
"scripts": { "scripts": {
"start": "node dist/server.js", "start": "node dist/server.js",
"dev": "NODE_ENV=development node build/dev-server.js", "dev": "NODE_ENV=development node build/dev-server.js",
"build-prod": "npm rebuild zeromq && webpack --config build/webpack.prod.conf.js", "build": "npm rebuild zeromq && webpack --config build/webpack.prod.conf.js",
"build-614": "webpack --config build/webpack.614.prod.conf.js",
"build": "npm run build-prod && npm run build-614",
"test": "jest --config jest.config.js" "test": "jest --config jest.config.js"
}, },
"repository": { "repository": {

Loading…
Cancel
Save