Permalink
Browse files

fix(rest): generate a node version with webpack

  • Loading branch information...
RangerRick committed Jul 19, 2017
1 parent 8c2e604 commit 58d2938eb1fb19b7f465a09c456e6fcf08ced157
Showing with 111 additions and 34 deletions.
  1. +3 −2 package.json
  2. +9 −0 src/rest/AxiosHTTP.ts
  3. +61 −30 webpack.config.js
  4. +38 −2 yarn.lock
View
@@ -37,6 +37,7 @@
"husky": "^0.13.3",
"jest": "^20.0.3",
"lodash.clonedeep": "^4.5.0",
"parallel-webpack": "^2.0.0",
"regenerator-runtime": "^0.10.5",
"standard-changelog": "^1.0.1",
"ts-jest": "^20.0.4",
@@ -86,13 +87,13 @@
"changelog": "standard-changelog -i CHANGELOG.md -s -r 0",
"build": "webpack -p --env production",
"dev": "webpack --progress --colors",
"dist": "yarn lint && yarn test && yarn dev && yarn build",
"dist": "yarn lint && yarn test && yarn build",
"watch": "webpack --progress --colors --watch",
"test": "jest",
"watch-test": "jest --watch",
"lint": "tslint 'src/**/*.ts'",
"cli": "ts-node src/CLI.ts",
"docker-build": "yarn && yarn lint && jest --color=false --verbose && webpack --verbose --color=false && webpack -p --env production --verbose --color=false && ./fix-ownership.sh",
"docker-build": "yarn && yarn lint && jest --color=false --verbose && webpack -p --env production --verbose --color=false && ./fix-ownership.sh",
"docker": "docker run --rm --name opennms-js -v `pwd`:/build -w /build node:latest yarn docker-build"
}
}
View
@@ -2,6 +2,8 @@ import axios from 'axios';
import {AxiosStatic, AxiosInstance, AxiosRequestConfig} from 'axios';
import * as qs from 'qs';
declare const IS_WEB;
/** @hidden */
// tslint:disable-next-line
const URI = require('urijs');
@@ -145,6 +147,13 @@ export class AxiosHTTP extends AbstractHTTP {
}
const allOptions = this.getOptions(options);
this.axiosObj = this.axiosImpl.create({
adapter: () => {
if (IS_WEB) {
return require('axios/lib/adapters/xhr');
} else {
return require('axios/lib/adapters/http');
}
},
auth: {
password: allOptions.auth.password,
username: allOptions.auth.username,
View
@@ -2,18 +2,29 @@ var webpack = require('webpack');
var path = require('path');
var TypedocWebpackPlugin = require('typedoc-webpack-plugin');
var createVariants = require('parallel-webpack').createVariants;
var clonedeep = require('lodash.clonedeep');
var isProduction = require('yargs').argv.p;
var libraryName = 'opennms';
var variants = {
web: [ true, false ],
};
if (isProduction) {
variants.production = [ true, false ];
}
var config = {
entry: {
'opennms': __dirname + '/src/API.ts',
},
devtool: 'source-map',
output: {
path: __dirname + '/dist',
library: libraryName,
libraryTarget: 'umd',
umdNamedDefine: true
},
@@ -54,9 +65,11 @@ var config = {
extensions: ['.webpack.js', '.web.js', '.ts', '.js']
},
plugins: [
/*
new webpack.DefinePlugin({
"global.GENTLY": false
}),
*/
],
node: {
fs: 'empty',
@@ -67,35 +80,53 @@ var config = {
}
};
if (isProduction) {
var tsconfig = require('./tsconfig.json');
tsconfig.name = 'OpenNMS.js';
tsconfig.mode = 'file';
tsconfig.ignoreCompilerErrors = true;
tsconfig.exclude = "/**/+(node_modules|test)/**/*";
tsconfig.excludeExternals = false;
function createConfig(options) {
var myconf = clonedeep(config);
myconf.output.filename = '[name]';
var defs = {
'IS_WEB': options.web,
'IS_PRODUCTION': options.production,
};
if (options.web) {
myconf.target = 'web';
} else {
myconf.target = 'node';
myconf.node = { process: false };
myconf.output.filename += '.node';
}
if (options.production) {
var tsconfig = require('./tsconfig.json');
tsconfig.name = 'OpenNMS.js';
tsconfig.mode = 'file';
tsconfig.ignoreCompilerErrors = true;
tsconfig.exclude = "/**/+(node_modules|test)/**/*";
tsconfig.excludeExternals = false;
defs['global.GENTLY'] = false;
myconf.plugins.push(new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
}));
myconf.plugins.push(new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
minimize: true
}));
myconf.plugins.push(new TypedocWebpackPlugin(tsconfig));
myconf.output.filename += '.min';
} else {
myconf.plugins.push(new webpack.LoaderOptionsPlugin({
minimize: false,
debug: true
}));
}
myconf.plugins.push(new webpack.DefinePlugin(defs));
myconf.output.filename += '.js';
config.plugins.push(new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
}));
config.plugins.push(new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
minimize: true
}));
config.plugins.push(new TypedocWebpackPlugin(tsconfig));
config.output.filename = '[name].min.js';
} else {
config.plugins.push(new webpack.LoaderOptionsPlugin({
minimize: false,
debug: true
}));
config.plugins.push(new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("test")
}
}));
config.output.filename = '[name].js';
return myconf;
}
module.exports = config;
module.exports = createVariants({}, variants, createConfig);
console.log('exports: ' + JSON.stringify(module.exports, undefined, 2));
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 58d2938

Please sign in to comment.