umd bundle

This commit is contained in:
Roman Hotsiy 2017-11-19 21:27:44 +02:00
parent 6dae49ac5f
commit ec45c8582a
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
11 changed files with 48 additions and 41 deletions

1
.gitignore vendored
View File

@ -24,6 +24,7 @@ lib/
stats.json stats.json
e2e/build/ e2e/build/
cypress/ cypress/
bundles
/coverage /coverage
.ghpages-tmp .ghpages-tmp

View File

@ -1,8 +1,2 @@
.DS_Store !bundles/
**/.* !package.json
node_modules/
perf/
demo/
coverage/

View File

@ -3,7 +3,7 @@
"name": "redoc", "name": "redoc",
"version": "2.0.0", "version": "2.0.0",
"description": "ReDoc", "description": "ReDoc",
"main": "lib/index.js", "main": "bundles/redoc.lib.js",
"scripts": { "scripts": {
"start": "webpack-dev-server --hot", "start": "webpack-dev-server --hot",
"start:perf": "webpack-dev-server --env.prod --env.perf", "start:perf": "webpack-dev-server --env.prod --env.perf",
@ -16,7 +16,9 @@
"e2e:clean": "rimraf e2e/.build", "e2e:clean": "rimraf e2e/.build",
"cy:open": "cypress open", "cy:open": "cypress open",
"bundle:clean": "rimraf bundles", "bundle:clean": "rimraf bundles",
"bundle": "npm run bundle:clean && webpack -p --env.prod --env.standalone", "bundle:standalone": "webpack -p --env.prod --env.standalone",
"bundle:lib": "webpack -p --env.prod",
"bundle": "npm run bundle:clean && npm run bundle:lib && npm run bundle:standalone",
"stats": "webpack -p --env.prod --json --profile > stats.json", "stats": "webpack -p --env.prod --json --profile > stats.json",
"prettier": "prettier --write \"src/**/*.{ts,tsx}\"" "prettier": "prettier --write \"src/**/*.{ts,tsx}\""
}, },
@ -38,6 +40,7 @@
"@types/webpack": "^3.0.5", "@types/webpack": "^3.0.5",
"@types/webpack-env": "^1.13.0", "@types/webpack-env": "^1.13.0",
"awesome-typescript-loader": "^3.2.2", "awesome-typescript-loader": "^3.2.2",
"core-js": "^2.5.1",
"css-loader": "^0.28.7", "css-loader": "^0.28.7",
"cypress": "^1.0.3", "cypress": "^1.0.3",
"enzyme": "^3.1.1", "enzyme": "^3.1.1",
@ -45,6 +48,7 @@
"enzyme-to-json": "^3.2.2", "enzyme-to-json": "^3.2.2",
"extract-text-webpack-plugin": "^3.0.0", "extract-text-webpack-plugin": "^3.0.0",
"html-webpack-plugin": "^2.30.1", "html-webpack-plugin": "^2.30.1",
"http-server": "^0.10.0",
"jest": "^21.1.0", "jest": "^21.1.0",
"mobx-react-devtools": "^4.2.15", "mobx-react-devtools": "^4.2.15",
"prettier": "^1.5.3", "prettier": "^1.5.3",
@ -53,6 +57,7 @@
"raf": "^3.4.0", "raf": "^3.4.0",
"react-dev-utils": "^4.1.0", "react-dev-utils": "^4.1.0",
"react-hot-loader": "3.0.0-beta.6", "react-hot-loader": "3.0.0-beta.6",
"rimraf": "^2.6.2",
"source-map-loader": "^0.2.1", "source-map-loader": "^0.2.1",
"style-loader": "^0.18.2", "style-loader": "^0.18.2",
"ts-jest": "^21.0.1", "ts-jest": "^21.0.1",
@ -61,9 +66,7 @@
"webpack": "^3.4.1", "webpack": "^3.4.1",
"webpack-dashboard": "^0.4.0", "webpack-dashboard": "^0.4.0",
"webpack-dev-server": "^2.6.1", "webpack-dev-server": "^2.6.1",
"http-server": "^0.10.0", "webpack-node-externals": "^1.6.0"
"core-js": "^2.5.1",
"rimraf": "^2.6.2"
}, },
"dependencies": { "dependencies": {
"decko": "^1.2.0", "decko": "^1.2.0",

View File

@ -11,7 +11,7 @@ import { AppStore } from '../../services';
import defaultTheme from '../../theme'; import defaultTheme from '../../theme';
interface RedocProps { export interface RedocProps {
store: AppStore; store: AppStore;
options?: { options?: {
theme?: ThemeInterface; theme?: ThemeInterface;

View File

@ -1,5 +1,6 @@
import { hoverColor } from '../../common-elements/mixins'; import { hoverColor } from '../../common-elements/mixins';
import styled from '../../styled-components'; import styled from '../../styled-components';
export { ClassAttributes } from 'react';
export const RedocWrap = styled.div` export const RedocWrap = styled.div`
overflow: hidden; overflow: hidden;

View File

@ -7,14 +7,14 @@ import { StoreProvider } from './StoreProvider';
import { ErrorBoundary } from './ErrorBoundary'; import { ErrorBoundary } from './ErrorBoundary';
import { Redoc } from './Redoc/Redoc'; import { Redoc } from './Redoc/Redoc';
export interface RedocProps { export interface RedocStandaloneProps {
specOrSpecUrl: string | object; specOrSpecUrl: string | object;
options?: { options?: {
theme?: ThemeInterface; theme?: ThemeInterface;
}; };
} }
export class RedocStandalone extends React.Component<RedocProps> { export class RedocStandalone extends React.Component<RedocStandaloneProps> {
render() { render() {
const { specOrSpecUrl, options } = this.props; const { specOrSpecUrl, options } = this.props;
let specUrl; let specUrl;

View File

@ -1,6 +1,6 @@
export * from './RedocStandalone'; export * from './RedocStandalone';
export * from './Redoc/Redoc'; export * from './Redoc/Redoc';
export * from './Redoc/elements'; // export * from './Redoc/elements';
export * from './Schema/'; export * from './Schema/';
export * from './Operation/Operation'; export * from './Operation/Operation';
export * from './RedocStandalone'; export * from './RedocStandalone';

View File

@ -3,7 +3,7 @@ import { ThemedStyledComponentsModule } from 'styled-components';
import { ThemeInterface } from './theme'; import { ThemeInterface } from './theme';
type StyledFunction<T> = styledComponents.ThemedStyledFunction<T, ThemeInterface>; export type StyledFunction<T> = styledComponents.ThemedStyledFunction<T, ThemeInterface>;
function withProps<T, U extends HTMLElement = HTMLElement>( function withProps<T, U extends HTMLElement = HTMLElement>(
styledFunction: StyledFunction<React.HTMLProps<U>>, styledFunction: StyledFunction<React.HTMLProps<U>>,

View File

@ -9,6 +9,7 @@
"noUnusedParameters": true, "noUnusedParameters": true,
"strictNullChecks": true, "strictNullChecks": true,
"sourceMap": true, "sourceMap": true,
// "declaration": true,
"outDir": "lib", "outDir": "lib",
"pretty": true, "pretty": true,
"lib": [ "lib": [

View File

@ -2,6 +2,7 @@ const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack'); const webpack = require('webpack');
const DashboardPlugin = require('webpack-dashboard/plugin'); const DashboardPlugin = require('webpack-dashboard/plugin');
const nodeExternals = require('webpack-node-externals');
module.exports = env => { module.exports = env => {
env = env || {}; env = env || {};
@ -11,7 +12,9 @@ module.exports = env => {
entry = ['./src/polyfills.ts', './src/standalone.tsx']; entry = ['./src/polyfills.ts', './src/standalone.tsx'];
} else { } else {
entry = env.prod entry = env.prod
? env.perf ? ['./perf/index.tsx'] : ['./src/hmr-playground.tsx'] ? './src/index.ts'
: env.perf
? ['./perf/index.tsx']
: [ : [
'react-dev-utils/webpackHotDevClient', 'react-dev-utils/webpackHotDevClient',
'react-hot-loader/patch', 'react-hot-loader/patch',
@ -23,7 +26,7 @@ module.exports = env => {
entry: entry, entry: entry,
output: { output: {
filename: env.standalone ? 'redoc.standalone.js' : 'redoc.bundle.js', filename: env.standalone ? 'redoc.standalone.js' : 'redoc.lib.js',
path: __dirname + '/bundles', path: __dirname + '/bundles',
}, },
@ -69,19 +72,12 @@ module.exports = env => {
}, },
{ {
test: /\.css$/, test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader', loader: 'css-loader',
options: { options: {
sourceMap: true, sourceMap: true,
minimize: true, minimize: true,
}, },
}, },
],
}),
},
{ enforce: 'pre', test: /\.js$/, loader: 'source-map-loader' }, { enforce: 'pre', test: /\.js$/, loader: 'source-map-loader' },
], ],
}, },
@ -90,20 +86,27 @@ module.exports = env => {
'process.env.NODE_ENV': env.prod ? '"production"' : '"development"', 'process.env.NODE_ENV': env.prod ? '"production"' : '"development"',
__DEV__: env.prod ? 'false' : 'true', __DEV__: env.prod ? 'false' : 'true',
}), }),
new ExtractTextPlugin({
filename: 'redoc.css',
allChunks: true,
}),
new HtmlWebpackPlugin({ new HtmlWebpackPlugin({
template: './demo/index.html', template: './demo/index.html',
}), }),
new webpack.NamedModulesPlugin(), new webpack.NamedModulesPlugin(),
], ],
}; };
if (env.prod) { if (env.prod) {
config.plugins.push(new webpack.optimize.ModuleConcatenationPlugin()); config.plugins.push(new webpack.optimize.ModuleConcatenationPlugin());
} else { } else {
config.plugins.push(new DashboardPlugin()); config.plugins.push(new DashboardPlugin());
} }
if (env.prod && !env.standalone) {
config.externals = nodeExternals({
// bundle in moudules that need transpiling + non-js (e.g. css)
whitelist: ['swagger2openapi', 'reftools', /\.(?!(?:jsx?|json)$).{1,5}$/i],
});
config.output.library = 'Redoc';
config.output.libraryTarget = 'umd';
}
return config; return config;
}; };

View File

@ -7162,6 +7162,10 @@ webpack-dev-server@^2.6.1:
webpack-dev-middleware "^1.11.0" webpack-dev-middleware "^1.11.0"
yargs "^6.6.0" yargs "^6.6.0"
webpack-node-externals@^1.6.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/webpack-node-externals/-/webpack-node-externals-1.6.0.tgz#232c62ec6092b100635a3d29d83c1747128df9bd"
webpack-sources@^1.0.1: webpack-sources@^1.0.1:
version "1.0.2" version "1.0.2"
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.0.2.tgz#d0148ec083b3b5ccef1035a6b3ec16442983b27a" resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.0.2.tgz#d0148ec083b3b5ccef1035a6b3ec16442983b27a"