diff --git a/package.json b/package.json index b2a6a52762463..2f0f73ae90a2b 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,10 @@ "rimraf": "^2.6.1", "yargs": "^10.0.3" }, + "peerDependencies": { + "inferno": "6.x", + "inferno-compat": "6.x" + }, "engines": { "yarn": "^1.2.1", "node": ">=6.11.5" diff --git a/packages/gatsby-plugin-inferno/.babelrc b/packages/gatsby-plugin-inferno/.babelrc new file mode 100644 index 0000000000000..49f11f3ac4077 --- /dev/null +++ b/packages/gatsby-plugin-inferno/.babelrc @@ -0,0 +1,5 @@ +{ + "presets": [ + ["../../.babel-preset.js", { "browser": true }] + ] +} diff --git a/packages/gatsby-plugin-inferno/.gitignore b/packages/gatsby-plugin-inferno/.gitignore new file mode 100644 index 0000000000000..8c9686624a187 --- /dev/null +++ b/packages/gatsby-plugin-inferno/.gitignore @@ -0,0 +1,3 @@ +/*.js +!index.js +yarn.lock diff --git a/packages/gatsby-plugin-inferno/.npmignore b/packages/gatsby-plugin-inferno/.npmignore new file mode 100644 index 0000000000000..e771d2c9fa299 --- /dev/null +++ b/packages/gatsby-plugin-inferno/.npmignore @@ -0,0 +1,34 @@ +# Logs +logs +*.log + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directory +# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git +node_modules +*.un~ +yarn.lock +src +flow-typed +coverage +decls +examples diff --git a/packages/gatsby-plugin-inferno/README.md b/packages/gatsby-plugin-inferno/README.md new file mode 100644 index 0000000000000..5ee14a38e3a54 --- /dev/null +++ b/packages/gatsby-plugin-inferno/README.md @@ -0,0 +1,19 @@ +# gatsby-plugin-inferno + +Provides drop-in support for replacing React with [Inferno](https://infernojs.org/). + +While Inferno doesn't provide full support for the React ecosystem, it is an +intriguing option for Gatsby sites as it both offers bundle size and performance benefits over React + +## Install + +`npm install --save gatsby-plugin-preact inferno inferno-compat` + +More information can be found on [inferno-compat's README](https://github.com/infernojs/inferno/tree/master/packages/inferno-compat). They allow you to customize what React features you support via additional packages + +## How to use + +```javascript +// In your gatsby-config.js +plugins: [`gatsby-plugin-inferno`] +``` diff --git a/packages/gatsby-plugin-inferno/index.js b/packages/gatsby-plugin-inferno/index.js new file mode 100644 index 0000000000000..172f1ae6a468c --- /dev/null +++ b/packages/gatsby-plugin-inferno/index.js @@ -0,0 +1 @@ +// noop diff --git a/packages/gatsby-plugin-inferno/package.json b/packages/gatsby-plugin-inferno/package.json new file mode 100644 index 0000000000000..e68b2110c595a --- /dev/null +++ b/packages/gatsby-plugin-inferno/package.json @@ -0,0 +1,34 @@ +{ + "name": "gatsby-plugin-inferno", + "description": "A Gatsby plugin which replaces React with Inferno", + "version": "1.0.0", + "author": "Kyle Mathews ", + "bugs": { + "url": "https://github.com/gatsbyjs/gatsby/issues" + }, + "dependencies": { + "@babel/runtime": "^7.0.0" + }, + "devDependencies": { + "@babel/cli": "^7.0.0", + "@babel/core": "^7.0.0", + "cross-env": "^5.1.4" + }, + "homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-inferno#readme", + "keywords": [ + "gatsby", + "gatsby-plugin", + "inferno" + ], + "license": "MIT", + "main": "index.js", + "peerDependencies": { + "gatsby": ">2.0.0-alpha" + }, + "repository": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-inferno", + "scripts": { + "build": "babel src --out-dir . --ignore **/__tests__", + "prepare": "cross-env NODE_ENV=production npm run build", + "watch": "babel -w src --out-dir . --ignore **/__tests__" + } +} diff --git a/packages/gatsby-plugin-inferno/src/gatsby-node.js b/packages/gatsby-plugin-inferno/src/gatsby-node.js new file mode 100644 index 0000000000000..a027488bd9a58 --- /dev/null +++ b/packages/gatsby-plugin-inferno/src/gatsby-node.js @@ -0,0 +1,16 @@ +exports.onCreateWebpackConfig = ({ stage, actions }) => { + /* + * Inferno doesn't currently support Hot Module Reloading + * in development mode, so we'll exclude it from the process then + */ + if (stage !== `develop-html` && stage !== `develop`) { + actions.setWebpackConfig({ + resolve: { + alias: { + react: `inferno-compat`, + "react-dom": `inferno-compat`, + }, + }, + }) + } +}