diff --git a/.travis.yml b/.travis.yml index bc55b556..0cd1a4d7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,7 +32,7 @@ before_script: after_script: - kill %1 # kill e2e server before_deploy: -- npm run build-dist +- npm run build:prod-module deploy: - provider: npm skip_cleanup: true diff --git a/build/webpack.prod.js b/build/webpack.prod.js index ae10a82e..718da7e4 100644 --- a/build/webpack.prod.js +++ b/build/webpack.prod.js @@ -10,7 +10,9 @@ const BANNER = Version: ${VERSION} Repo: https://github.com/Rebilly/ReDoc`; -module.exports = { +const IS_MODULE = process.env.IS_MODULE != null; + +const config = { context: root(), devtool: 'source-map', @@ -35,13 +37,13 @@ module.exports = { setImmediate: false }, entry: { - 'redoc': ['./lib/polyfills.ts', './lib/vendor.ts', './lib/index.ts'] + 'redoc': IS_MODULE ? ['./lib/vendor.ts', './lib/redoc.module.ts'] : ['./lib/polyfills.ts', './lib/vendor.ts', './lib/index.ts'] }, output: { path: root('dist'), - filename: '[name].min.js', - sourceMapFilename: '[name].min.map', + filename: IS_MODULE ? '[name]-module.js' : '[name].min.js', + sourceMapFilename: IS_MODULE ? '[name]-module.map' : '[name].min.map', library: 'Redoc', libraryTarget: 'umd', umdNamedDefine: true @@ -60,9 +62,14 @@ module.exports = { test: /\.ts$/, loader: 'awesome-typescript-loader', exclude: /(node_modules)/ + }, { + test: /lib[\\\/].*\.css$/, + loaders: ['raw-loader'], + exclude: [/redoc-initial-styles\.css$/] }, { test: /\.css$/, - loaders: ['style', 'css?-import'] + loaders: ['style', 'css?-import'], + exclude: [/lib[\\\/](?!.*redoc-initial-styles).*\.css$/] }] }, @@ -90,3 +97,31 @@ module.exports = { }) ], } + +if (IS_MODULE) { + config.externals = { + 'jquery': 'jQuery', + 'esprima': 'esprima', // optional dep of ys-yaml not needed for redoc + '@angular/platform-browser-dynamic': '@angular/platform-browser-dynamic', + '@angular/platform-browser': '@angular/platform-browser', + '@angular/core': '@angular/core', + '@angular/common': '@angular/common', + '@angular/forms': '@angular/forms', + 'core-js': 'core-js', + 'rxjs': 'rxjs', + 'zone.js/dist/zone': 'zone.js/dist/zone' + }; + + config.module.rules.push({ + test: /\.ts$/, + loader: 'angular2-template-loader', + exclude: [/\.(spec|e2e)\.ts$/] + }); + + config.module.rules.push({ + test: /\.html$/, + loader: 'raw-loader' + }); +} + +module.exports = config; diff --git a/lib/components/Redoc/redoc.html b/lib/components/Redoc/redoc.html index 0a4bcaa4..8df000b0 100644 --- a/lib/components/Redoc/redoc.html +++ b/lib/components/Redoc/redoc.html @@ -1,4 +1,4 @@ -
+