From cfbbfe4864e3f19aa1816d29b4c63bc62d10f63e Mon Sep 17 00:00:00 2001 From: vvo Date: Wed, 4 Nov 2015 14:23:42 +0100 Subject: [PATCH] feat(build): allow building React based custom widgets fixes #373 This is a try at it, not sure this is sufficient --- package.json | 4 ++-- scripts/build.sh | 5 ++++- webpack.config.babel.js => webpack.config.jsdelivr.babel.js | 4 ++++ 3 files changed, 10 insertions(+), 3 deletions(-) rename webpack.config.babel.js => webpack.config.jsdelivr.babel.js (75%) diff --git a/package.json b/package.json index 3e1660e3d0..334ea379a8 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "instantsearch.js", "version": "0.8.0", "description": "instantsearch.js is a library of widgets to build high performance instant search experiences using Algolia", - "main": "dist/instantsearch.js", + "main": "dist/instantsearch.module.js", "author": "Algolia ", "scripts": { "build": "./scripts/build.sh", @@ -15,7 +15,6 @@ "test": "BABEL_ENV=test mocha --opts mocha.opts --reporter dot && npm run lint", "test:watch": "BABEL_ENV=test mocha --opts mocha.opts --reporter min --watch", "test:watch:browser": "BABEL_ENV=test karma start", - "watch": "webpack --watch", "shrinkwrap": "npm-shrinkwrap --dev" }, "repository": "algolia/instantsearch.js", @@ -36,6 +35,7 @@ "eslint-plugin-react": "^3.6.3", "expect": "^1.12.2", "expect-jsx": "^2.1.0", + "expose-loader": "^0.7.0", "gh-pages": "^0.4.0", "jsdoc-parse": "^1.1.1", "jsdoc-to-markdown": "^1.2.0", diff --git a/scripts/build.sh b/scripts/build.sh index e1b3c6826e..4daef326a0 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -8,7 +8,10 @@ license="/*! instantsearch.js ${VERSION:-UNRELEASED} | © Algolia Inc. and other bundle='instantsearch' -webpack +# build for jsdelivr, with everything inlined while exposing React + ReactDOM (for plugins) +webpack --config webpack.config.jsdelivr.babel.js +# only transpile to ES5 for package.json main entry +babel index.js -o dist/${bundle}.module.js for source in "$ROOT"/css/[^_]*.scss; do base=`basename "$source" .scss` diff --git a/webpack.config.babel.js b/webpack.config.jsdelivr.babel.js similarity index 75% rename from webpack.config.babel.js rename to webpack.config.jsdelivr.babel.js index ead7dce0b7..0a7bf21106 100644 --- a/webpack.config.babel.js +++ b/webpack.config.jsdelivr.babel.js @@ -11,6 +11,10 @@ export default { module: { loaders: [{ test: /\.js$/, exclude: /node_modules/, loader: 'babel' + }, { + test: require.resolve('react'), loader: 'expose?React' + }, { + test: require.resolve('react-dom'), loader: 'expose?ReactDOM' }] }, plugins: [