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
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/dist/server.js",
"skipFiles": [
"<node_internals>/**"
]
},
{
"type": "node",
"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 GitRevisionPlugin = require('git-revision-webpack-plugin');
const gitRevisionPlugin = new GitRevisionPlugin();
const path = require('path');
function resolve(p) {
return path.resolve(__dirname, './../', p);
@ -18,7 +17,6 @@ module.exports = {
},
entry: [ 'babel-polyfill', './src/index.ts' ],
output: {
filename: "server-dev.js",
path: resolve('dist')
},
optimization: {
@ -32,9 +30,13 @@ module.exports = {
})
],
resolve: {
// default `modules` value is `["node_modules"]`
// we change it to resolve `underscore-lodash-wrapper`
modules: [__dirname, 'node_modules'],
extensions: [".ts", ".js"],
alias: {
'any-promise': 'es6-promise'
'any-promise': 'es6-promise',
'underscore': 'underscore-lodash-wrapper'
}
},
stats: {

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

@ -4,6 +4,7 @@ const webpack = require('webpack');
base.mode = 'development';
base.watch = true;
base.output.filename = "server-dev.js";
// https://webpack.js.org/configuration/devtool/
base.devtool = 'inline-source-map';
@ -24,4 +25,4 @@ base.plugins.push(new webpack.DefinePlugin({
'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');
const nodeVersion = 'node-' + /[0-9]+/.exec(process.versions.node)[0];
const PLATFORM = `${process.platform}-${process.arch}-${nodeVersion}`;
const TARGET_NODE_VERSION = process.versions.node;
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(
'node_modules',
@ -21,6 +25,8 @@ if(!fs.existsSync(DEASYNC_NODE_MODULES_PATH)) {
}
base.mode = 'production';
base.output.filename = "server.js";
base.optimization.minimize = true;
base.externals = base.externals ? base.externals : [];
base.externals.push(
@ -34,6 +40,21 @@ base.externals.push(
);
const prodRules = [
{
test: /\.js$/,
use: {
loader: 'babel-loader',
options: {
presets: [
["env", {
"targets": {
"node": TARGET_NODE_VERSION
}
}]
]
}
}
},
{
test: /\.node$/,
use: [
@ -58,4 +79,3 @@ base.module.rules = [...base.module.rules, ...prodRules];
base.plugins = [...base.plugins, ...prodPlugins];
module.exports = base;

4
server/package.json

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

Loading…
Cancel
Save