diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 1a33f1f2..00000000 --- a/.eslintignore +++ /dev/null @@ -1,2 +0,0 @@ -dist -docs diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 21568aba..a867ca02 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -67,10 +67,10 @@ not want to merge into the project. Development commands: -* `npm start` – start the dev server and develop against live examples +* `npm run build` – build the library +* `npm run dev` – start the dev server and develop against live examples * `npm run lint` – run the linter -* `npm run specs` – run the unit tests -* `npm run build` – generate a build +* `npm run specs:watch` – run and watch the unit tests Please follow this process for submitting a patch: diff --git a/config/constants.js b/config/constants.js new file mode 100644 index 00000000..7c7cfd93 --- /dev/null +++ b/config/constants.js @@ -0,0 +1,9 @@ +var path = require('path') + +var ROOT = path.join(__dirname, '..') + +module.exports = { + DIST_DIRECTORY: path.join(ROOT, 'dist'), + SRC_DIRECTORY: path.join(ROOT, 'src'), + ROOT_DIRECTORY: ROOT +} diff --git a/config/karma.config.js b/config/karma.config.js index fa976379..1886c470 100644 --- a/config/karma.config.js +++ b/config/karma.config.js @@ -1,10 +1,10 @@ var assign = require('object-assign') -var path = require('path') -var webpackConfig = require('./webpack-base.config.js') +var constants = require('./constants') +var webpackConfig = require('./webpack.config.base') module.exports = function (config) { config.set({ - basePath: path.resolve(__dirname, '..'), + basePath: constants.ROOT_DIRECTORY, browsers: [ process.env.TRAVIS ? 'Firefox' : 'Chrome' ], browserNoActivityTimeout: 60000, client: { @@ -15,7 +15,7 @@ module.exports = function (config) { useIframe: true }, files: [ - 'src/specs.bundle.js' + 'src/specs.context.js' ], frameworks: [ 'mocha' @@ -28,7 +28,7 @@ module.exports = function (config) { 'karma-webpack' ], preprocessors: { - 'src/specs.bundle.js': [ 'webpack', 'sourcemap' ] + 'src/specs.context.js': [ 'webpack', 'sourcemap' ] }, reporters: [ 'dots' ], singleRun: true, diff --git a/config/webpack-base.config.js b/config/webpack-base.config.js deleted file mode 100644 index 9fff4fe8..00000000 --- a/config/webpack-base.config.js +++ /dev/null @@ -1,23 +0,0 @@ -var autoprefixer = require('autoprefixer-core') - -module.exports = { - module: { - loaders: [ - { - test: /\.css$/, - loader: [ - 'style-loader', - 'css-loader?module&localIdentName=[hash:base64:5]', - '!postcss-loader' - ].join('!') - }, - { - test: /\.jsx?$/, - exclude: /node_modules/, - loader: 'babel-loader', - query: { cacheDirectory: true } - } - ] - }, - postcss: [ autoprefixer ] -} diff --git a/config/webpack.config.base.js b/config/webpack.config.base.js new file mode 100644 index 00000000..47532220 --- /dev/null +++ b/config/webpack.config.base.js @@ -0,0 +1,47 @@ +var autoprefixer = require('autoprefixer-core') +var webpack = require('webpack') + +var DedupePlugin = webpack.optimize.DedupePlugin +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 UglifyJsPlugin({ + compress: { + dead_code: true, + drop_console: true, + screw_ie8: true, + warnings: true + } + }) + ) +} + +module.exports = { + module: { + loaders: [ + { + test: /\.css$/, + loader: [ + 'style-loader', + 'css-loader?module&localIdentName=[hash:base64:5]', + '!postcss-loader' + ].join('!') + }, + { + test: /\.jsx?$/, + exclude: /node_modules/, + loader: 'babel-loader', + query: { cacheDirectory: true } + } + ] + }, + plugins: plugins, + postcss: [ autoprefixer ] +} diff --git a/config/webpack.config.example.js b/config/webpack.config.example.js new file mode 100644 index 00000000..e0975d46 --- /dev/null +++ b/config/webpack.config.example.js @@ -0,0 +1,17 @@ +var assign = require('object-assign') +var base = require('./webpack.config.base') +var constants = require('./constants') +var path = require('path') + +module.exports = assign({}, base, { + devServer: { + contentBase: constants.SRC_DIRECTORY + }, + entry: { + example: path.join(constants.SRC_DIRECTORY, 'example') + }, + output: { + filename: 'example.js', + path: constants.DIST_DIRECTORY + } +}) diff --git a/config/webpack.config.js b/config/webpack.config.js deleted file mode 100644 index ec9c4d8a..00000000 --- a/config/webpack.config.js +++ /dev/null @@ -1,34 +0,0 @@ -var assign = require('object-assign') -var base = require('./webpack-base.config.js') -var webpack = require('webpack') -var UglifyJsPlugin = webpack.optimize.UglifyJsPlugin - -var plugins = [] -if (process.env.NODE_ENV === 'production') { - plugins.push( - new UglifyJsPlugin({ - compress: { - dead_code: true, - drop_console: true, - screw_ie8: true, - warnings: true - } - }) - ) -} - -module.exports = assign({}, base, { - entry: { - main: './src/index' - }, - externals: [{ - react: true - }], - output: { - filename: 'react-native-web.js', - library: 'ReactNativeWeb', - libraryTarget: 'commonjs2', - path: './dist' - }, - plugins: plugins -}) diff --git a/config/webpack.config.publish.js b/config/webpack.config.publish.js new file mode 100644 index 00000000..601da79a --- /dev/null +++ b/config/webpack.config.publish.js @@ -0,0 +1,18 @@ +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 + }], + output: { + filename: 'react-native-web.js', + library: 'ReactNativeWeb', + libraryTarget: 'commonjs2', + path: constants.DIST_DIRECTORY + } +}) diff --git a/example/index.html b/example/index.html deleted file mode 100644 index 035dcf31..00000000 --- a/example/index.html +++ /dev/null @@ -1,5 +0,0 @@ - - - -
- diff --git a/example/webpack.config.js b/example/webpack.config.js deleted file mode 100644 index a54fff4f..00000000 --- a/example/webpack.config.js +++ /dev/null @@ -1,19 +0,0 @@ -module.exports = { - entry: { - example: './example.js' - }, - module: { - loaders: [ - { - test: /\.jsx?$/, - exclude: /node_modules/, - loader: 'babel-loader', - query: { cacheDirectory: true } - } - ] - }, - output: { - filename: 'example.js', - path: '../dist' - } -} diff --git a/package.json b/package.json index c8f687d5..3878c125 100644 --- a/package.json +++ b/package.json @@ -7,13 +7,12 @@ "dist" ], "scripts": { + "build": "rm -rf ./dist && webpack --config config/webpack.config.publish.js --sort-assets-by --progress", + "dev": "webpack-dev-server --config config/webpack.config.example.js --inline --colors --quiet", + "lint": "eslint config src", "prepublish": "npm run build", - "build": "rm -rf ./dist && webpack --config config/webpack.config.js --sort-assets-by --progress", - "example": "cd example && webpack --config webpack.config.js", - "lint": "eslint .", "specs": "NODE_ENV=test karma start config/karma.config.js", "specs:watch": "npm run specs -- --no-single-run", - "start": "webpack-dev-server --config config/webpack.config.js --inline --hot --colors --quiet", "test": "npm run specs && npm run lint" }, "dependencies": { diff --git a/example/example.js b/src/example.js similarity index 99% rename from example/example.js rename to src/example.js index 8fab0740..6e068937 100644 --- a/example/example.js +++ b/src/example.js @@ -1,4 +1,4 @@ -import React, { Image, Swipeable, Text, TextInput, Touchable, View } from '../dist/react-native-web' +import React, { Image, Swipeable, Text, TextInput, Touchable, View } from '.' const { Component, PropTypes } = React diff --git a/src/index.html b/src/index.html new file mode 100644 index 00000000..c80817a9 --- /dev/null +++ b/src/index.html @@ -0,0 +1,7 @@ + + +React Native for Web + + +
+ diff --git a/src/specs.bundle.js b/src/specs.context.js similarity index 100% rename from src/specs.bundle.js rename to src/specs.context.js