Add version and revision to standalone bundle exports

This commit is contained in:
Roman Hotsiy 2017-11-22 13:02:15 +02:00
parent 57c424f6b5
commit 63dfdebf6a
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
4 changed files with 16 additions and 0 deletions

2
custom.d.ts vendored
View File

@ -14,6 +14,8 @@ declare module '*.css' {
} }
declare var __DEV__: boolean; declare var __DEV__: boolean;
declare var __REDOC_VERSION__: string;
declare var __REDOC_REVISION__: string;
declare type Dict<T> = { declare type Dict<T> = {
[key: string]: T; [key: string]: T;

View File

@ -3,6 +3,9 @@ import * as React from 'react';
import { RedocStandalone } from './components/RedocStandalone'; import { RedocStandalone } from './components/RedocStandalone';
export const version = __REDOC_VERSION__;
export const revision = __REDOC_REVISION__;
function attributesMap(element: Element) { function attributesMap(element: Element) {
var res = {}; var res = {};
var elAttrs = element.attributes; var elAttrs = element.attributes;

View File

@ -35,6 +35,7 @@
"./custom.d.ts", "./custom.d.ts",
"./demo/playground/hmr-playground.tsx", "./demo/playground/hmr-playground.tsx",
"./src/index.ts", "./src/index.ts",
"./src/standalone.tsx",
"demo/*.tsx" "demo/*.tsx"
], ],
"awesomeTypescriptLoaderOptions": { "awesomeTypescriptLoaderOptions": {

View File

@ -6,6 +6,14 @@ const nodeExternals = require('webpack-node-externals')({
whitelist: ['swagger2openapi', 'reftools', /\.(?!(?:jsx?|json)$).{1,5}$/i], whitelist: ['swagger2openapi', 'reftools', /\.(?!(?:jsx?|json)$).{1,5}$/i],
}); });
const VERSION = JSON.stringify(require('./package.json').version);
const REVISION = JSON.stringify(
require('child_process')
.execSync('git rev-parse --short HEAD')
.toString()
.trim(),
);
export default env => { export default env => {
env = env || {}; env = env || {};
@ -101,6 +109,8 @@ export default env => {
plugins: [ plugins: [
new webpack.DefinePlugin({ new webpack.DefinePlugin({
'process.env.NODE_ENV': env.prod ? '"production"' : '"development"', 'process.env.NODE_ENV': env.prod ? '"production"' : '"development"',
__REDOC_VERSION__: VERSION,
__REDOC_REVISION__: REVISION,
__DEV__: env.prod ? 'false' : 'true', __DEV__: env.prod ? 'false' : 'true',
}), }),
new webpack.NamedModulesPlugin(), new webpack.NamedModulesPlugin(),