From 8a65894ad9c18c290e073e67d7c5f3c6bd170f97 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Sun, 18 Sep 2016 22:57:10 +0200 Subject: [PATCH] Add umd bundle via webpack. Fixes #170 --- .gitignore | 1 + package.json | 7 +++++-- webpack.config.js | 31 +++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 webpack.config.js diff --git a/.gitignore b/.gitignore index bf995662b..94cb7579c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules lib/ +dist/ diff --git a/package.json b/package.json index d06f57e4b..1556da5dc 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "test": "standard && ava", "test:watch": "npm test -- --watch", "clean": "rimraf lib dist", - "build": "babel src --out-dir lib", + "build": "babel src --out-dir lib && webpack && NODE_ENV=production webpack", "build:watch": "npm run build ./src -- -watch", "prepublish": "npm run clean && npm run build" }, @@ -39,13 +39,16 @@ "devDependencies": { "ava": "^0.16.0", "babel-cli": "^6.14.0", + "babel-core": "^6.14.0", "babel-eslint": "^6.0.0", + "babel-loader": "^6.2.5", "babel-preset-es2015": "^6.14.0", "babel-preset-stage-2": "^6.5.0", "immutable": "^3.7.6", "redux": "^3.5.2", "rimraf": "~2.5.2", - "standard": "^8.0.0" + "standard": "^8.0.0", + "webpack": "^1.13.2" }, "files": [ "lib", diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 000000000..c084b0842 --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,31 @@ +const webpack = require('webpack') +const env = process.env.NODE_ENV +const isProd = env === 'production' + +let plugins = [ + new webpack.optimize.OccurrenceOrderPlugin(), + new webpack.DefinePlugin({ + 'process.env.NODE_ENV': JSON.stringify(env) + }) +] + +if (isProd) { + plugins.push(new webpack.optimize.UglifyJsPlugin({ minimize: true })) +} + +module.exports = { + entry: './src/index.js', + output: { + path: 'dist/', + filename: isProd ? 'redux-persist.min.js' : 'redux-persist.js', + library: 'redux-persist', + libraryTarget: 'umd' + }, + devtool: 'source-map', + plugins, + module: { + loaders: [ + { test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/ } + ] + } +}