From 804132ce366703814cdbe65eadc49777e2f5a59e Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Sat, 26 Dec 2015 14:22:36 +0000 Subject: [PATCH] [fix] 'process.env.NODE_ENV' check Use babel to transpile the source code without bundling it. Use webpack to create a standalone, productionized UMD bundle. Fix #50 --- README.md | 2 +- config/webpack.config.base.js | 43 -------------------------------- config/webpack.config.example.js | 32 +++++++++++++++++------- config/webpack.config.js | 31 +++++++++++++++++++++++ config/webpack.config.publish.js | 19 -------------- package.json | 25 ++++++++++--------- 6 files changed, 68 insertions(+), 84 deletions(-) delete mode 100644 config/webpack.config.base.js create mode 100644 config/webpack.config.js delete mode 100644 config/webpack.config.publish.js diff --git a/README.md b/README.md index 7ce9e2be..4d4f7ab7 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Build Status][travis-image]][travis-url] [![npm version][npm-image]][npm-url] -![gzipped size](https://img.shields.io/badge/gzipped-~18.6k-blue.svg) +![gzipped size](https://img.shields.io/badge/gzipped-~18.9k-blue.svg) [React Native][react-native-url] components and APIs for the Web. diff --git a/config/webpack.config.base.js b/config/webpack.config.base.js deleted file mode 100644 index 05d23de5..00000000 --- a/config/webpack.config.base.js +++ /dev/null @@ -1,43 +0,0 @@ -var webpack = require('webpack') - -var DedupePlugin = webpack.optimize.DedupePlugin -var DefinePlugin = webpack.DefinePlugin -var OccurenceOrderPlugin = webpack.optimize.OccurenceOrderPlugin -var UglifyJsPlugin = webpack.optimize.UglifyJsPlugin - -var plugins = [ - new DedupePlugin(), - new OccurenceOrderPlugin() -] - -if (process.env.NODE_ENV === 'production') { - plugins.push( - new DefinePlugin({ - 'process.env.NODE_ENV': JSON.stringify('production') - }) - ) - plugins.push( - new UglifyJsPlugin({ - compress: { - dead_code: true, - drop_console: true, - screw_ie8: true, - warnings: true - } - }) - ) -} - -module.exports = { - module: { - loaders: [ - { - test: /\.jsx?$/, - exclude: /node_modules/, - loader: 'babel-loader', - query: { cacheDirectory: true } - } - ] - }, - plugins: plugins -} diff --git a/config/webpack.config.example.js b/config/webpack.config.example.js index 4626ade5..519e7f68 100644 --- a/config/webpack.config.example.js +++ b/config/webpack.config.example.js @@ -1,17 +1,31 @@ -var assign = require('object-assign') -var base = require('./webpack.config.base') var constants = require('./constants') -var path = require('path') +var webpack = require('webpack') -module.exports = assign({}, base, { +module.exports = { devServer: { contentBase: constants.EXAMPLES_DIRECTORY }, entry: { - example: path.join(constants.EXAMPLES_DIRECTORY, 'index') + example: constants.EXAMPLES_DIRECTORY + }, + module: { + loaders: [ + { + test: /\.js$/, + exclude: /node_modules/, + loader: 'babel-loader', + query: { cacheDirectory: true } + } + ] }, output: { - filename: 'examples.js', - path: constants.DIST_DIRECTORY - } -}) + filename: 'examples.js' + }, + plugins: [ + new webpack.DefinePlugin({ + 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development') + }), + new webpack.optimize.DedupePlugin(), + new webpack.optimize.OccurenceOrderPlugin() + ] +} diff --git a/config/webpack.config.js b/config/webpack.config.js new file mode 100644 index 00000000..152ae547 --- /dev/null +++ b/config/webpack.config.js @@ -0,0 +1,31 @@ +var constants = require('./constants') +var webpack = require('webpack') + +module.exports = { + entry: { + main: constants.DIST_DIRECTORY + }, + externals: [{ + 'react': true, + 'react-dom': true + }], + output: { + filename: 'react-native-web.js', + library: 'ReactNativeWeb', + libraryTarget: 'umd', + path: constants.DIST_DIRECTORY + }, + plugins: [ + new webpack.DefinePlugin({ 'process.env.NODE_ENV': 'production' }), + new webpack.optimize.DedupePlugin(), + new webpack.optimize.OccurenceOrderPlugin(), + new webpack.optimize.UglifyJsPlugin({ + compress: { + dead_code: true, + drop_console: true, + screw_ie8: true, + warnings: true + } + }) + ] +} diff --git a/config/webpack.config.publish.js b/config/webpack.config.publish.js deleted file mode 100644 index df4c5a54..00000000 --- a/config/webpack.config.publish.js +++ /dev/null @@ -1,19 +0,0 @@ -var assign = require('object-assign') -var base = require('./webpack.config.base') -var constants = require('./constants') - -module.exports = assign({}, base, { - entry: { - main: constants.SRC_DIRECTORY - }, - externals: [{ - 'react': true, - 'react-dom': true - }], - output: { - filename: 'react-native-web.js', - library: 'ReactNativeWeb', - libraryTarget: 'commonjs2', - path: constants.DIST_DIRECTORY - } -}) diff --git a/package.json b/package.json index 29f5947f..ff38ac60 100644 --- a/package.json +++ b/package.json @@ -2,15 +2,16 @@ "name": "react-native-web", "version": "0.0.12", "description": "React Native for Web", - "main": "dist/react-native-web.js", + "main": "dist/index.js", "files": [ "dist" ], "scripts": { - "build": "rm -rf ./dist && webpack --config config/webpack.config.publish.js --sort-assets-by --progress", + "build": "rm -rf ./dist && mkdir dist && babel src -d dist --ignore src/**/__tests__,src/modules/specHelpers", + "build:umd": "webpack --config config/webpack.config.js --sort-assets-by --progress", "examples": "webpack-dev-server --config config/webpack.config.example.js --inline --hot --colors --quiet", "lint": "eslint config examples src", - "prepublish": "npm run build", + "prepublish": "npm run build && npm run build:umd", "test": "npm run lint && npm run test:unit", "test:unit": "karma start config/karma.config.js", "test:watch": "npm run test:unit -- --no-single-run" @@ -22,20 +23,21 @@ "react-textarea-autosize": "^3.1.0" }, "devDependencies": { - "babel-core": "^6.2.4", + "babel-cli": "^6.3.17", + "babel-core": "^6.3.13", "babel-eslint": "^4.1.6", "babel-loader": "^6.2.0", - "babel-preset-es2015": "^6.2.4", - "babel-preset-react": "^6.2.4", - "babel-preset-stage-1": "^6.2.4", - "babel-runtime": "^6.2.4", + "babel-preset-es2015": "^6.3.13", + "babel-preset-react": "^6.3.13", + "babel-preset-stage-1": "^6.3.13", + "babel-runtime": "^6.3.19", "eslint": "^1.10.3", "eslint-config-standard": "^4.4.0", "eslint-config-standard-react": "^1.2.1", - "eslint-plugin-react": "^3.11.2", + "eslint-plugin-react": "^3.13.1", "eslint-plugin-standard": "^1.3.1", - "karma": "^0.13.15", - "karma-browserstack-launcher": "^0.1.7", + "karma": "^0.13.16", + "karma-browserstack-launcher": "^0.1.8", "karma-chrome-launcher": "^0.2.2", "karma-firefox-launcher": "^0.1.7", "karma-mocha": "^0.2.1", @@ -44,7 +46,6 @@ "karma-webpack": "^1.7.0", "mocha": "^2.3.4", "node-libs-browser": "^0.5.3", - "object-assign": "^4.0.1", "react": "^0.14.3", "react-addons-test-utils": "^0.14.3", "react-dom": "^0.14.3",