From 02b061cbd8ff0b227053906f9a56ea49689b3862 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Fri, 14 Oct 2016 11:44:48 +0300 Subject: [PATCH] Build and publish angular2 module (fixes #126) --- build/webpack.prod.js | 45 ++++++++++++++++++++++++++++++++++++++----- package.json | 24 ++++++++++++----------- 2 files changed, 53 insertions(+), 16 deletions(-) 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/package.json b/package.json index 6f84ef02..a732244d 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "ngc": "ngc -p .", "webpack:prod": "webpack --config build/webpack.prod.js --profile --bail", "build:sass": "node-sass -q -o lib lib", - "build:prod": "npm run build:sass && npm run ngc && npm run webpack:prod", + "build:prod": "npm run build:sass && npm run ngc && npm run webpack:prod && IS_MODULE=true npm run webpack:prod", "build-dist": "npm run build:prod", "stats": "webpack --config build/webpack.prod.js --json > stats.json", "start": "webpack-dev-server --config build/webpack.dev.js --content-base demo", @@ -44,7 +44,7 @@ "author": "Roman Hotsiy", "license": "MIT", "devDependencies": { - "@angular/compiler-cli": "^0.6.3", + "@angular/compiler-cli": "^2.1.0", "@types/core-js": "^0.9.31", "@types/jasmine": "^2.2.32", "@types/requirejs": "^2.1.26", @@ -91,13 +91,6 @@ "webpack-dev-server": "^2.1.0-beta.6" }, "dependencies": { - "@angular/common": "^2.0.1", - "@angular/compiler": "^2.0.1", - "@angular/core": "^2.0.1", - "@angular/platform-browser": "^2.0.1", - "@angular/platform-browser-dynamic": "^2.0.1", - "@angular/platform-server": "^2.0.1", - "core-js": "^2.4.1", "dropkickjs": "^2.1.10", "hint.css": "^2.3.2", "json-pointer": "^0.5.0", @@ -105,10 +98,19 @@ "openapi-sampler": "^0.3.1", "prismjs": "^1.5.1", "remarkable": "^1.6.2", - "rxjs": "^5.0.0-beta.12", "scrollparent": "^1.0.0", "slugify": "^1.0.2", - "stream-http": "^2.3.1", + "stream-http": "^2.3.1" + }, + "peerDependencies": { + "@angular/common": "^2.1.0", + "@angular/compiler": "^2.1.0", + "@angular/core": "^2.1.0", + "@angular/platform-browser": "^2.1.0", + "@angular/platform-browser-dynamic": "^2.1.0", + "@angular/platform-server": "^2.1.0", + "core-js": "^2.4.1", + "rxjs": "^5.0.0-beta.12", "zone.js": "^0.6.25" } }