From 17c2c02c12d31d767eae176c88b55dfac6978db2 Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Wed, 22 Nov 2017 20:36:21 -0500 Subject: [PATCH] Switch to Preact CLI --- .babelrc | 11 ----- .eslintrc | 40 ----------------- README.md | 4 +- package.json | 53 +++++++--------------- src/components/todo-item.js | 8 ++-- src/index.js | 5 +-- src/reducers.js | 4 +- src/store.js | 2 +- webpack.config.babel.js | 90 ------------------------------------- 9 files changed, 25 insertions(+), 192 deletions(-) delete mode 100644 .babelrc delete mode 100644 .eslintrc delete mode 100644 webpack.config.babel.js diff --git a/.babelrc b/.babelrc deleted file mode 100644 index 652867c..0000000 --- a/.babelrc +++ /dev/null @@ -1,11 +0,0 @@ -{ - "sourceMaps": true, - "presets": [ - "es2015-minimal", - "stage-0" - ], - "plugins": [ - ["transform-decorators-legacy"], - ["transform-react-jsx", { "pragma": "h" }] - ] -} diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 940e483..0000000 --- a/.eslintrc +++ /dev/null @@ -1,40 +0,0 @@ -{ - "parser": "babel-eslint", - "rules": { - "semi": 2, - "camelcase": 0, - "comma-style": 2, - "comma-dangle": [2, "never"], - "indent": [2, "tab", {"SwitchCase": 1}], - "no-mixed-spaces-and-tabs": [2, "smart-tabs"], - "no-trailing-spaces": [2, { "skipBlankLines": true }], - "max-nested-callbacks": [2, 3], - "no-eval": 2, - "no-implied-eval": 2, - "no-new-func": 2, - "guard-for-in": 2, - "eqeqeq": 2, - "no-else-return": 2, - "no-redeclare": 2, - "no-dupe-keys": 2, - "radix": 2, - "strict": [2, "never"], - "no-shadow": 0, - "callback-return": [1, ["callback", "cb", "next", "done"]], - "no-delete-var": 2, - "no-undef-init": 2, - "no-shadow-restricted-names": 2, - "handle-callback-err": 0, - "no-lonely-if": 2, - "keyword-spacing": 2, - "constructor-super": 2, - "no-this-before-super": 2, - "no-dupe-class-members": 2, - "no-const-assign": 2, - "prefer-spread": 2, - "no-useless-concat": 2, - "no-var": 2, - "object-shorthand": 2, - "prefer-arrow-callback": 2 - } -} diff --git a/README.md b/README.md index 08aa4bb..b499ab4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Preact Redux Example -A **10kb** Redux-powered alternative to [preact-boilerplate](https://github.com/developit/preact-boilerplate), implementing a To-Do List app. +A **10kb** Preact + Redux boilerplate built with [Preact CLI], implementing a To-Do List app. @@ -100,4 +100,4 @@ MIT [Preact]: https://github.com/developit/preact -[webpack]: https://webpack.github.io +[Preact CLI]: https://github.com/developit/preact-cli diff --git a/package.json b/package.json index 971eaf0..8c2c0cf 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,16 @@ { "name": "preact-redux-example", "version": "1.0.0", - "description": "Ready-to-go Preact + Redux starter project, powered by webpack.", + "description": "Ready-to-go Preact + Redux starter project, powered by Preact CLI.", "scripts": { - "dev": "cross-env NODE_ENV=development webpack-dev-server --inline --hot --progress", - "start": "superstatic build -p 8080 --host 0.0.0.0 --gzip -c '{\"rewrites\": [{\"source\":\"**\",\"destination\":\"index.html\"}],\"headers\":[{\"source\":\"**\",\"headers\":[{\"key\":\"Cache-Control\",\"value\":\"max-age=86400\"}]}]}'", - "prestart": "npm run build", - "build": "cross-env NODE_ENV=production webpack -p --progress", - "prebuild": "mkdirp build", - "test": "eslint src tests/**/*.js" + "start": "if-env NODE_ENV=production && npm run -s serve || npm run -s dev", + "build": "preact build", + "serve": "preact build && preact serve", + "dev": "preact watch", + "lint": "eslint src" + }, + "eslintConfig": { + "extends": "eslint-config-synacor" }, "keywords": [ "preact", @@ -17,37 +19,12 @@ "license": "MIT", "author": "Jason Miller ", "devDependencies": { - "autoprefixer": "^6.3.6", - "babel": "^6.5.2", - "babel-core": "^6.9.1", - "babel-eslint": "^6.0.4", - "babel-loader": "^6.2.4", - "babel-plugin-transform-decorators-legacy": "^1.3.4", - "babel-plugin-transform-react-jsx": "^6.8.0", - "babel-preset-es2015": "^6.9.0", - "babel-preset-es2015-minimal": "^2.0.0", - "babel-preset-stage-0": "^6.5.0", - "babel-register": "^6.9.0", - "babel-runtime": "^6.9.2", - "chai": "^3.5.0", - "core-js": "^2.4.0", - "cross-env": "^1.0.8", - "css-loader": "^0.23.1", - "eslint": "^2.11.1", - "extract-text-webpack-plugin": "^1.0.1", - "file-loader": "^0.8.5", - "html-webpack-plugin": "^2.19.0", - "json-loader": "^0.5.4", - "less": "^2.7.1", - "less-loader": "^2.2.3", - "mkdirp": "^0.5.1", - "postcss-loader": "^0.9.1", - "raw-loader": "^0.5.1", - "source-map-loader": "^0.1.5", - "superstatic": "^4.0.2", - "url-loader": "^0.5.7", - "webpack": "^1.13.1", - "webpack-dev-server": "^1.14.1" + "eslint": "^4.5.0", + "eslint-config-synacor": "^1.1.0", + "if-env": "^1.0.0", + "less": "^2.7.3", + "less-loader": "^4.0.5", + "preact-cli": "^2.0.0" }, "dependencies": { "preact": "^8.1.0", diff --git a/src/components/todo-item.js b/src/components/todo-item.js index 6e956e1..a005442 100644 --- a/src/components/todo-item.js +++ b/src/components/todo-item.js @@ -1,15 +1,15 @@ import { h, Component } from 'preact'; export default class TodoItem extends Component { - shouldComponentUpdate({ todo, onRemove }) { - return todo !== this.props.todo || onRemove !== this.props.onRemove; - } - remove = () => { let { onRemove, todo } = this.props; onRemove(todo); }; + shouldComponentUpdate({ todo, onRemove }) { + return todo !== this.props.todo || onRemove !== this.props.onRemove; + } + render({ todo }) { return (
  • diff --git a/src/index.js b/src/index.js index dca8676..2597494 100755 --- a/src/index.js +++ b/src/index.js @@ -1,13 +1,12 @@ -import { h, render } from 'preact'; import { Provider } from 'preact-redux'; import store from './store'; import App from './components/app'; import './style'; -render(( +export default () => (
    -), document.body); +); diff --git a/src/reducers.js b/src/reducers.js index 13284db..8da1ff1 100644 --- a/src/reducers.js +++ b/src/reducers.js @@ -1,6 +1,4 @@ const EMPTY = {}; -export default store => { - return store || EMPTY; -}; +export default store => store || EMPTY; diff --git a/src/store.js b/src/store.js index 641fc27..7b20d57 100644 --- a/src/store.js +++ b/src/store.js @@ -21,4 +21,4 @@ const INITIAL = { export default createStore( (state, action) => ( action && ACTIONS[action.type] ? ACTIONS[action.type](state, action) : state -), INITIAL, window.devToolsExtension && window.devToolsExtension()); +), INITIAL, typeof devToolsExtension==='function' ? devToolsExtension() : undefined); diff --git a/webpack.config.babel.js b/webpack.config.babel.js deleted file mode 100644 index c605898..0000000 --- a/webpack.config.babel.js +++ /dev/null @@ -1,90 +0,0 @@ -import webpack from 'webpack'; -import ExtractTextPlugin from 'extract-text-webpack-plugin'; -import HtmlWebpackPlugin from 'html-webpack-plugin'; -import autoprefixer from 'autoprefixer'; - -const ENV = process.env.NODE_ENV || 'development'; - -module.exports = { - entry: './src/index.js', - - output: { - path: './build', - publicPath: '/', - filename: 'bundle.js' - }, - - resolve: { - extensions: ['', '.jsx', '.js', '.json', '.less'] - }, - - module: { - preLoaders: [ - { - test: /\.jsx?$/, - exclude: /src\//, - loader: 'source-map' - } - ], - loaders: [ - { - test: /\.jsx?$/, - exclude: /node_modules/, - loader: 'babel' - }, - { - test: /\.(less|css)$/, - loader: ExtractTextPlugin.extract('css?sourceMap!postcss!less?sourceMap') - }, - { - test: /\.json$/, - loader: 'json' - }, - { - test: /\.(xml|html|txt)$/, - loader: 'raw' - }, - { - test: /\.(svg|woff|ttf|eot)(\?.*)?$/i, - loader: 'file-loader?name=assets/fonts/[name]_[hash:base64:5].[ext]' - } - ] - }, - - postcss: () => [ - autoprefixer({ browsers: 'last 2 versions' }) - ], - - plugins: ([ - new webpack.NoErrorsPlugin(), - new ExtractTextPlugin('style.css', { allChunks: true }), - new webpack.DefinePlugin({ - 'process.env.NODE_ENV': JSON.stringify(ENV) - }), - new HtmlWebpackPlugin() - ]).concat(ENV === 'production' ? [ - new webpack.optimize.DedupePlugin(), - new webpack.optimize.OccurenceOrderPlugin() - ] : []), - - stats: { colors: true }, - - devtool: ENV === 'production' ? 'source-map' : 'inline-source-map', - - devServer: { - port: process.env.PORT || 8080, - host: '0.0.0.0', - colors: true, - publicPath: '/', - contentBase: './src', - historyApiFallback: true, - proxy: [ - // OPTIONAL: proxy configuration: - // { - // path: '/optional-prefix/**', - // target: 'http://target-host.com', - // rewrite: req => { req.url = req.url.replace(/^\/[^\/]+\//, ''); } // strip first path segment - // } - ] - } -};