diff --git a/README.md b/README.md index 443a4f5..eb4290e 100644 --- a/README.md +++ b/README.md @@ -2,31 +2,54 @@ Kickstarts a new React app +### The Webpack configuration sits in [our Create React App fork](https://github.com/Neverbland/create-react-app/tree/master/packages/react-scripts) for easier maintainability. +This repository is intended to replace the `/template` folder of Create React App. + +This package includes scripts and configuration used by [Create React App](https://github.com/facebookincubator/create-react-app).
+Please refer to its documentation: + +* [User Guide](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md) – How to develop apps bootstrapped with Create React App. + + ## Features -* React +* [Every Create React App features](https://github.com/facebookincubator/create-react-app#whats-inside) * React Router -* Webpack * SCSS -* hot reloading (css and React components) * SVG sprites * Assets optimisation (png, jpg, svg, ...) * Automatic polyfilling (using Polyfill.io) ## Getting started -- Install: `npm install` -- Start dev: `npm start` -- Production build: `npm run build` +### `npm install` or `yarn start` +Install the project. -## Testing +### `npm start` or `yarn start` -- Lint SCSS: `npm run lint:scss` +Runs the app in development mode.
+Open [http://localhost:3000](http://localhost:3000) to view it in the browser. + +### `npm run build` or `yarn build` + +Builds the app for production to the `build` folder.
+It correctly bundles React in production mode and optimizes the build for the best performance. + +The build is minified and the filenames include the hashes.
+By default, it also [includes a service worker](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#making-a-progressive-web-app) so that your app loads from local cache on future visits. + +## Writing JS + +We use [EditorConfig](http://editorconfig.org/) for code consistency. Please see below to add support to your editor. ## Writing CSS We use [BEM](https://en.bem.info/) across our projects. +## Testing + +- Lint SCSS: `npm run lint:scss` + ## Polyfills We use [Polyfill.io](https://polyfill.io/v2/docs/) to polyfill missing Javascript functionality. Simply add any missing functionality by appending the polyfill.io url in `src/public/index.html` with the feature you need. @@ -35,10 +58,9 @@ We use [Polyfill.io](https://polyfill.io/v2/docs/) to polyfill missing Javascrip - ESLint ([Atom Plugin](https://atom.io/packages/linter-eslint)/[Sublime Plugin](https://github.com/roadhump/SublimeLinter-eslint)) - SASS Lint ([Atom Plugin](https://atom.io/packages/linter-sass-lint)/[Sublime Plugin](https://github.com/skovhus/SublimeLinter-contrib-sass-lint)) +- EditorConfig ([Atom Plugin](https://atom.io/packages/editorconfig)/[Sublime Plugin](https://github.com/sindresorhus/editorconfig-sublime)) - Beautifier ([Atom Plugin](https://atom.io/packages/atom-beautify)) ## License [MIT license](http://opensource.org/licenses/MIT) - -This project was bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app). diff --git a/config/babel.dev.js b/config/babel.dev.js deleted file mode 100644 index 59b69d2..0000000 --- a/config/babel.dev.js +++ /dev/null @@ -1,40 +0,0 @@ -var path = require('path'); -var findCacheDir = require('find-cache-dir'); - -module.exports = { - // Don't try to find .babelrc because we want to force this configuration. - babelrc: false, - // This is a feature of `babel-loader` for webpack (not Babel itself). - // It enables caching results in ./node_modules/.cache/react-scripts/ - // directory for faster rebuilds. We use findCacheDir() because of: - // https://github.com/facebookincubator/create-react-app/issues/483 - cacheDirectory: findCacheDir({ - name: 'react-scripts' - }), - presets: [ - // Latest stable ECMAScript features - require.resolve('babel-preset-latest'), - // JSX - require.resolve('babel-preset-react') - ], - plugins: [ - // class { handleClick = () => { } } - require.resolve('babel-plugin-transform-class-properties'), - // { ...todo, completed: true } - require.resolve('babel-plugin-transform-object-rest-spread'), - // function* () { yield 42; yield 43; } - [require.resolve('babel-plugin-transform-regenerator'), { - // Async functions are converted to generators by babel-preset-latest - async: false - }], - // Polyfills the runtime needed for async/await and generators - [require.resolve('babel-plugin-transform-runtime'), { - helpers: false, - polyfill: false, - regenerator: true, - // Resolve the Babel runtime relative to the config. - // You can safely remove this after ejecting: - moduleName: path.dirname(require.resolve('babel-runtime/package')) - }] - ] -}; diff --git a/config/babel.prod.js b/config/babel.prod.js deleted file mode 100644 index aea10be..0000000 --- a/config/babel.prod.js +++ /dev/null @@ -1,38 +0,0 @@ -var path = require('path'); - -module.exports = { - // Don't try to find .babelrc because we want to force this configuration. - babelrc: false, - presets: [ - // Latest stable ECMAScript features - require.resolve('babel-preset-latest'), - // JSX - require.resolve('babel-preset-react') - ], - plugins: [ - // class { handleClick = () => { } } - require.resolve('babel-plugin-transform-class-properties'), - // { ...todo, completed: true } - require.resolve('babel-plugin-transform-object-rest-spread'), - // function* () { yield 42; yield 43; } - [require.resolve('babel-plugin-transform-regenerator'), { - // Async functions are converted to generators by babel-preset-latest - async: false - }], - // Polyfills the runtime needed for async/await and generators - [require.resolve('babel-plugin-transform-runtime'), { - helpers: false, - polyfill: false, - regenerator: true, - // Resolve the Babel runtime relative to the config. - // You can safely remove this after ejecting: - moduleName: path.dirname(require.resolve('babel-runtime/package')) - }], - // Optimization: hoist JSX that never changes out of render() - // Disabled because of issues: - // * https://github.com/facebookincubator/create-react-app/issues/525 - // * https://phabricator.babeljs.io/search/query/pCNlnC2xzwzx/ - // TODO: Enable again when these issues are resolved. - // require.resolve('babel-plugin-transform-react-constant-elements') - ] -}; diff --git a/config/env.js b/config/env.js deleted file mode 100644 index 80f77a7..0000000 --- a/config/env.js +++ /dev/null @@ -1,27 +0,0 @@ -// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be -// injected into the application via DefinePlugin in Webpack configuration. - -var REACT_APP = /^REACT_APP_/i; - -function getClientEnvironment(publicUrl) { - return Object - .keys(process.env) - .filter(key => REACT_APP.test(key)) - .reduce((env, key) => { - env['process.env.' + key] = JSON.stringify(process.env[key]); - return env; - }, { - // Useful for determining whether we’re running in production mode. - // Most importantly, it switches React into the correct mode. - 'process.env.NODE_ENV': JSON.stringify( - process.env.NODE_ENV || 'development' - ), - // Useful for resolving the correct path to static assets in `public`. - // For example, . - // This should only be used as an escape hatch. Normally you would put - // images into the `src` and `import` them in code to get their paths. - 'process.env.PUBLIC_URL': JSON.stringify(publicUrl) - }); -} - -module.exports = getClientEnvironment; diff --git a/config/eslint.js b/config/eslint.js deleted file mode 100644 index d64745c..0000000 --- a/config/eslint.js +++ /dev/null @@ -1,56 +0,0 @@ -module.exports = { - root: true, - parser: 'babel-eslint', - extends: 'airbnb', - plugins: ['import', 'jsx-a11y', 'react'], - env: { - browser: true, - commonjs: true, - es6: true, - jest: true, - node: true - }, - parserOptions: { - ecmaVersion: 6, - sourceType: 'module', - ecmaFeatures: { - jsx: true, - generators: true, - experimentalObjectRestSpread: true - } - }, - settings: { - 'import/ignore': [ - 'node_modules', - '\\.(json|css|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$' - ], - 'import/extensions': ['.js'], - 'import/resolver': { - node: { - extensions: ['.js', '.json'] - } - } - }, - rules: { - 'arrow-body-style': [0], - 'arrow-parens': [0], - 'class-methods-use-this': [0], - 'comma-dangle': ['error', 'never'], - 'global-require': [0], - 'import/no-dynamic-require': [0], - 'import/prefer-default-export': [0], - 'jsx-a11y/no-static-element-interactions': [0], - 'max-len': [0], - 'no-plusplus': [0], - radix: [0], - 'react/forbid-prop-types': [0], - 'react/jsx-filename-extension': [1, { - extensions: ['.js', '.jsx'] - }], - 'react/jsx-no-bind': [0], - 'react/no-danger': [0], - 'react/prop-types': [0], - 'react/react-in-jsx-scope': [0], - 'react/style-prop-object': [0] - } -}; diff --git a/config/jest/CSSStub.js b/config/jest/CSSStub.js deleted file mode 100644 index f053ebf..0000000 --- a/config/jest/CSSStub.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = {}; diff --git a/config/jest/FileStub.js b/config/jest/FileStub.js deleted file mode 100644 index 0a445d0..0000000 --- a/config/jest/FileStub.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = "test-file-stub"; diff --git a/config/jest/transform.js b/config/jest/transform.js deleted file mode 100644 index 75f893c..0000000 --- a/config/jest/transform.js +++ /dev/null @@ -1,4 +0,0 @@ -const babelDev = require('../babel.dev'); -const babelJest = require('babel-jest'); - -module.exports = babelJest.createTransformer(babelDev); diff --git a/config/paths.js b/config/paths.js deleted file mode 100644 index 45b3eba..0000000 --- a/config/paths.js +++ /dev/null @@ -1,40 +0,0 @@ -var path = require('path'); -var fs = require('fs'); - -// Make sure any symlinks in the project folder are resolved: -// https://github.com/facebookincubator/create-react-app/issues/637 -var appDirectory = fs.realpathSync(process.cwd()); -function resolveApp(relativePath) { - return path.resolve(appDirectory, relativePath); -} - -// We support resolving modules according to `NODE_PATH`. -// This lets you use absolute paths in imports inside large monorepos: -// https://github.com/facebookincubator/create-react-app/issues/253. - -// It works similar to `NODE_PATH` in Node itself: -// https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders - -// We will export `nodePaths` as an array of absolute paths. -// It will then be used by Webpack configs. -// Jest doesn’t need this because it already handles `NODE_PATH` out of the box. - -var nodePaths = (process.env.NODE_PATH || '') - .split(process.platform === 'win32' ? ';' : ':') - .filter(Boolean) - .map(resolveApp); - -// config after eject: we're in ./config/ -module.exports = { - appBuild: resolveApp('build'), - appPublic: resolveApp('src/public'), - appHtml: resolveApp('src/public/index.html'), - appSprite: resolveApp('src/images/sprite'), - appIndexJs: resolveApp('src/index.js'), - appPackageJson: resolveApp('package.json'), - appSrc: resolveApp('src'), - testsSetup: resolveApp('src/setupTests.js'), - appNodeModules: resolveApp('node_modules'), - ownNodeModules: resolveApp('node_modules'), - nodePaths: nodePaths -}; diff --git a/config/sasslint.yml b/config/sasslint.yml deleted file mode 100644 index cc045b1..0000000 --- a/config/sasslint.yml +++ /dev/null @@ -1,98 +0,0 @@ -options: - formatter: stylish -files: - include: '**/*.s+(a|c)ss' - ignore: - - 'src/css/vendor/*.scss' - - 'src/css/scratchpad.scss' -rules: - # Extends - extends-before-mixins: 1 - extends-before-declarations: 1 - placeholder-in-extend: 1 - - # Mixins - mixins-before-declarations: 0 - - # Line Spacing - one-declaration-per-line: 1 - empty-line-between-blocks: 1 - single-line-per-selector: 1 - - # Disallows - no-attribute-selectors: 0 - no-color-hex: 0 - no-color-keywords: 1 - no-color-literals: 1 - no-combinators: 0 - no-css-comments: 1 - no-debug: 1 - no-disallowed-properties: 0 - no-duplicate-properties: 2 - no-empty-rulesets: 1 - no-extends: 0 - no-ids: 1 - no-important: 1 - no-invalid-hex: 1 - no-mergeable-selectors: 2 - no-misspelled-properties: 1 - no-qualifying-elements: 1 - no-trailing-whitespace: 1 - no-trailing-zero: 0 - no-transition-all: 2 - no-universal-selectors: 0 - no-url-protocols: 1 - no-vendor-prefixes: 1 - no-warn: 1 - property-units: 0 - - # Nesting - force-attribute-nesting: 0 - force-element-nesting: 0 - force-pseudo-nesting: 0 - - # Name Formats - class-name-format: - - 2 - - - convention: 'hyphenatedbem' - convention-explanation: "butt" - function-name-format: 1 - id-name-format: 0 - mixin-name-format: 1 - placeholder-name-format: 1 - variable-name-format: 1 - - # Style Guide - attribute-quotes: 1 - bem-depth: 2 - border-zero: 1 - brace-style: 1 - clean-import-paths: 1 - empty-args: 0 - hex-length: 0 - hex-notation: 0 - indentation: 2 - leading-zero: 0 - nesting-depth: 2 - property-sort-order: 0 - pseudo-element: 0 - quotes: 0 - shorthand-values: 1 - url-quotes: 1 - variable-for-property: 1 - zero-unit: 1 - - # Inner Spacing - space-after-comma: 1 - space-before-colon: 1 - space-after-colon: 1 - space-before-brace: 2 - space-before-bang: 1 - space-after-bang: 1 - space-between-parens: 1 - space-around-operator: 1 - - # Final Items - trailing-semicolon: 1 - final-newline: 1 diff --git a/config/webpack.config.dev.js b/config/webpack.config.dev.js deleted file mode 100755 index c701f40..0000000 --- a/config/webpack.config.dev.js +++ /dev/null @@ -1,203 +0,0 @@ -var path = require('path'); -var autoprefixer = require('autoprefixer'); -var postcssFlexbugsFixes = require('postcss-flexbugs-fixes'); -var webpack = require('webpack'); -var findCacheDir = require('find-cache-dir'); -var HtmlWebpackPlugin = require('html-webpack-plugin'); -var CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin'); -var InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin'); -var WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin'); -var getClientEnvironment = require('./env'); -var paths = require('./paths'); - -// Webpack uses `publicPath` to determine where the app is being served from. -// In development, we always serve from the root. This makes config easier. -var publicPath = '/'; -// `publicUrl` is just like `publicPath`, but we will provide it to our app -// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript. -// Omit trailing shlash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz. -var publicUrl = ''; -// Get enrivonment variables to inject into our app. -var env = getClientEnvironment(publicUrl); - -// This is the development configuration. -// It is focused on developer experience and fast rebuilds. -// The production configuration is different and lives in a separate file. -module.exports = { - // This makes the bundle appear split into separate modules in the devtools. - // We don't use source maps here because they can be confusing: - // https://github.com/facebookincubator/create-react-app/issues/343#issuecomment-237241875 - // You may want 'cheap-module-source-map' instead if you prefer source maps. - devtool: 'cheap-module-source-map', - // These are the "entry points" to our application. - // This means they will be the "root" imports that are included in JS bundle. - // The first two entry points enable "hot" CSS and auto-refreshes for JS. - entry: [ - // Include an alternative client for WebpackDevServer. A client's job is to - // connect to WebpackDevServer by a socket and get notified about changes. - // When you save a file, the client will either apply hot updates (in case - // of CSS changes), or refresh the page (in case of JS changes). When you - // make a syntax error, this client will display a syntax error overlay. - // Note: instead of the default WebpackDevServer client, we use a custom one - // to bring better experience for Create React App users. You can replace - // the line below with these two lines if you prefer the stock client: - require.resolve('webpack-dev-server/client') + '?/', - require.resolve('webpack/hot/dev-server'), - // require.resolve('react-dev-utils/webpackHotDevClient'), - // Hot loader - require.resolve('react-hot-loader/patch'), - // Finally, this is your app's code: - paths.appIndexJs - // We include the app code last so that if there is a runtime error during - // initialization, it doesn't blow up the WebpackDevServer client, and - // changing JS code would still trigger a refresh. - ], - output: { - // Next line is not used in dev but WebpackDevServer crashes without it: - path: paths.appBuild, - // Add /* filename */ comments to generated require()s in the output. - pathinfo: true, - // This does not produce a real file. It's just the virtual path that is - // served by WebpackDevServer in development. This is the JS bundle - // containing code from all our entry points, and the Webpack runtime. - filename: 'js/bundle.js', - // This is the URL that app is served from. We use "/" in development. - publicPath: publicPath - }, - resolve: { - // This allows you to set a fallback for where Webpack should look for modules. - // We read `NODE_PATH` environment variable in `paths.js` and pass paths here. - // We use `fallback` instead of `root` because we want `node_modules` to "win" - // if there any conflicts. This matches Node resolution mechanism. - // https://github.com/facebookincubator/create-react-app/issues/253 - fallback: paths.nodePaths, - // These are the reasonable defaults supported by the Node ecosystem. - // We also include JSX as a common component filename extension to support - // some tools, although we do not recommend using it, see: - // https://github.com/facebookincubator/create-react-app/issues/290 - extensions: ['.js', '.json', '.jsx', ''], - alias: { - // Support React Native Web - // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/ - 'react-native': 'react-native-web' - } - }, - - module: { - // First, run the linter. - // It's important to do this before Babel processes the JS. - preLoaders: [ - { - test: /\.(js|jsx)$/, - loader: 'eslint', - include: paths.appSrc, - } - ], - loaders: [ - // Process JS with Babel. - { - test: /\.(js|jsx)$/, - include: paths.appSrc, - loader: 'babel', - query: require('./babel.dev') - }, - // "postcss" loader applies autoprefixer to our CSS. - // "css" loader resolves paths in CSS and adds assets as dependencies. - // "style" loader turns CSS into JS modules that inject