mirror of
https://github.com/hodgef/simple-keyboard.git
synced 2025-03-03 16:02:56 +08:00
ES6 initial setup
This commit is contained in:
commit
df42db3b95
22
.gitignore
vendored
Normal file
22
.gitignore
vendored
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# See https://help.github.com/ignore-files/ for more about ignoring files.
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
/node_modules
|
||||||
|
|
||||||
|
# production
|
||||||
|
/build
|
||||||
|
/demo
|
||||||
|
|
||||||
|
# testing
|
||||||
|
/coverage
|
||||||
|
|
||||||
|
# misc
|
||||||
|
.DS_Store
|
||||||
|
.env.local
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
|
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
25
.npmignore
Normal file
25
.npmignore
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# dependencies
|
||||||
|
/node_modules
|
||||||
|
|
||||||
|
# testing
|
||||||
|
/coverage
|
||||||
|
|
||||||
|
# misc
|
||||||
|
.DS_Store
|
||||||
|
.env.local
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
|
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
|
||||||
|
# Development folders and files
|
||||||
|
public
|
||||||
|
src
|
||||||
|
scripts
|
||||||
|
config
|
||||||
|
.travis.yml
|
||||||
|
CHANGELOG.md
|
||||||
|
README.md
|
5
.travis.yml
Normal file
5
.travis.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
language: node_js
|
||||||
|
node_js:
|
||||||
|
- "node"
|
||||||
|
script:
|
||||||
|
- npm run test
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2018 Francisco Hodge
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
175
README.md
Normal file
175
README.md
Normal file
@ -0,0 +1,175 @@
|
|||||||
|
# simple-keyboard
|
||||||
|
|
||||||
|
[](https://www.npmjs.com/package/simple-keyboard)
|
||||||
|
|
||||||
|
<a href="https://franciscohodge.com/projects/simple-keyboard/"><img src="src/demo/images/simple-keyboard.png" align="center"></a>
|
||||||
|
> An easily customisable and responsive on-screen virtual keyboard for Javascript projects.
|
||||||
|
> Want the React.js version? Get [https://www.npmjs.com/package/react-simple-keyboard](react-simple-keyboard) instead!
|
||||||
|
|
||||||
|
<img src="src/demo/images/keyboard.PNG" align="center" width="100%">
|
||||||
|
|
||||||
|
<b>[Live Demo](https://franciscohodge.com/simple-keyboard/demo)</b>
|
||||||
|
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
`npm install simple-keyboard --save`
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
### js
|
||||||
|
|
||||||
|
````js
|
||||||
|
import Keyboard from 'simple-keyboard';
|
||||||
|
import 'simple-keyboard/build/css/index.css';
|
||||||
|
|
||||||
|
var keyboard = new Keyboard({
|
||||||
|
onChange: input => this.onChange(input),
|
||||||
|
onKeyPress: button => this.onKeyPress(button)
|
||||||
|
});
|
||||||
|
````
|
||||||
|
|
||||||
|
### html
|
||||||
|
|
||||||
|
````html
|
||||||
|
<div class="simple-keyboard"></div>
|
||||||
|
````
|
||||||
|
|
||||||
|
> Need a more extensive example? [Click here](https://github.com/hodgef/simple-keyboard/blob/master/src/demo/App.js).
|
||||||
|
|
||||||
|
## Options
|
||||||
|
|
||||||
|
You can customize the Keyboard by passing options to it.
|
||||||
|
Here are the available options (the code examples are the defaults):
|
||||||
|
|
||||||
|
### layout
|
||||||
|
|
||||||
|
> Modify the keyboard layout
|
||||||
|
|
||||||
|
```js
|
||||||
|
layout: {
|
||||||
|
'default': [
|
||||||
|
'` 1 2 3 4 5 6 7 8 9 0 - = {bksp}',
|
||||||
|
'{tab} q w e r t y u i o p [ ] \\',
|
||||||
|
'{lock} a s d f g h j k l ; \' {enter}',
|
||||||
|
'{shift} z x c v b n m , . / {shift}',
|
||||||
|
'.com @ {space}'
|
||||||
|
],
|
||||||
|
'shift': [
|
||||||
|
'~ ! @ # $ % ^ & * ( ) _ + {bksp}',
|
||||||
|
'{tab} Q W E R T Y U I O P { } |',
|
||||||
|
'{lock} A S D F G H J K L : " {enter}',
|
||||||
|
'{shift} Z X C V B N M < > ? {shift}',
|
||||||
|
'.com @ {space}'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### layoutName
|
||||||
|
|
||||||
|
> Specifies which layout should be used.
|
||||||
|
|
||||||
|
```js
|
||||||
|
layoutName: "default"
|
||||||
|
```
|
||||||
|
|
||||||
|
### display
|
||||||
|
|
||||||
|
> Replaces variable buttons (such as `{bksp}`) with a human-friendly name (e.g.: "delete").
|
||||||
|
|
||||||
|
```js
|
||||||
|
display: {
|
||||||
|
'{bksp}': 'delete',
|
||||||
|
'{enter}': '< enter',
|
||||||
|
'{shift}': 'shift',
|
||||||
|
'{s}': 'shift',
|
||||||
|
'{tab}': 'tab',
|
||||||
|
'{lock}': 'caps',
|
||||||
|
'{accept}': 'Submit',
|
||||||
|
'{space}': ' ',
|
||||||
|
'{//}': ' '
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### theme
|
||||||
|
|
||||||
|
> A prop to add your own css classes. You can add multiple classes separated by a space.
|
||||||
|
|
||||||
|
```js
|
||||||
|
theme: "hg-theme-default"
|
||||||
|
```
|
||||||
|
|
||||||
|
### debug
|
||||||
|
|
||||||
|
> Runs a console.log every time a key is pressed. Displays the buttons pressed and the current input.
|
||||||
|
|
||||||
|
```js
|
||||||
|
debug: false
|
||||||
|
```
|
||||||
|
|
||||||
|
### newLineOnEnter
|
||||||
|
|
||||||
|
> Specifies whether clicking the "ENTER" button will input a newline (`\n`) or not.
|
||||||
|
|
||||||
|
```js
|
||||||
|
newLineOnEnter: false
|
||||||
|
```
|
||||||
|
|
||||||
|
## Methods
|
||||||
|
|
||||||
|
simple-keybord has a few methods you can use to further control it's behavior.
|
||||||
|
To access these functions, you need the instance the simple-keyboard component, like so:
|
||||||
|
|
||||||
|
```js
|
||||||
|
var keyboard = new Keyboard({
|
||||||
|
...
|
||||||
|
});
|
||||||
|
/>
|
||||||
|
|
||||||
|
// Then, use as follows...
|
||||||
|
keyboard.methodName(params);
|
||||||
|
```
|
||||||
|
|
||||||
|
### clearInput
|
||||||
|
|
||||||
|
> Clear the keyboard's input.
|
||||||
|
|
||||||
|
```js
|
||||||
|
keyboard.clearInput();
|
||||||
|
```
|
||||||
|
|
||||||
|
### getInput
|
||||||
|
|
||||||
|
> Get the keyboard's input (You can also get it from the _onChange_ prop).
|
||||||
|
|
||||||
|
```js
|
||||||
|
let input = keyboard.getInput();
|
||||||
|
```
|
||||||
|
|
||||||
|
### setInput
|
||||||
|
|
||||||
|
> Set the keyboard's input. Useful if you want the keybord to initialize with a default value, for example.
|
||||||
|
|
||||||
|
```js
|
||||||
|
keyboard.setInput("Hello World!");
|
||||||
|
```
|
||||||
|
|
||||||
|
## Demo
|
||||||
|
|
||||||
|
<img src="src/demo/images/demo.gif" align="center" width="600">
|
||||||
|
|
||||||
|
### Live demo
|
||||||
|
|
||||||
|
[https://franciscohodge.com/simple-keyboard/demo](https://franciscohodge.com/simple-keyboard/demo)
|
||||||
|
|
||||||
|
### To run demo on your own computer
|
||||||
|
|
||||||
|
* Clone this repository
|
||||||
|
* `npm install`
|
||||||
|
* `npm start`
|
||||||
|
* Visit [http://localhost:3000/](http://localhost:3000/)
|
||||||
|
|
||||||
|
## Note
|
||||||
|
|
||||||
|
This is a work in progress. Feel free to submit any issues you have at:
|
||||||
|
[https://github.com/hodgef/simple-keyboard/issues](https://github.com/hodgef/simple-keyboard/issues)
|
90
config/env.js
Normal file
90
config/env.js
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const paths = require('./paths');
|
||||||
|
|
||||||
|
// Make sure that including paths.js after env.js will read .env variables.
|
||||||
|
delete require.cache[require.resolve('./paths')];
|
||||||
|
|
||||||
|
const NODE_ENV = process.env.NODE_ENV;
|
||||||
|
if (!NODE_ENV) {
|
||||||
|
throw new Error(
|
||||||
|
'The NODE_ENV environment variable is required but was not specified.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
|
||||||
|
var dotenvFiles = [
|
||||||
|
`${paths.dotenv}.${NODE_ENV}.local`,
|
||||||
|
`${paths.dotenv}.${NODE_ENV}`,
|
||||||
|
// Don't include `.env.local` for `test` environment
|
||||||
|
// since normally you expect tests to produce the same
|
||||||
|
// results for everyone
|
||||||
|
NODE_ENV !== 'test' && `${paths.dotenv}.local`,
|
||||||
|
paths.dotenv,
|
||||||
|
].filter(Boolean);
|
||||||
|
|
||||||
|
// Load environment variables from .env* files. Suppress warnings using silent
|
||||||
|
// if this file is missing. dotenv will never modify any environment variables
|
||||||
|
// that have already been set.
|
||||||
|
// https://github.com/motdotla/dotenv
|
||||||
|
dotenvFiles.forEach(dotenvFile => {
|
||||||
|
if (fs.existsSync(dotenvFile)) {
|
||||||
|
require('dotenv').config({
|
||||||
|
path: dotenvFile,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored.
|
||||||
|
// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims.
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/1023#issuecomment-265344421
|
||||||
|
// We also resolve them to make sure all tools using them work consistently.
|
||||||
|
const appDirectory = fs.realpathSync(process.cwd());
|
||||||
|
process.env.NODE_PATH = (process.env.NODE_PATH || '')
|
||||||
|
.split(path.delimiter)
|
||||||
|
.filter(folder => folder && !path.isAbsolute(folder))
|
||||||
|
.map(folder => path.resolve(appDirectory, folder))
|
||||||
|
.join(path.delimiter);
|
||||||
|
|
||||||
|
// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
|
||||||
|
// injected into the application via DefinePlugin in Webpack configuration.
|
||||||
|
const REACT_APP = /^REACT_APP_/i;
|
||||||
|
|
||||||
|
function getClientEnvironment(publicUrl) {
|
||||||
|
const raw = Object.keys(process.env)
|
||||||
|
.filter(key => REACT_APP.test(key))
|
||||||
|
.reduce(
|
||||||
|
(env, key) => {
|
||||||
|
env[key] = process.env[key];
|
||||||
|
return env;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// Useful for determining whether we’re running in production mode.
|
||||||
|
// Most importantly, it switches React into the correct mode.
|
||||||
|
NODE_ENV: process.env.NODE_ENV || 'development',
|
||||||
|
// Useful for resolving the correct path to static assets in `public`.
|
||||||
|
// For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
|
||||||
|
// 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.
|
||||||
|
PUBLIC_URL: publicUrl,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
// Stringify all values so we can feed into Webpack DefinePlugin
|
||||||
|
const stringified = {
|
||||||
|
'process.env': Object.keys(raw).reduce((env, key) => {
|
||||||
|
env[key] = JSON.stringify(raw[key]);
|
||||||
|
return env;
|
||||||
|
}, {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
return { raw, stringified };
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = getClientEnvironment;
|
14
config/jest/cssTransform.js
Normal file
14
config/jest/cssTransform.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// This is a custom Jest transformer turning style imports into empty objects.
|
||||||
|
// http://facebook.github.io/jest/docs/tutorial-webpack.html
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
process() {
|
||||||
|
return 'module.exports = {};';
|
||||||
|
},
|
||||||
|
getCacheKey() {
|
||||||
|
// The output is always the same.
|
||||||
|
return 'cssTransform';
|
||||||
|
},
|
||||||
|
};
|
12
config/jest/fileTransform.js
Normal file
12
config/jest/fileTransform.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
// This is a custom Jest transformer turning file imports into filenames.
|
||||||
|
// http://facebook.github.io/jest/docs/tutorial-webpack.html
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
process(src, filename) {
|
||||||
|
return `module.exports = ${JSON.stringify(path.basename(filename))};`;
|
||||||
|
},
|
||||||
|
};
|
64
config/paths.js
Normal file
64
config/paths.js
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const path = require('path');
|
||||||
|
const fs = require('fs');
|
||||||
|
const url = require('url');
|
||||||
|
|
||||||
|
// Make sure any symlinks in the project folder are resolved:
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/637
|
||||||
|
const appDirectory = fs.realpathSync(process.cwd());
|
||||||
|
const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
|
||||||
|
|
||||||
|
const envPublicUrl = process.env.PUBLIC_URL;
|
||||||
|
|
||||||
|
function ensureSlash(path, needsSlash) {
|
||||||
|
const hasSlash = path.endsWith('/');
|
||||||
|
if (hasSlash && !needsSlash) {
|
||||||
|
return path.substr(path, path.length - 1);
|
||||||
|
} else if (!hasSlash && needsSlash) {
|
||||||
|
return `${path}/`;
|
||||||
|
} else {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const getPublicUrl = appPackageJson =>
|
||||||
|
envPublicUrl || require(appPackageJson).homepage;
|
||||||
|
|
||||||
|
// We use `PUBLIC_URL` environment variable or "homepage" field to infer
|
||||||
|
// "public path" at which the app is served.
|
||||||
|
// Webpack needs to know it to put the right <script> hrefs into HTML even in
|
||||||
|
// single-page apps that may serve index.html for nested URLs like /todos/42.
|
||||||
|
// We can't use a relative path in HTML because we don't want to load something
|
||||||
|
// like /todos/42/static/js/bundle.7289d.js. We have to know the root.
|
||||||
|
function getServedPath(appPackageJson) {
|
||||||
|
const publicUrl = getPublicUrl(appPackageJson);
|
||||||
|
const servedUrl =
|
||||||
|
envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/');
|
||||||
|
return ensureSlash(servedUrl, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// config after eject: we're in ./config/
|
||||||
|
module.exports = {
|
||||||
|
dotenv: resolveApp('.env'),
|
||||||
|
appBuild: resolveApp('build'),
|
||||||
|
appDemoBuild: resolveApp('demo'),
|
||||||
|
appPublic: resolveApp('public'),
|
||||||
|
appHtml: resolveApp('public/index.html'),
|
||||||
|
appIndexJs: resolveApp('src/demo/index.js'), // CRL: Updated for demo purposes
|
||||||
|
appPackageJson: resolveApp('package.json'),
|
||||||
|
appSrc: resolveApp('src'),
|
||||||
|
yarnLockFile: resolveApp('yarn.lock'),
|
||||||
|
testsSetup: resolveApp('src/setupTests.js'),
|
||||||
|
appNodeModules: resolveApp('node_modules'),
|
||||||
|
publicUrl: getPublicUrl(resolveApp('package.json')),
|
||||||
|
servedPath: getServedPath(resolveApp('package.json')),
|
||||||
|
|
||||||
|
// CRL: New paths for demo build
|
||||||
|
appDemoIndexJs: resolveApp('src/demo/index.js'),
|
||||||
|
appDemoSrc: resolveApp('src/demo'),
|
||||||
|
|
||||||
|
// CRL: New paths for library
|
||||||
|
appLibIndexJs: resolveApp('src/lib/index.js'),
|
||||||
|
appLibSrc: resolveApp('src/lib'),
|
||||||
|
};
|
22
config/polyfills.js
Normal file
22
config/polyfills.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
if (typeof Promise === 'undefined') {
|
||||||
|
// Rejection tracking prevents a common issue where React gets into an
|
||||||
|
// inconsistent state due to an error, but it gets swallowed by a Promise,
|
||||||
|
// and the user has no idea what causes React's erratic future behavior.
|
||||||
|
require('promise/lib/rejection-tracking').enable();
|
||||||
|
window.Promise = require('promise/lib/es6-extensions.js');
|
||||||
|
}
|
||||||
|
|
||||||
|
// fetch() polyfill for making API calls.
|
||||||
|
require('whatwg-fetch');
|
||||||
|
|
||||||
|
// Object.assign() is commonly used with React.
|
||||||
|
// It will use the native implementation if it's present and isn't buggy.
|
||||||
|
Object.assign = require('object-assign');
|
||||||
|
|
||||||
|
// In tests, polyfill requestAnimationFrame since jsdom doesn't provide it yet.
|
||||||
|
// We don't polyfill it in the browser--this is user's responsibility.
|
||||||
|
if (process.env.NODE_ENV === 'test') {
|
||||||
|
require('raf').polyfill(global);
|
||||||
|
}
|
279
config/webpack.config.demo.js
Normal file
279
config/webpack.config.demo.js
Normal file
@ -0,0 +1,279 @@
|
|||||||
|
|
||||||
|
|
||||||
|
const autoprefixer = require('autoprefixer');
|
||||||
|
const path = require('path');
|
||||||
|
const webpack = require('webpack');
|
||||||
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||||
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
||||||
|
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
|
||||||
|
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
||||||
|
const eslintFormatter = require('react-dev-utils/eslintFormatter');
|
||||||
|
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
|
||||||
|
const paths = require('./paths');
|
||||||
|
const getClientEnvironment = require('./env');
|
||||||
|
|
||||||
|
// Webpack uses `publicPath` to determine where the app is being served from.
|
||||||
|
// It requires a trailing slash, or the file assets will get an incorrect path.
|
||||||
|
const publicPath = paths.servedPath;
|
||||||
|
// Some apps do not use client-side routing with pushState.
|
||||||
|
// For these, "homepage" can be set to "." to enable relative asset paths.
|
||||||
|
const shouldUseRelativeAssetPaths = publicPath === './';
|
||||||
|
// Source maps are resource heavy and can cause out of memory issue for large source files.
|
||||||
|
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
|
||||||
|
// `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 slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
|
||||||
|
const publicUrl = '.';
|
||||||
|
// Get environment variables to inject into our app.
|
||||||
|
const env = getClientEnvironment(publicUrl);
|
||||||
|
|
||||||
|
// Assert this just to be safe.
|
||||||
|
// Development builds of React are slow and not intended for production.
|
||||||
|
if (env.stringified['process.env'].NODE_ENV !== '"production"') {
|
||||||
|
throw new Error('Production builds must have NODE_ENV=production.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note: defined here because it will be used more than once.
|
||||||
|
const cssFilename = 'css/index.css';
|
||||||
|
|
||||||
|
// ExtractTextPlugin expects the build output to be flat.
|
||||||
|
// (See https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/27)
|
||||||
|
// However, our output is structured with css, js and media folders.
|
||||||
|
// To have this structure working with relative paths, we have to use custom options.
|
||||||
|
const extractTextPluginOptions = shouldUseRelativeAssetPaths
|
||||||
|
? // Making sure that the publicPath goes back to to build folder.
|
||||||
|
{ publicPath: Array(cssFilename.split('/').length).join('../') }
|
||||||
|
: {};
|
||||||
|
|
||||||
|
// This is the production configuration.
|
||||||
|
// It compiles slowly and is focused on producing a fast and minimal bundle.
|
||||||
|
// The development configuration is different and lives in a separate file.
|
||||||
|
module.exports = {
|
||||||
|
// Don't attempt to continue if there are any errors.
|
||||||
|
bail: true,
|
||||||
|
// We generate sourcemaps in production. This is slow but gives good results.
|
||||||
|
// You can exclude the *.map files from the build during deployment.
|
||||||
|
devtool: shouldUseSourceMap ? 'source-map' : false,
|
||||||
|
// In production, we only want to load the app code.
|
||||||
|
entry: [paths.appDemoIndexJs], // CRL: library index file instead of app index
|
||||||
|
output: {
|
||||||
|
// CRL: Updated whole block with library specific info
|
||||||
|
path: paths.appDemoBuild,
|
||||||
|
filename: 'index.js',
|
||||||
|
libraryTarget: 'umd'
|
||||||
|
},
|
||||||
|
resolve: {
|
||||||
|
// This allows you to set a fallback for where Webpack should look for modules.
|
||||||
|
// We placed these paths second because we want `node_modules` to "win"
|
||||||
|
// if there are any conflicts. This matches Node resolution mechanism.
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/253
|
||||||
|
modules: ['node_modules', paths.appNodeModules].concat(
|
||||||
|
// It is guaranteed to exist because we tweak it in `env.js`
|
||||||
|
process.env.NODE_PATH.split(path.delimiter).filter(Boolean)
|
||||||
|
),
|
||||||
|
// 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
|
||||||
|
// `web` extension prefixes have been added for better support
|
||||||
|
// for React Native Web.
|
||||||
|
extensions: ['.web.js', '.mjs', '.js', '.json', '.web.jsx', '.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'
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
// Prevents users from importing files from outside of src/ (or node_modules/).
|
||||||
|
// This often causes confusion because we only process files within src/ with babel.
|
||||||
|
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
|
||||||
|
// please link the files into your node_modules/ and let module-resolution kick in.
|
||||||
|
// Make sure your source files are compiled, as they will not be processed in any way.
|
||||||
|
new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson])
|
||||||
|
]
|
||||||
|
},
|
||||||
|
module: {
|
||||||
|
strictExportPresence: true,
|
||||||
|
rules: [
|
||||||
|
// TODO: Disable require.ensure as it's not a standard language feature.
|
||||||
|
// We are waiting for https://github.com/facebookincubator/create-react-app/issues/2176.
|
||||||
|
// { parser: { requireEnsure: false } },
|
||||||
|
|
||||||
|
// First, run the linter.
|
||||||
|
// It's important to do this before Babel processes the JS.
|
||||||
|
{
|
||||||
|
test: /\.(js|jsx|mjs)$/,
|
||||||
|
enforce: 'pre',
|
||||||
|
use: [
|
||||||
|
{
|
||||||
|
options: {
|
||||||
|
formatter: eslintFormatter,
|
||||||
|
eslintPath: require.resolve('eslint')
|
||||||
|
},
|
||||||
|
loader: require.resolve('eslint-loader')
|
||||||
|
}
|
||||||
|
],
|
||||||
|
include: paths.appDemoSrc // CRL: updated with library src folder
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// "oneOf" will traverse all following loaders until one will
|
||||||
|
// match the requirements. When no loader matches it will fall
|
||||||
|
// back to the "file" loader at the end of the loader list.
|
||||||
|
oneOf: [
|
||||||
|
// "url" loader works just like "file" loader but it also embeds
|
||||||
|
// assets smaller than specified size as data URLs to avoid requests.
|
||||||
|
{
|
||||||
|
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
|
||||||
|
loader: require.resolve('url-loader'),
|
||||||
|
options: {
|
||||||
|
limit: 10000,
|
||||||
|
name: 'media/[name].[ext]'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// Process JS with Babel.
|
||||||
|
{
|
||||||
|
test: /\.(js|jsx|mjs)$/,
|
||||||
|
include: [paths.appLibSrc, paths.appDemoSrc], // CRL: updated with library src folder
|
||||||
|
loader: require.resolve('babel-loader'),
|
||||||
|
options: {
|
||||||
|
compact: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// The notation here is somewhat confusing.
|
||||||
|
// "postcss" loader applies autoprefixer to our CSS.
|
||||||
|
// "css" loader resolves paths in CSS and adds assets as dependencies.
|
||||||
|
// "style" loader normally turns CSS into JS modules injecting <style>,
|
||||||
|
// but unlike in development configuration, we do something different.
|
||||||
|
// `ExtractTextPlugin` first applies the "postcss" and "css" loaders
|
||||||
|
// (second argument), then grabs the result CSS and puts it into a
|
||||||
|
// separate file in our build process. This way we actually ship
|
||||||
|
// a single CSS file in production instead of JS code injecting <style>
|
||||||
|
// tags. If you use code splitting, however, any async bundles will still
|
||||||
|
// use the "style" loader inside the async code so CSS from them won't be
|
||||||
|
// in the main CSS file.
|
||||||
|
{
|
||||||
|
test: /\.css$/,
|
||||||
|
loader: ExtractTextPlugin.extract(
|
||||||
|
Object.assign(
|
||||||
|
{
|
||||||
|
fallback: {
|
||||||
|
loader: require.resolve('style-loader'),
|
||||||
|
options: {
|
||||||
|
hmr: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
use: [
|
||||||
|
{
|
||||||
|
loader: require.resolve('css-loader'),
|
||||||
|
options: {
|
||||||
|
importLoaders: 1,
|
||||||
|
minimize: true,
|
||||||
|
sourceMap: shouldUseSourceMap
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
loader: require.resolve('postcss-loader'),
|
||||||
|
options: {
|
||||||
|
// Necessary for external CSS imports to work
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/2677
|
||||||
|
ident: 'postcss',
|
||||||
|
plugins: () => [
|
||||||
|
require('postcss-flexbugs-fixes'),
|
||||||
|
autoprefixer({
|
||||||
|
browsers: [
|
||||||
|
'>1%',
|
||||||
|
'last 4 versions',
|
||||||
|
'Firefox ESR',
|
||||||
|
'not ie < 9' // React doesn't support IE8 anyway
|
||||||
|
],
|
||||||
|
flexbox: 'no-2009'
|
||||||
|
})
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
extractTextPluginOptions
|
||||||
|
)
|
||||||
|
)
|
||||||
|
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
|
||||||
|
},
|
||||||
|
// "file" loader makes sure assets end up in the `build` folder.
|
||||||
|
// When you `import` an asset, you get its filename.
|
||||||
|
// This loader doesn't use a "test" so it will catch all modules
|
||||||
|
// that fall through the other loaders.
|
||||||
|
{
|
||||||
|
loader: require.resolve('file-loader'),
|
||||||
|
// Exclude `js` files to keep "css" loader working as it injects
|
||||||
|
// it's runtime that would otherwise processed through "file" loader.
|
||||||
|
// Also exclude `html` and `json` extensions so they get processed
|
||||||
|
// by webpacks internal loaders.
|
||||||
|
exclude: [/\.js$/, /\.html$/, /\.json$/],
|
||||||
|
options: {
|
||||||
|
name: 'media/[name].[ext]'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ** STOP ** Are you adding a new loader?
|
||||||
|
// Make sure to add the new loader(s) before the "file" loader.
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
// Makes some environment variables available to the JS code, for example:
|
||||||
|
// if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`.
|
||||||
|
// It is absolutely essential that NODE_ENV was set to production here.
|
||||||
|
// Otherwise React will be compiled in the very slow development mode.
|
||||||
|
new InterpolateHtmlPlugin(env.raw),
|
||||||
|
// Generates an `index.html` file with the <script> injected.
|
||||||
|
new HtmlWebpackPlugin({
|
||||||
|
inject: true,
|
||||||
|
template: paths.appHtml
|
||||||
|
}),
|
||||||
|
// Add module names to factory functions so they appear in browser profiler.
|
||||||
|
new webpack.NamedModulesPlugin(),
|
||||||
|
new webpack.DefinePlugin(env.stringified),
|
||||||
|
// Minify the code.
|
||||||
|
new webpack.optimize.UglifyJsPlugin({
|
||||||
|
compress: false,
|
||||||
|
mangle: {
|
||||||
|
safari10: true
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
comments: false,
|
||||||
|
// Turned on because emoji and regex is not minified properly using default
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/2488
|
||||||
|
ascii_only: true
|
||||||
|
},
|
||||||
|
sourceMap: shouldUseSourceMap
|
||||||
|
}),
|
||||||
|
// Note: this won't work without ExtractTextPlugin.extract(..) in `loaders`.
|
||||||
|
new ExtractTextPlugin({
|
||||||
|
filename: cssFilename
|
||||||
|
}),
|
||||||
|
// Moment.js is an extremely popular library that bundles large locale files
|
||||||
|
// by default due to how Webpack interprets its code. This is a practical
|
||||||
|
// solution that requires the user to opt into importing specific locales.
|
||||||
|
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
|
||||||
|
// You can remove this if you don't use Moment.js:
|
||||||
|
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
|
||||||
|
new CopyWebpackPlugin([
|
||||||
|
{ from: `${paths.appPublic}/favicon.ico`, to: paths.appDemoBuild },
|
||||||
|
{ from: `${paths.appPublic}/manifest.json`, to: paths.appDemoBuild }
|
||||||
|
])
|
||||||
|
],
|
||||||
|
// CRL: added externals block for library
|
||||||
|
// externals: {
|
||||||
|
// 'react': 'react',
|
||||||
|
// 'react-dom': 'react-dom'
|
||||||
|
// },
|
||||||
|
// Some libraries import Node modules but don't use them in the browser.
|
||||||
|
// Tell Webpack to provide empty mocks for them so importing them works.
|
||||||
|
node: {
|
||||||
|
dgram: 'empty',
|
||||||
|
fs: 'empty',
|
||||||
|
net: 'empty',
|
||||||
|
tls: 'empty',
|
||||||
|
child_process: 'empty'
|
||||||
|
}
|
||||||
|
};
|
259
config/webpack.config.dev.js
Normal file
259
config/webpack.config.dev.js
Normal file
@ -0,0 +1,259 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const autoprefixer = require('autoprefixer');
|
||||||
|
const path = require('path');
|
||||||
|
const webpack = require('webpack');
|
||||||
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||||
|
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
|
||||||
|
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
|
||||||
|
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
|
||||||
|
const eslintFormatter = require('react-dev-utils/eslintFormatter');
|
||||||
|
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
|
||||||
|
const getClientEnvironment = require('./env');
|
||||||
|
const 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.
|
||||||
|
const 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 slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
|
||||||
|
const publicUrl = '';
|
||||||
|
// Get environment variables to inject into our app.
|
||||||
|
const 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 = {
|
||||||
|
// You may want 'eval' instead if you prefer to see the compiled output in DevTools.
|
||||||
|
// See the discussion in https://github.com/facebookincubator/create-react-app/issues/343.
|
||||||
|
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'),
|
||||||
|
// 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: {
|
||||||
|
// 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: 'static/js/bundle.js',
|
||||||
|
// There are also additional JS chunk files if you use code splitting.
|
||||||
|
chunkFilename: 'static/js/[name].chunk.js',
|
||||||
|
// This is the URL that app is served from. We use "/" in development.
|
||||||
|
publicPath: publicPath,
|
||||||
|
// Point sourcemap entries to original disk location (format as URL on Windows)
|
||||||
|
devtoolModuleFilenameTemplate: info =>
|
||||||
|
path.resolve(info.absoluteResourcePath).replace(/\\/g, '/'),
|
||||||
|
},
|
||||||
|
resolve: {
|
||||||
|
// This allows you to set a fallback for where Webpack should look for modules.
|
||||||
|
// We placed these paths second because we want `node_modules` to "win"
|
||||||
|
// if there are any conflicts. This matches Node resolution mechanism.
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/253
|
||||||
|
modules: ['node_modules', paths.appNodeModules].concat(
|
||||||
|
// It is guaranteed to exist because we tweak it in `env.js`
|
||||||
|
process.env.NODE_PATH.split(path.delimiter).filter(Boolean)
|
||||||
|
),
|
||||||
|
// 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
|
||||||
|
// `web` extension prefixes have been added for better support
|
||||||
|
// for React Native Web.
|
||||||
|
extensions: ['.web.js', '.mjs', '.js', '.json', '.web.jsx', '.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',
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
// Prevents users from importing files from outside of src/ (or node_modules/).
|
||||||
|
// This often causes confusion because we only process files within src/ with babel.
|
||||||
|
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
|
||||||
|
// please link the files into your node_modules/ and let module-resolution kick in.
|
||||||
|
// Make sure your source files are compiled, as they will not be processed in any way.
|
||||||
|
new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
module: {
|
||||||
|
strictExportPresence: true,
|
||||||
|
rules: [
|
||||||
|
// TODO: Disable require.ensure as it's not a standard language feature.
|
||||||
|
// We are waiting for https://github.com/facebookincubator/create-react-app/issues/2176.
|
||||||
|
// { parser: { requireEnsure: false } },
|
||||||
|
|
||||||
|
// First, run the linter.
|
||||||
|
// It's important to do this before Babel processes the JS.
|
||||||
|
{
|
||||||
|
test: /\.(js|jsx|mjs)$/,
|
||||||
|
enforce: 'pre',
|
||||||
|
use: [
|
||||||
|
{
|
||||||
|
options: {
|
||||||
|
formatter: eslintFormatter,
|
||||||
|
eslintPath: require.resolve('eslint'),
|
||||||
|
|
||||||
|
},
|
||||||
|
loader: require.resolve('eslint-loader'),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
include: paths.appSrc,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// "oneOf" will traverse all following loaders until one will
|
||||||
|
// match the requirements. When no loader matches it will fall
|
||||||
|
// back to the "file" loader at the end of the loader list.
|
||||||
|
oneOf: [
|
||||||
|
// "url" loader works like "file" loader except that it embeds assets
|
||||||
|
// smaller than specified limit in bytes as data URLs to avoid requests.
|
||||||
|
// A missing `test` is equivalent to a match.
|
||||||
|
{
|
||||||
|
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
|
||||||
|
loader: require.resolve('url-loader'),
|
||||||
|
options: {
|
||||||
|
limit: 10000,
|
||||||
|
name: 'static/media/[name].[hash:8].[ext]',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// Process JS with Babel.
|
||||||
|
{
|
||||||
|
test: /\.(js|jsx|mjs)$/,
|
||||||
|
include: paths.appSrc,
|
||||||
|
loader: require.resolve('babel-loader'),
|
||||||
|
options: {
|
||||||
|
// This is a feature of `babel-loader` for webpack (not Babel itself).
|
||||||
|
// It enables caching results in ./node_modules/.cache/babel-loader/
|
||||||
|
// directory for faster rebuilds.
|
||||||
|
cacheDirectory: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// "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 <style> tags.
|
||||||
|
// In production, we use a plugin to extract that CSS to a file, but
|
||||||
|
// in development "style" loader enables hot editing of CSS.
|
||||||
|
{
|
||||||
|
test: /\.css$/,
|
||||||
|
use: [
|
||||||
|
require.resolve('style-loader'),
|
||||||
|
{
|
||||||
|
loader: require.resolve('css-loader'),
|
||||||
|
options: {
|
||||||
|
importLoaders: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
loader: require.resolve('postcss-loader'),
|
||||||
|
options: {
|
||||||
|
// Necessary for external CSS imports to work
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/2677
|
||||||
|
ident: 'postcss',
|
||||||
|
plugins: () => [
|
||||||
|
require('postcss-flexbugs-fixes'),
|
||||||
|
autoprefixer({
|
||||||
|
browsers: [
|
||||||
|
'>1%',
|
||||||
|
'last 4 versions',
|
||||||
|
'Firefox ESR',
|
||||||
|
'not ie < 9', // React doesn't support IE8 anyway
|
||||||
|
],
|
||||||
|
flexbox: 'no-2009',
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
// "file" loader makes sure those assets get served by WebpackDevServer.
|
||||||
|
// When you `import` an asset, you get its (virtual) filename.
|
||||||
|
// In production, they would get copied to the `build` folder.
|
||||||
|
// This loader doesn't use a "test" so it will catch all modules
|
||||||
|
// that fall through the other loaders.
|
||||||
|
{
|
||||||
|
// Exclude `js` files to keep "css" loader working as it injects
|
||||||
|
// it's runtime that would otherwise processed through "file" loader.
|
||||||
|
// Also exclude `html` and `json` extensions so they get processed
|
||||||
|
// by webpacks internal loaders.
|
||||||
|
exclude: [/\.js$/, /\.html$/, /\.json$/],
|
||||||
|
loader: require.resolve('file-loader'),
|
||||||
|
options: {
|
||||||
|
name: 'static/media/[name].[hash:8].[ext]',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
// ** STOP ** Are you adding a new loader?
|
||||||
|
// Make sure to add the new loader(s) before the "file" loader.
|
||||||
|
],
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
// Makes some environment variables available in index.html.
|
||||||
|
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
|
||||||
|
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
||||||
|
// In development, this will be an empty string.
|
||||||
|
new InterpolateHtmlPlugin(env.raw),
|
||||||
|
// Generates an `index.html` file with the <script> injected.
|
||||||
|
new HtmlWebpackPlugin({
|
||||||
|
inject: true,
|
||||||
|
template: paths.appHtml,
|
||||||
|
}),
|
||||||
|
// Add module names to factory functions so they appear in browser profiler.
|
||||||
|
new webpack.NamedModulesPlugin(),
|
||||||
|
// Makes some environment variables available to the JS code, for example:
|
||||||
|
// if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
|
||||||
|
new webpack.DefinePlugin(env.stringified),
|
||||||
|
// This is necessary to emit hot updates (currently CSS only):
|
||||||
|
new webpack.HotModuleReplacementPlugin(),
|
||||||
|
// Watcher doesn't work well if you mistype casing in a path so we use
|
||||||
|
// a plugin that prints an error when you attempt to do this.
|
||||||
|
// See https://github.com/facebookincubator/create-react-app/issues/240
|
||||||
|
new CaseSensitivePathsPlugin(),
|
||||||
|
// If you require a missing module and then `npm install` it, you still have
|
||||||
|
// to restart the development server for Webpack to discover it. This plugin
|
||||||
|
// makes the discovery automatic so you don't have to restart.
|
||||||
|
// See https://github.com/facebookincubator/create-react-app/issues/186
|
||||||
|
new WatchMissingNodeModulesPlugin(paths.appNodeModules),
|
||||||
|
// Moment.js is an extremely popular library that bundles large locale files
|
||||||
|
// by default due to how Webpack interprets its code. This is a practical
|
||||||
|
// solution that requires the user to opt into importing specific locales.
|
||||||
|
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
|
||||||
|
// You can remove this if you don't use Moment.js:
|
||||||
|
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
|
||||||
|
],
|
||||||
|
// Some libraries import Node modules but don't use them in the browser.
|
||||||
|
// Tell Webpack to provide empty mocks for them so importing them works.
|
||||||
|
node: {
|
||||||
|
dgram: 'empty',
|
||||||
|
fs: 'empty',
|
||||||
|
net: 'empty',
|
||||||
|
tls: 'empty',
|
||||||
|
child_process: 'empty',
|
||||||
|
},
|
||||||
|
// Turn off performance hints during development because we don't do any
|
||||||
|
// splitting or minification in interest of speed. These warnings become
|
||||||
|
// cumbersome.
|
||||||
|
performance: {
|
||||||
|
hints: false,
|
||||||
|
},
|
||||||
|
};
|
274
config/webpack.config.prod.js
Normal file
274
config/webpack.config.prod.js
Normal file
@ -0,0 +1,274 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const autoprefixer = require('autoprefixer');
|
||||||
|
const path = require('path');
|
||||||
|
const webpack = require('webpack');
|
||||||
|
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
||||||
|
const eslintFormatter = require('react-dev-utils/eslintFormatter');
|
||||||
|
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
|
||||||
|
const paths = require('./paths');
|
||||||
|
const getClientEnvironment = require('./env');
|
||||||
|
|
||||||
|
// Webpack uses `publicPath` to determine where the app is being served from.
|
||||||
|
// It requires a trailing slash, or the file assets will get an incorrect path.
|
||||||
|
const publicPath = paths.servedPath;
|
||||||
|
// Some apps do not use client-side routing with pushState.
|
||||||
|
// For these, "homepage" can be set to "." to enable relative asset paths.
|
||||||
|
const shouldUseRelativeAssetPaths = publicPath === './';
|
||||||
|
// Source maps are resource heavy and can cause out of memory issue for large source files.
|
||||||
|
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
|
||||||
|
// `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 slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
|
||||||
|
const publicUrl = publicPath.slice(0, -1);
|
||||||
|
// Get environment variables to inject into our app.
|
||||||
|
const env = getClientEnvironment(publicUrl);
|
||||||
|
|
||||||
|
// Assert this just to be safe.
|
||||||
|
// Development builds of React are slow and not intended for production.
|
||||||
|
if (env.stringified['process.env'].NODE_ENV !== '"production"') {
|
||||||
|
throw new Error('Production builds must have NODE_ENV=production.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note: defined here because it will be used more than once.
|
||||||
|
const cssFilename = 'css/index.css';
|
||||||
|
|
||||||
|
// ExtractTextPlugin expects the build output to be flat.
|
||||||
|
// (See https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/27)
|
||||||
|
// However, our output is structured with css, js and media folders.
|
||||||
|
// To have this structure working with relative paths, we have to use custom options.
|
||||||
|
const extractTextPluginOptions = shouldUseRelativeAssetPaths
|
||||||
|
? // Making sure that the publicPath goes back to to build folder.
|
||||||
|
{ publicPath: Array(cssFilename.split('/').length).join('../') }
|
||||||
|
: {};
|
||||||
|
|
||||||
|
// This is the production configuration.
|
||||||
|
// It compiles slowly and is focused on producing a fast and minimal bundle.
|
||||||
|
// The development configuration is different and lives in a separate file.
|
||||||
|
module.exports = {
|
||||||
|
// Don't attempt to continue if there are any errors.
|
||||||
|
bail: true,
|
||||||
|
// We generate sourcemaps in production. This is slow but gives good results.
|
||||||
|
// You can exclude the *.map files from the build during deployment.
|
||||||
|
devtool: shouldUseSourceMap ? 'source-map' : false,
|
||||||
|
// In production, we only want to load the app code.
|
||||||
|
entry: [paths.appLibIndexJs], // CRL: library index file instead of app index
|
||||||
|
output: {
|
||||||
|
// CRL: Updated whole block with library specific info
|
||||||
|
path: paths.appBuild,
|
||||||
|
filename: 'index.js',
|
||||||
|
libraryTarget: 'umd'
|
||||||
|
},
|
||||||
|
resolve: {
|
||||||
|
// This allows you to set a fallback for where Webpack should look for modules.
|
||||||
|
// We placed these paths second because we want `node_modules` to "win"
|
||||||
|
// if there are any conflicts. This matches Node resolution mechanism.
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/253
|
||||||
|
modules: ['node_modules', paths.appNodeModules].concat(
|
||||||
|
// It is guaranteed to exist because we tweak it in `env.js`
|
||||||
|
process.env.NODE_PATH.split(path.delimiter).filter(Boolean)
|
||||||
|
),
|
||||||
|
// 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
|
||||||
|
// `web` extension prefixes have been added for better support
|
||||||
|
// for React Native Web.
|
||||||
|
extensions: ['.web.js', '.mjs', '.js', '.json', '.web.jsx', '.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',
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
// Prevents users from importing files from outside of src/ (or node_modules/).
|
||||||
|
// This often causes confusion because we only process files within src/ with babel.
|
||||||
|
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
|
||||||
|
// please link the files into your node_modules/ and let module-resolution kick in.
|
||||||
|
// Make sure your source files are compiled, as they will not be processed in any way.
|
||||||
|
new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
module: {
|
||||||
|
strictExportPresence: true,
|
||||||
|
rules: [
|
||||||
|
// TODO: Disable require.ensure as it's not a standard language feature.
|
||||||
|
// We are waiting for https://github.com/facebookincubator/create-react-app/issues/2176.
|
||||||
|
// { parser: { requireEnsure: false } },
|
||||||
|
|
||||||
|
// First, run the linter.
|
||||||
|
// It's important to do this before Babel processes the JS.
|
||||||
|
{
|
||||||
|
test: /\.(js|jsx|mjs)$/,
|
||||||
|
enforce: 'pre',
|
||||||
|
use: [
|
||||||
|
{
|
||||||
|
options: {
|
||||||
|
formatter: eslintFormatter,
|
||||||
|
eslintPath: require.resolve('eslint'),
|
||||||
|
|
||||||
|
},
|
||||||
|
loader: require.resolve('eslint-loader'),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
include: paths.appLibSrc, // CRL: updated with library src folder
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// "oneOf" will traverse all following loaders until one will
|
||||||
|
// match the requirements. When no loader matches it will fall
|
||||||
|
// back to the "file" loader at the end of the loader list.
|
||||||
|
oneOf: [
|
||||||
|
// "url" loader works just like "file" loader but it also embeds
|
||||||
|
// assets smaller than specified size as data URLs to avoid requests.
|
||||||
|
{
|
||||||
|
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
|
||||||
|
loader: require.resolve('url-loader'),
|
||||||
|
options: {
|
||||||
|
limit: 10000,
|
||||||
|
name: 'media/[name].[ext]',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// Process JS with Babel.
|
||||||
|
{
|
||||||
|
test: /\.(js|jsx|mjs)$/,
|
||||||
|
include: paths.appLibSrc, // CRL: updated with library src folder
|
||||||
|
loader: require.resolve('babel-loader'),
|
||||||
|
options: {
|
||||||
|
|
||||||
|
compact: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// The notation here is somewhat confusing.
|
||||||
|
// "postcss" loader applies autoprefixer to our CSS.
|
||||||
|
// "css" loader resolves paths in CSS and adds assets as dependencies.
|
||||||
|
// "style" loader normally turns CSS into JS modules injecting <style>,
|
||||||
|
// but unlike in development configuration, we do something different.
|
||||||
|
// `ExtractTextPlugin` first applies the "postcss" and "css" loaders
|
||||||
|
// (second argument), then grabs the result CSS and puts it into a
|
||||||
|
// separate file in our build process. This way we actually ship
|
||||||
|
// a single CSS file in production instead of JS code injecting <style>
|
||||||
|
// tags. If you use code splitting, however, any async bundles will still
|
||||||
|
// use the "style" loader inside the async code so CSS from them won't be
|
||||||
|
// in the main CSS file.
|
||||||
|
{
|
||||||
|
test: /\.css$/,
|
||||||
|
loader: ExtractTextPlugin.extract(
|
||||||
|
Object.assign(
|
||||||
|
{
|
||||||
|
fallback: {
|
||||||
|
loader: require.resolve('style-loader'),
|
||||||
|
options: {
|
||||||
|
hmr: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
use: [
|
||||||
|
{
|
||||||
|
loader: require.resolve('css-loader'),
|
||||||
|
options: {
|
||||||
|
importLoaders: 1,
|
||||||
|
minimize: true,
|
||||||
|
sourceMap: shouldUseSourceMap,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
loader: require.resolve('postcss-loader'),
|
||||||
|
options: {
|
||||||
|
// Necessary for external CSS imports to work
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/2677
|
||||||
|
ident: 'postcss',
|
||||||
|
plugins: () => [
|
||||||
|
require('postcss-flexbugs-fixes'),
|
||||||
|
autoprefixer({
|
||||||
|
browsers: [
|
||||||
|
'>1%',
|
||||||
|
'last 4 versions',
|
||||||
|
'Firefox ESR',
|
||||||
|
'not ie < 9', // React doesn't support IE8 anyway
|
||||||
|
],
|
||||||
|
flexbox: 'no-2009',
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
extractTextPluginOptions
|
||||||
|
)
|
||||||
|
),
|
||||||
|
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
|
||||||
|
},
|
||||||
|
// "file" loader makes sure assets end up in the `build` folder.
|
||||||
|
// When you `import` an asset, you get its filename.
|
||||||
|
// This loader doesn't use a "test" so it will catch all modules
|
||||||
|
// that fall through the other loaders.
|
||||||
|
{
|
||||||
|
loader: require.resolve('file-loader'),
|
||||||
|
// Exclude `js` files to keep "css" loader working as it injects
|
||||||
|
// it's runtime that would otherwise processed through "file" loader.
|
||||||
|
// Also exclude `html` and `json` extensions so they get processed
|
||||||
|
// by webpacks internal loaders.
|
||||||
|
exclude: [/\.js$/, /\.html$/, /\.json$/],
|
||||||
|
options: {
|
||||||
|
name: 'media/[name].[ext]',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// ** STOP ** Are you adding a new loader?
|
||||||
|
// Make sure to add the new loader(s) before the "file" loader.
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
// Makes some environment variables available to the JS code, for example:
|
||||||
|
// if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`.
|
||||||
|
// It is absolutely essential that NODE_ENV was set to production here.
|
||||||
|
// Otherwise React will be compiled in the very slow development mode.
|
||||||
|
new webpack.DefinePlugin(env.stringified),
|
||||||
|
// Minify the code.
|
||||||
|
new webpack.optimize.UglifyJsPlugin({
|
||||||
|
compress: {
|
||||||
|
warnings: false,
|
||||||
|
// Disabled because of an issue with Uglify breaking seemingly valid code:
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/2376
|
||||||
|
// Pending further investigation:
|
||||||
|
// https://github.com/mishoo/UglifyJS2/issues/2011
|
||||||
|
comparisons: false,
|
||||||
|
},
|
||||||
|
mangle: {
|
||||||
|
safari10: true,
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
comments: false,
|
||||||
|
// Turned on because emoji and regex is not minified properly using default
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/2488
|
||||||
|
ascii_only: true,
|
||||||
|
},
|
||||||
|
sourceMap: shouldUseSourceMap,
|
||||||
|
}),
|
||||||
|
// Note: this won't work without ExtractTextPlugin.extract(..) in `loaders`.
|
||||||
|
new ExtractTextPlugin({
|
||||||
|
filename: cssFilename,
|
||||||
|
}),
|
||||||
|
// Moment.js is an extremely popular library that bundles large locale files
|
||||||
|
// by default due to how Webpack interprets its code. This is a practical
|
||||||
|
// solution that requires the user to opt into importing specific locales.
|
||||||
|
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
|
||||||
|
// You can remove this if you don't use Moment.js:
|
||||||
|
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
|
||||||
|
],
|
||||||
|
// CRL: added externals block for library
|
||||||
|
externals: {
|
||||||
|
'react': 'react',
|
||||||
|
'react-dom': 'react-dom'
|
||||||
|
},
|
||||||
|
// Some libraries import Node modules but don't use them in the browser.
|
||||||
|
// Tell Webpack to provide empty mocks for them so importing them works.
|
||||||
|
node: {
|
||||||
|
dgram: 'empty',
|
||||||
|
fs: 'empty',
|
||||||
|
net: 'empty',
|
||||||
|
tls: 'empty',
|
||||||
|
child_process: 'empty',
|
||||||
|
},
|
||||||
|
};
|
100
config/webpackDevServer.config.js
Normal file
100
config/webpackDevServer.config.js
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const errorOverlayMiddleware = require('react-dev-utils/errorOverlayMiddleware');
|
||||||
|
const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware');
|
||||||
|
const path = require('path');
|
||||||
|
const config = require('./webpack.config.dev');
|
||||||
|
const paths = require('./paths');
|
||||||
|
|
||||||
|
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
|
||||||
|
const host = process.env.HOST || '0.0.0.0';
|
||||||
|
|
||||||
|
module.exports = function(proxy, allowedHost) {
|
||||||
|
return {
|
||||||
|
// WebpackDevServer 2.4.3 introduced a security fix that prevents remote
|
||||||
|
// websites from potentially accessing local content through DNS rebinding:
|
||||||
|
// https://github.com/webpack/webpack-dev-server/issues/887
|
||||||
|
// https://medium.com/webpack/webpack-dev-server-middleware-security-issues-1489d950874a
|
||||||
|
// However, it made several existing use cases such as development in cloud
|
||||||
|
// environment or subdomains in development significantly more complicated:
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/2271
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/2233
|
||||||
|
// While we're investigating better solutions, for now we will take a
|
||||||
|
// compromise. Since our WDS configuration only serves files in the `public`
|
||||||
|
// folder we won't consider accessing them a vulnerability. However, if you
|
||||||
|
// use the `proxy` feature, it gets more dangerous because it can expose
|
||||||
|
// remote code execution vulnerabilities in backends like Django and Rails.
|
||||||
|
// So we will disable the host check normally, but enable it if you have
|
||||||
|
// specified the `proxy` setting. Finally, we let you override it if you
|
||||||
|
// really know what you're doing with a special environment variable.
|
||||||
|
disableHostCheck:
|
||||||
|
!proxy || process.env.DANGEROUSLY_DISABLE_HOST_CHECK === 'true',
|
||||||
|
// Enable gzip compression of generated files.
|
||||||
|
compress: true,
|
||||||
|
// Silence WebpackDevServer's own logs since they're generally not useful.
|
||||||
|
// It will still show compile warnings and errors with this setting.
|
||||||
|
clientLogLevel: 'none',
|
||||||
|
// By default WebpackDevServer serves physical files from current directory
|
||||||
|
// in addition to all the virtual build products that it serves from memory.
|
||||||
|
// This is confusing because those files won’t automatically be available in
|
||||||
|
// production build folder unless we copy them. However, copying the whole
|
||||||
|
// project directory is dangerous because we may expose sensitive files.
|
||||||
|
// Instead, we establish a convention that only files in `public` directory
|
||||||
|
// get served. Our build script will copy `public` into the `build` folder.
|
||||||
|
// In `index.html`, you can get URL of `public` folder with %PUBLIC_URL%:
|
||||||
|
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
||||||
|
// In JavaScript code, you can access it with `process.env.PUBLIC_URL`.
|
||||||
|
// Note that we only recommend to use `public` folder as an escape hatch
|
||||||
|
// for files like `favicon.ico`, `manifest.json`, and libraries that are
|
||||||
|
// for some reason broken when imported through Webpack. If you just want to
|
||||||
|
// use an image, put it in `src` and `import` it from JavaScript instead.
|
||||||
|
contentBase: paths.appPublic,
|
||||||
|
// By default files from `contentBase` will not trigger a page reload.
|
||||||
|
watchContentBase: true,
|
||||||
|
// Enable hot reloading server. It will provide /sockjs-node/ endpoint
|
||||||
|
// for the WebpackDevServer client so it can learn when the files were
|
||||||
|
// updated. The WebpackDevServer client is included as an entry point
|
||||||
|
// in the Webpack development configuration. Note that only changes
|
||||||
|
// to CSS are currently hot reloaded. JS changes will refresh the browser.
|
||||||
|
hot: true,
|
||||||
|
// It is important to tell WebpackDevServer to use the same "root" path
|
||||||
|
// as we specified in the config. In development, we always serve from /.
|
||||||
|
publicPath: config.output.publicPath,
|
||||||
|
// WebpackDevServer is noisy by default so we emit custom message instead
|
||||||
|
// by listening to the compiler events with `compiler.plugin` calls above.
|
||||||
|
quiet: true,
|
||||||
|
// Reportedly, this avoids CPU overload on some systems.
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/293
|
||||||
|
// src/node_modules is not ignored to support absolute imports
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/1065
|
||||||
|
watchOptions: {
|
||||||
|
ignored: new RegExp(
|
||||||
|
`^(?!${path
|
||||||
|
.normalize(paths.appSrc + '/')
|
||||||
|
.replace(/[\\]+/g, '\\\\')}).+[\\\\/]node_modules[\\\\/]`,
|
||||||
|
'g'
|
||||||
|
),
|
||||||
|
},
|
||||||
|
// Enable HTTPS if the HTTPS environment variable is set to 'true'
|
||||||
|
https: protocol === 'https',
|
||||||
|
host: host,
|
||||||
|
overlay: false,
|
||||||
|
historyApiFallback: {
|
||||||
|
// Paths with dots should still use the history fallback.
|
||||||
|
// See https://github.com/facebookincubator/create-react-app/issues/387.
|
||||||
|
disableDotRule: true,
|
||||||
|
},
|
||||||
|
public: allowedHost,
|
||||||
|
proxy,
|
||||||
|
before(app) {
|
||||||
|
// This lets us open files from the runtime error overlay.
|
||||||
|
app.use(errorOverlayMiddleware());
|
||||||
|
// This service worker file is effectively a 'no-op' that will reset any
|
||||||
|
// previous service worker registered for the same host:port combination.
|
||||||
|
// We do this in development to avoid hitting the production cache if
|
||||||
|
// it used the same host and port.
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/2272#issuecomment-302832432
|
||||||
|
app.use(noopServiceWorkerMiddleware());
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
11688
package-lock.json
generated
Normal file
11688
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
124
package.json
Normal file
124
package.json
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
{
|
||||||
|
"name": "simple-keyboard",
|
||||||
|
"version": "2.0.0",
|
||||||
|
"description": "On-screen Virtual Keyboard",
|
||||||
|
"main": "build/index.js",
|
||||||
|
"scripts": {
|
||||||
|
"start": "node scripts/start.js",
|
||||||
|
"build": "node scripts/build.js",
|
||||||
|
"demo": "node scripts/demo.js",
|
||||||
|
"test": "node scripts/test.js --env=jsdom",
|
||||||
|
"prepublish": "npm run build"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/hodgef/simple-keyboard"
|
||||||
|
},
|
||||||
|
"author": "Francisco Hodge <hello@franciscohodge.com> (https://github.com/hodgef)",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/hodgef/simple-keyboard/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://franciscohodge.com/simple-keyboard",
|
||||||
|
"keywords": [
|
||||||
|
"javascript",
|
||||||
|
"es6",
|
||||||
|
"digital",
|
||||||
|
"keyboard",
|
||||||
|
"onscreen",
|
||||||
|
"virtual",
|
||||||
|
"component",
|
||||||
|
"virtual-keyboard",
|
||||||
|
"touchscreen",
|
||||||
|
"touch-screen"
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {},
|
||||||
|
"devDependencies": {
|
||||||
|
"autoprefixer": "7.1.6",
|
||||||
|
"babel-core": "6.26.0",
|
||||||
|
"babel-eslint": "7.2.3",
|
||||||
|
"babel-jest": "20.0.3",
|
||||||
|
"babel-loader": "7.1.2",
|
||||||
|
"babel-preset-react-app": "^3.1.0",
|
||||||
|
"babel-runtime": "6.26.0",
|
||||||
|
"case-sensitive-paths-webpack-plugin": "2.1.1",
|
||||||
|
"chalk": "1.1.3",
|
||||||
|
"copy-webpack-plugin": "^4.3.1",
|
||||||
|
"css-loader": "0.28.7",
|
||||||
|
"dotenv": "4.0.0",
|
||||||
|
"eslint": "4.10.0",
|
||||||
|
"eslint-config-react-app": "^2.0.1",
|
||||||
|
"eslint-loader": "1.9.0",
|
||||||
|
"eslint-plugin-flowtype": "2.39.1",
|
||||||
|
"eslint-plugin-import": "2.8.0",
|
||||||
|
"eslint-plugin-jsx-a11y": "5.1.1",
|
||||||
|
"eslint-plugin-react": "7.4.0",
|
||||||
|
"extract-text-webpack-plugin": "3.0.2",
|
||||||
|
"file-loader": "1.1.5",
|
||||||
|
"fs-extra": "3.0.1",
|
||||||
|
"html-webpack-plugin": "2.29.0",
|
||||||
|
"jest": "20.0.4",
|
||||||
|
"object-assign": "4.1.1",
|
||||||
|
"postcss-flexbugs-fixes": "3.2.0",
|
||||||
|
"postcss-loader": "2.0.8",
|
||||||
|
"promise": "8.0.1",
|
||||||
|
"raf": "3.4.0",
|
||||||
|
"react": "^16.2.0",
|
||||||
|
"react-dev-utils": "^4.2.1",
|
||||||
|
"react-dom": "^16.2.0",
|
||||||
|
"style-loader": "0.19.0",
|
||||||
|
"sw-precache-webpack-plugin": "0.11.4",
|
||||||
|
"url-loader": "0.6.2",
|
||||||
|
"webpack": "3.8.1",
|
||||||
|
"webpack-dev-server": "2.9.4",
|
||||||
|
"webpack-manifest-plugin": "1.3.2",
|
||||||
|
"whatwg-fetch": "2.0.3",
|
||||||
|
"prop-types": "^15.6.1"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"react": ">=0.14",
|
||||||
|
"react-dom": ">=0.14"
|
||||||
|
},
|
||||||
|
"jest": {
|
||||||
|
"collectCoverageFrom": [
|
||||||
|
"src/**/*.{js,jsx,mjs}"
|
||||||
|
],
|
||||||
|
"setupFiles": [
|
||||||
|
"<rootDir>/config/polyfills.js"
|
||||||
|
],
|
||||||
|
"testMatch": [
|
||||||
|
"<rootDir>/src/**/__tests__/**/*.{js,jsx,mjs}",
|
||||||
|
"<rootDir>/src/**/?(*.)(spec|test).{js,jsx,mjs}"
|
||||||
|
],
|
||||||
|
"testEnvironment": "node",
|
||||||
|
"testURL": "http://localhost",
|
||||||
|
"transform": {
|
||||||
|
"^.+\\.(js|jsx|mjs)$": "<rootDir>/node_modules/babel-jest",
|
||||||
|
"^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
|
||||||
|
"^(?!.*\\.(js|jsx|mjs|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
|
||||||
|
},
|
||||||
|
"transformIgnorePatterns": [
|
||||||
|
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs)$"
|
||||||
|
],
|
||||||
|
"moduleNameMapper": {
|
||||||
|
"^react-native$": "react-native-web"
|
||||||
|
},
|
||||||
|
"moduleFileExtensions": [
|
||||||
|
"web.js",
|
||||||
|
"mjs",
|
||||||
|
"js",
|
||||||
|
"json",
|
||||||
|
"web.jsx",
|
||||||
|
"jsx",
|
||||||
|
"node"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"babel": {
|
||||||
|
"presets": [
|
||||||
|
"react-app"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"eslintConfig": {
|
||||||
|
"extends": "react-app"
|
||||||
|
}
|
||||||
|
}
|
BIN
public/favicon.ico
Normal file
BIN
public/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
44
public/index.html
Normal file
44
public/index.html
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
|
<meta name="theme-color" content="#000000">
|
||||||
|
<!--
|
||||||
|
manifest.json provides metadata used when your web app is added to the
|
||||||
|
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
|
||||||
|
-->
|
||||||
|
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
|
||||||
|
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
||||||
|
<!--
|
||||||
|
Notice the use of %PUBLIC_URL% in the tags above.
|
||||||
|
It will be replaced with the URL of the `public` folder during the build.
|
||||||
|
Only files inside the `public` folder can be referenced from the HTML.
|
||||||
|
|
||||||
|
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
||||||
|
work correctly both with client-side routing and a non-root public URL.
|
||||||
|
Learn how to configure a non-root public URL by running `npm run build`.
|
||||||
|
-->
|
||||||
|
<title>simple-keyboard</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<noscript>
|
||||||
|
You need to enable JavaScript to run this app.
|
||||||
|
</noscript>
|
||||||
|
<div id="root">
|
||||||
|
<div class="simple-keyboard"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<!--
|
||||||
|
This HTML file is a template.
|
||||||
|
If you open it directly in the browser, you will see an empty page.
|
||||||
|
|
||||||
|
You can add webfonts, meta tags, or analytics to this file.
|
||||||
|
The build step will place the bundled scripts into the <body> tag.
|
||||||
|
|
||||||
|
To begin the development, run `npm start` or `yarn start`.
|
||||||
|
To create a production bundle, use `npm run build` or `yarn build`.
|
||||||
|
-->
|
||||||
|
</body>
|
||||||
|
</html>
|
15
public/manifest.json
Normal file
15
public/manifest.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"short_name": "React App",
|
||||||
|
"name": "Create React App Sample",
|
||||||
|
"icons": [
|
||||||
|
{
|
||||||
|
"src": "favicon.ico",
|
||||||
|
"sizes": "64x64 32x32 24x24 16x16",
|
||||||
|
"type": "image/x-icon"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"start_url": "./index.html",
|
||||||
|
"display": "standalone",
|
||||||
|
"theme_color": "#000000",
|
||||||
|
"background_color": "#ffffff"
|
||||||
|
}
|
127
scripts/build.js
Normal file
127
scripts/build.js
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// Do this as the first thing so that any code reading it knows the right env.
|
||||||
|
process.env.BABEL_ENV = 'production';
|
||||||
|
process.env.NODE_ENV = 'production';
|
||||||
|
|
||||||
|
// Makes the script crash on unhandled rejections instead of silently
|
||||||
|
// ignoring them. In the future, promise rejections that are not handled will
|
||||||
|
// terminate the Node.js process with a non-zero exit code.
|
||||||
|
process.on('unhandledRejection', err => {
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Ensure environment variables are read.
|
||||||
|
require('../config/env');
|
||||||
|
|
||||||
|
const chalk = require('chalk');
|
||||||
|
const fs = require('fs-extra');
|
||||||
|
const webpack = require('webpack');
|
||||||
|
const config = require('../config/webpack.config.prod');
|
||||||
|
const paths = require('../config/paths');
|
||||||
|
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
|
||||||
|
const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages');
|
||||||
|
const FileSizeReporter = require('react-dev-utils/FileSizeReporter');
|
||||||
|
const printBuildError = require('react-dev-utils/printBuildError');
|
||||||
|
|
||||||
|
const measureFileSizesBeforeBuild =
|
||||||
|
FileSizeReporter.measureFileSizesBeforeBuild;
|
||||||
|
const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild;
|
||||||
|
|
||||||
|
// These sizes are pretty large. We'll warn for bundles exceeding them.
|
||||||
|
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
|
||||||
|
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
|
||||||
|
|
||||||
|
// Warn and crash if required files are missing
|
||||||
|
if (!checkRequiredFiles([paths.appLibIndexJs])) { // CRL: Updated with library index file
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// First, read the current file sizes in build directory.
|
||||||
|
// This lets us display how much they changed later.
|
||||||
|
measureFileSizesBeforeBuild(paths.appBuild)
|
||||||
|
.then(previousFileSizes => {
|
||||||
|
// Remove all content but keep the directory so that
|
||||||
|
// if you're in it, you don't end up in Trash
|
||||||
|
fs.emptyDirSync(paths.appBuild);
|
||||||
|
|
||||||
|
// Start the webpack build
|
||||||
|
return build(previousFileSizes);
|
||||||
|
})
|
||||||
|
.then(
|
||||||
|
({ stats, previousFileSizes, warnings }) => {
|
||||||
|
if (warnings.length) {
|
||||||
|
console.log(chalk.yellow('Compiled with warnings.\n'));
|
||||||
|
console.log(warnings.join('\n\n'));
|
||||||
|
console.log(
|
||||||
|
'\nSearch for the ' +
|
||||||
|
chalk.underline(chalk.yellow('keywords')) +
|
||||||
|
' to learn more about each warning.'
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
'To ignore, add ' +
|
||||||
|
chalk.cyan('// eslint-disable-next-line') +
|
||||||
|
' to the line before.\n'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
console.log(chalk.green('Compiled successfully.\n'));
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('File sizes after gzip:\n');
|
||||||
|
printFileSizesAfterBuild(
|
||||||
|
stats,
|
||||||
|
previousFileSizes,
|
||||||
|
paths.appBuild,
|
||||||
|
WARN_AFTER_BUNDLE_GZIP_SIZE,
|
||||||
|
WARN_AFTER_CHUNK_GZIP_SIZE
|
||||||
|
);
|
||||||
|
console.log();
|
||||||
|
},
|
||||||
|
err => {
|
||||||
|
console.log(chalk.red('Failed to compile.\n'));
|
||||||
|
printBuildError(err);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Create the production build and print the deployment instructions.
|
||||||
|
function build(previousFileSizes) {
|
||||||
|
console.log('Creating an optimized production build...');
|
||||||
|
|
||||||
|
let compiler = webpack(config);
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
compiler.run((err, stats) => {
|
||||||
|
if (err) {
|
||||||
|
return reject(err);
|
||||||
|
}
|
||||||
|
const messages = formatWebpackMessages(stats.toJson({}, true));
|
||||||
|
if (messages.errors.length) {
|
||||||
|
// Only keep the first error. Others are often indicative
|
||||||
|
// of the same problem, but confuse the reader with noise.
|
||||||
|
if (messages.errors.length > 1) {
|
||||||
|
messages.errors.length = 1;
|
||||||
|
}
|
||||||
|
return reject(new Error(messages.errors.join('\n\n')));
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
process.env.CI &&
|
||||||
|
(typeof process.env.CI !== 'string' ||
|
||||||
|
process.env.CI.toLowerCase() !== 'false') &&
|
||||||
|
messages.warnings.length
|
||||||
|
) {
|
||||||
|
console.log(
|
||||||
|
chalk.yellow(
|
||||||
|
'\nTreating warnings as errors because process.env.CI = true.\n' +
|
||||||
|
'Most CI servers set it automatically.\n'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return reject(new Error(messages.warnings.join('\n\n')));
|
||||||
|
}
|
||||||
|
return resolve({
|
||||||
|
stats,
|
||||||
|
previousFileSizes,
|
||||||
|
warnings: messages.warnings,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
127
scripts/demo.js
Normal file
127
scripts/demo.js
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// Do this as the first thing so that any code reading it knows the right env.
|
||||||
|
process.env.BABEL_ENV = 'production';
|
||||||
|
process.env.NODE_ENV = 'production';
|
||||||
|
|
||||||
|
// Makes the script crash on unhandled rejections instead of silently
|
||||||
|
// ignoring them. In the future, promise rejections that are not handled will
|
||||||
|
// terminate the Node.js process with a non-zero exit code.
|
||||||
|
process.on('unhandledRejection', err => {
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Ensure environment variables are read.
|
||||||
|
require('../config/env');
|
||||||
|
|
||||||
|
const chalk = require('chalk');
|
||||||
|
const fs = require('fs-extra');
|
||||||
|
const webpack = require('webpack');
|
||||||
|
const config = require('../config/webpack.config.demo');
|
||||||
|
const paths = require('../config/paths');
|
||||||
|
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
|
||||||
|
const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages');
|
||||||
|
const FileSizeReporter = require('react-dev-utils/FileSizeReporter');
|
||||||
|
const printBuildError = require('react-dev-utils/printBuildError');
|
||||||
|
|
||||||
|
const measureFileSizesBeforeBuild =
|
||||||
|
FileSizeReporter.measureFileSizesBeforeBuild;
|
||||||
|
const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild;
|
||||||
|
|
||||||
|
// These sizes are pretty large. We'll warn for bundles exceeding them.
|
||||||
|
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
|
||||||
|
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
|
||||||
|
|
||||||
|
// Warn and crash if required files are missing
|
||||||
|
if (!checkRequiredFiles([paths.appDemoIndexJs])) { // CRL: Updated with library index file
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// First, read the current file sizes in build directory.
|
||||||
|
// This lets us display how much they changed later.
|
||||||
|
measureFileSizesBeforeBuild(paths.appDemoBuild)
|
||||||
|
.then(previousFileSizes => {
|
||||||
|
// Remove all content but keep the directory so that
|
||||||
|
// if you're in it, you don't end up in Trash
|
||||||
|
fs.emptyDirSync(paths.appDemoBuild);
|
||||||
|
|
||||||
|
// Start the webpack build
|
||||||
|
return build(previousFileSizes);
|
||||||
|
})
|
||||||
|
.then(
|
||||||
|
({ stats, previousFileSizes, warnings }) => {
|
||||||
|
if (warnings.length) {
|
||||||
|
console.log(chalk.yellow('Compiled with warnings.\n'));
|
||||||
|
console.log(warnings.join('\n\n'));
|
||||||
|
console.log(
|
||||||
|
'\nSearch for the ' +
|
||||||
|
chalk.underline(chalk.yellow('keywords')) +
|
||||||
|
' to learn more about each warning.'
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
'To ignore, add ' +
|
||||||
|
chalk.cyan('// eslint-disable-next-line') +
|
||||||
|
' to the line before.\n'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
console.log(chalk.green('Compiled successfully.\n'));
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('File sizes after gzip:\n');
|
||||||
|
printFileSizesAfterBuild(
|
||||||
|
stats,
|
||||||
|
previousFileSizes,
|
||||||
|
paths.appDemoBuild,
|
||||||
|
WARN_AFTER_BUNDLE_GZIP_SIZE,
|
||||||
|
WARN_AFTER_CHUNK_GZIP_SIZE
|
||||||
|
);
|
||||||
|
console.log();
|
||||||
|
},
|
||||||
|
err => {
|
||||||
|
console.log(chalk.red('Failed to compile.\n'));
|
||||||
|
printBuildError(err);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Create the production build and print the deployment instructions.
|
||||||
|
function build(previousFileSizes) {
|
||||||
|
console.log('Creating a build of the demo app...');
|
||||||
|
|
||||||
|
let compiler = webpack(config);
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
compiler.run((err, stats) => {
|
||||||
|
if (err) {
|
||||||
|
return reject(err);
|
||||||
|
}
|
||||||
|
const messages = formatWebpackMessages(stats.toJson({}, true));
|
||||||
|
if (messages.errors.length) {
|
||||||
|
// Only keep the first error. Others are often indicative
|
||||||
|
// of the same problem, but confuse the reader with noise.
|
||||||
|
if (messages.errors.length > 1) {
|
||||||
|
messages.errors.length = 1;
|
||||||
|
}
|
||||||
|
return reject(new Error(messages.errors.join('\n\n')));
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
process.env.CI &&
|
||||||
|
(typeof process.env.CI !== 'string' ||
|
||||||
|
process.env.CI.toLowerCase() !== 'false') &&
|
||||||
|
messages.warnings.length
|
||||||
|
) {
|
||||||
|
console.log(
|
||||||
|
chalk.yellow(
|
||||||
|
'\nTreating warnings as errors because process.env.CI = true.\n' +
|
||||||
|
'Most CI servers set it automatically.\n'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return reject(new Error(messages.warnings.join('\n\n')));
|
||||||
|
}
|
||||||
|
return resolve({
|
||||||
|
stats,
|
||||||
|
previousFileSizes,
|
||||||
|
warnings: messages.warnings,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
92
scripts/start.js
Normal file
92
scripts/start.js
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// Do this as the first thing so that any code reading it knows the right env.
|
||||||
|
process.env.BABEL_ENV = 'development';
|
||||||
|
process.env.NODE_ENV = 'development';
|
||||||
|
|
||||||
|
// Makes the script crash on unhandled rejections instead of silently
|
||||||
|
// ignoring them. In the future, promise rejections that are not handled will
|
||||||
|
// terminate the Node.js process with a non-zero exit code.
|
||||||
|
process.on('unhandledRejection', err => {
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Ensure environment variables are read.
|
||||||
|
require('../config/env');
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const chalk = require('chalk');
|
||||||
|
const webpack = require('webpack');
|
||||||
|
const WebpackDevServer = require('webpack-dev-server');
|
||||||
|
const clearConsole = require('react-dev-utils/clearConsole');
|
||||||
|
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
|
||||||
|
const {
|
||||||
|
choosePort,
|
||||||
|
createCompiler,
|
||||||
|
prepareProxy,
|
||||||
|
prepareUrls,
|
||||||
|
} = require('react-dev-utils/WebpackDevServerUtils');
|
||||||
|
const openBrowser = require('react-dev-utils/openBrowser');
|
||||||
|
const paths = require('../config/paths');
|
||||||
|
const config = require('../config/webpack.config.dev');
|
||||||
|
const createDevServerConfig = require('../config/webpackDevServer.config');
|
||||||
|
|
||||||
|
const useYarn = fs.existsSync(paths.yarnLockFile);
|
||||||
|
const isInteractive = process.stdout.isTTY;
|
||||||
|
|
||||||
|
// Warn and crash if required files are missing
|
||||||
|
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tools like Cloud9 rely on this.
|
||||||
|
const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3000;
|
||||||
|
const HOST = process.env.HOST || '0.0.0.0';
|
||||||
|
|
||||||
|
// We attempt to use the default port but if it is busy, we offer the user to
|
||||||
|
// run on a different port. `detect()` Promise resolves to the next free port.
|
||||||
|
choosePort(HOST, DEFAULT_PORT)
|
||||||
|
.then(port => {
|
||||||
|
if (port == null) {
|
||||||
|
// We have not found a port.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
|
||||||
|
const appName = require(paths.appPackageJson).name;
|
||||||
|
const urls = prepareUrls(protocol, HOST, port);
|
||||||
|
// Create a webpack compiler that is configured with custom messages.
|
||||||
|
const compiler = createCompiler(webpack, config, appName, urls, useYarn);
|
||||||
|
// Load proxy config
|
||||||
|
const proxySetting = require(paths.appPackageJson).proxy;
|
||||||
|
const proxyConfig = prepareProxy(proxySetting, paths.appPublic);
|
||||||
|
// Serve webpack assets generated by the compiler over a web sever.
|
||||||
|
const serverConfig = createDevServerConfig(
|
||||||
|
proxyConfig,
|
||||||
|
urls.lanUrlForConfig
|
||||||
|
);
|
||||||
|
const devServer = new WebpackDevServer(compiler, serverConfig);
|
||||||
|
// Launch WebpackDevServer.
|
||||||
|
devServer.listen(port, HOST, err => {
|
||||||
|
if (err) {
|
||||||
|
return console.log(err);
|
||||||
|
}
|
||||||
|
if (isInteractive) {
|
||||||
|
clearConsole();
|
||||||
|
}
|
||||||
|
console.log(chalk.cyan('Starting the development server...\n'));
|
||||||
|
openBrowser(urls.localUrlForBrowser);
|
||||||
|
});
|
||||||
|
|
||||||
|
['SIGINT', 'SIGTERM'].forEach(function(sig) {
|
||||||
|
process.on(sig, function() {
|
||||||
|
devServer.close();
|
||||||
|
process.exit();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
if (err && err.message) {
|
||||||
|
console.log(err.message);
|
||||||
|
}
|
||||||
|
process.exit(1);
|
||||||
|
});
|
27
scripts/test.js
Normal file
27
scripts/test.js
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// Do this as the first thing so that any code reading it knows the right env.
|
||||||
|
process.env.BABEL_ENV = 'test';
|
||||||
|
process.env.NODE_ENV = 'test';
|
||||||
|
process.env.PUBLIC_URL = '';
|
||||||
|
|
||||||
|
// Makes the script crash on unhandled rejections instead of silently
|
||||||
|
// ignoring them. In the future, promise rejections that are not handled will
|
||||||
|
// terminate the Node.js process with a non-zero exit code.
|
||||||
|
process.on('unhandledRejection', err => {
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Ensure environment variables are read.
|
||||||
|
require('../config/env');
|
||||||
|
|
||||||
|
const jest = require('jest');
|
||||||
|
const argv = process.argv.slice(2);
|
||||||
|
|
||||||
|
// Watch unless on CI or in coverage mode
|
||||||
|
if (!process.env.CI && argv.indexOf('--coverage') < 0) {
|
||||||
|
argv.push('--watch');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
jest.run(argv);
|
31
src/demo/App.css
Normal file
31
src/demo/App.css
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#root {
|
||||||
|
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
|
||||||
|
max-width: 1000px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding-top: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#root .simple-keyboard-preview {
|
||||||
|
background: rgba(0,0,0,0.8);
|
||||||
|
border: 20px solid;
|
||||||
|
height: 300px;
|
||||||
|
border-top-right-radius: 5px;
|
||||||
|
border-top-left-radius: 5px;
|
||||||
|
padding: 10px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
#root .input {
|
||||||
|
color: white;
|
||||||
|
background: transparent;
|
||||||
|
border: none;
|
||||||
|
outline: none;
|
||||||
|
font-family: monospace;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard.hg-layout-custom {
|
||||||
|
border-top-left-radius: 0px;
|
||||||
|
border-top-right-radius: 0px;
|
||||||
|
}
|
49
src/demo/App.js
Normal file
49
src/demo/App.js
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import Keyboard from '../lib';
|
||||||
|
import './App.css';
|
||||||
|
|
||||||
|
class App {
|
||||||
|
constructor(){
|
||||||
|
document.addEventListener('DOMContentLoaded', this.onDOMLoaded);
|
||||||
|
|
||||||
|
this.layoutName = "default";
|
||||||
|
}
|
||||||
|
|
||||||
|
onDOMLoaded = () => {
|
||||||
|
this.keyboard = new Keyboard({
|
||||||
|
debug: true,
|
||||||
|
layoutName: this.layoutName,
|
||||||
|
onChange: input => this.onChange(input),
|
||||||
|
onKeyPress: button => this.onKeyPress(button)
|
||||||
|
});
|
||||||
|
|
||||||
|
this.keyboard.setInput("Hello World!");
|
||||||
|
|
||||||
|
console.log(this.keyboard);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleShiftButton = () => {
|
||||||
|
let layoutName = this.layoutName;
|
||||||
|
let shiftToggle = this.layoutName = layoutName === "default" ? "shift" : "default";
|
||||||
|
|
||||||
|
this.keyboard.setOptions({
|
||||||
|
layoutName: shiftToggle
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onChange = input => {
|
||||||
|
document.querySelector('.input').value = input;
|
||||||
|
}
|
||||||
|
|
||||||
|
onKeyPress = button => {
|
||||||
|
console.log("Button pressed", button);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shift functionality
|
||||||
|
*/
|
||||||
|
if(button === "{lock}" || button === "{shift}")
|
||||||
|
this.handleShiftButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default App;
|
BIN
src/demo/images/demo.gif
Normal file
BIN
src/demo/images/demo.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 MiB |
BIN
src/demo/images/keyboard.PNG
Normal file
BIN
src/demo/images/keyboard.PNG
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
BIN
src/demo/images/simple-keyboard.png
Normal file
BIN
src/demo/images/simple-keyboard.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.7 KiB |
15
src/demo/index.js
Normal file
15
src/demo/index.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import App from './App';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializing demo
|
||||||
|
*/
|
||||||
|
new App();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adding preview (demo only)
|
||||||
|
*/
|
||||||
|
document.querySelector('.simple-keyboard').insertAdjacentHTML('beforebegin', `
|
||||||
|
<div class="simple-keyboard-preview">
|
||||||
|
<textarea class="input" readonly>Hello World!</textarea>
|
||||||
|
</div>
|
||||||
|
`);
|
66
src/lib/components/Keyboard.css
Normal file
66
src/lib/components/Keyboard.css
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
body, html {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard {
|
||||||
|
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
|
||||||
|
width: 100%;
|
||||||
|
user-select: none;
|
||||||
|
box-sizing: border-box;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard .hg-row {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard .hg-row:not(:last-child) {
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard .hg-row .hg-button:not(:last-child) {
|
||||||
|
margin-right: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard .hg-button {
|
||||||
|
display: inline-block;
|
||||||
|
flex-grow: 1;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard.hg-layout-default .hg-button.hg-standardBtn {
|
||||||
|
max-width: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* hg-theme-default theme
|
||||||
|
*/
|
||||||
|
.simple-keyboard.hg-theme-default {
|
||||||
|
background-color: rgba(0,0,0,0.2);
|
||||||
|
padding: 5px;
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard.hg-theme-default .hg-button {
|
||||||
|
box-shadow: 0px 0px 3px -1px rgba(0,0,0,0.3);
|
||||||
|
height: 40px;
|
||||||
|
border: 1px solid rgba(0,0,0,0.25);
|
||||||
|
border-radius: 5px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
padding: 5px;
|
||||||
|
background: white;
|
||||||
|
border-bottom: 1px solid gray;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard.hg-theme-default .hg-button:active {
|
||||||
|
background: #e4e4e4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-keyboard.hg-theme-default.hg-layout-numeric .hg-button {
|
||||||
|
width: 33.3%;
|
||||||
|
height: 60px;
|
||||||
|
align-items: center;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
165
src/lib/components/Keyboard.js
Normal file
165
src/lib/components/Keyboard.js
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
import './Keyboard.css';
|
||||||
|
|
||||||
|
// Services
|
||||||
|
import KeyboardLayout from '../services/KeyboardLayout';
|
||||||
|
import Utilities from '../services/Utilities';
|
||||||
|
|
||||||
|
class SimpleKeyboard {
|
||||||
|
constructor(...params){
|
||||||
|
let keyboardDOMQuery = typeof params[0] === "string" ? params[0] : '.simple-keyboard';
|
||||||
|
let options = typeof params[0] === "object" ? params[0] : params[1];
|
||||||
|
|
||||||
|
if(!options)
|
||||||
|
options = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processing options
|
||||||
|
*/
|
||||||
|
this.keyboardDOM = document.querySelector(keyboardDOMQuery);
|
||||||
|
this.options = options;
|
||||||
|
this.input = '';
|
||||||
|
this.options.layoutName = this.options.layoutName || "default";
|
||||||
|
this.options.theme = this.options.theme || "hg-theme-default";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rendering keyboard
|
||||||
|
*/
|
||||||
|
if(this.keyboardDOM)
|
||||||
|
this.render();
|
||||||
|
else
|
||||||
|
console.error(`"${keyboardDOMQuery}" was not found in the DOM.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleButtonClicked = (button) => {
|
||||||
|
let debug = this.options.debug;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ignoring placeholder buttons
|
||||||
|
*/
|
||||||
|
if(button === '{//}')
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calling onKeyPress
|
||||||
|
*/
|
||||||
|
if(typeof this.options.onKeyPress === "function")
|
||||||
|
this.options.onKeyPress(button);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updating input
|
||||||
|
*/
|
||||||
|
let options = {
|
||||||
|
newLineOnEnter: (this.options.newLineOnEnter === true)
|
||||||
|
}
|
||||||
|
|
||||||
|
let updatedInput = Utilities.getUpdatedInput(button, this.input, options);
|
||||||
|
|
||||||
|
if(this.input !== updatedInput){
|
||||||
|
this.input = updatedInput;
|
||||||
|
|
||||||
|
if(debug)
|
||||||
|
console.log('Input changed:', this.input);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calling onChange
|
||||||
|
*/
|
||||||
|
if(typeof this.options.onChange === "function")
|
||||||
|
this.options.onChange(this.input);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(debug){
|
||||||
|
console.log("Key pressed:", button);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
clearInput = () => {
|
||||||
|
this.input = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
getInput = () => {
|
||||||
|
return this.input;
|
||||||
|
}
|
||||||
|
|
||||||
|
setInput = input => {
|
||||||
|
this.input = input;
|
||||||
|
}
|
||||||
|
|
||||||
|
setOptions = option => {
|
||||||
|
option = option || {};
|
||||||
|
this.options = Object.assign(this.options, option);
|
||||||
|
this.render();
|
||||||
|
}
|
||||||
|
|
||||||
|
clear = () => {
|
||||||
|
this.keyboardDOM.innerHTML = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
render = () => {
|
||||||
|
/**
|
||||||
|
* Clear keyboard
|
||||||
|
*/
|
||||||
|
this.clear();
|
||||||
|
|
||||||
|
let layoutClass = this.options.layout ? "hg-layout-custom" : `hg-layout-${this.options.layoutName}`;
|
||||||
|
let layout = this.options.layout || KeyboardLayout.getLayout(this.options.layoutName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adding themeClass, layoutClass to keyboardDOM
|
||||||
|
*/
|
||||||
|
this.keyboardDOM.className += ` ${this.options.theme} ${layoutClass}`;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterating through each row
|
||||||
|
*/
|
||||||
|
layout[this.options.layoutName].forEach((row, index) => {
|
||||||
|
let rowArray = row.split(' ');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creating empty row
|
||||||
|
*/
|
||||||
|
var rowDOM = document.createElement('div');
|
||||||
|
rowDOM.className += "hg-row";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterating through each button in row
|
||||||
|
*/
|
||||||
|
rowArray.forEach((button, index) => {
|
||||||
|
let fctBtnClass = Utilities.getButtonClass(button);
|
||||||
|
let buttonDisplayName = Utilities.getButtonDisplayName(button, this.options.display);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creating button
|
||||||
|
*/
|
||||||
|
var buttonDOM = document.createElement('div');
|
||||||
|
buttonDOM.className += `hg-button ${fctBtnClass}`;
|
||||||
|
buttonDOM.onclick = () => this.handleButtonClicked(button);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adding button label to button
|
||||||
|
*/
|
||||||
|
var buttonSpanDOM = document.createElement('span');
|
||||||
|
buttonSpanDOM.innerHTML = buttonDisplayName;
|
||||||
|
buttonDOM.appendChild(buttonSpanDOM);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appending button to row
|
||||||
|
*/
|
||||||
|
rowDOM.appendChild(buttonDOM);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calling onInit
|
||||||
|
*/
|
||||||
|
if(typeof this.options.onInit === "function")
|
||||||
|
this.options.onInit();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appending row to keyboard
|
||||||
|
*/
|
||||||
|
this.keyboardDOM.appendChild(rowDOM);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default SimpleKeyboard;
|
8
src/lib/components/Keyboard.test.js
Normal file
8
src/lib/components/Keyboard.test.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import ReactDOM from 'react-dom';
|
||||||
|
import Keyboard from './Keyboard';
|
||||||
|
|
||||||
|
it('Keyboard renders without crashing', () => {
|
||||||
|
const div = document.createElement('div');
|
||||||
|
ReactDOM.render(<Keyboard />, div);
|
||||||
|
});
|
2
src/lib/index.js
Normal file
2
src/lib/index.js
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
import SimpleKeyboard from './components/Keyboard';
|
||||||
|
export default SimpleKeyboard;
|
37
src/lib/services/KeyboardLayout.js
Normal file
37
src/lib/services/KeyboardLayout.js
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
class KeyboardLayout {
|
||||||
|
|
||||||
|
static getLayout = layout => {
|
||||||
|
if(layout === "qwerty"){
|
||||||
|
return {
|
||||||
|
'default': [
|
||||||
|
'` 1 2 3 4 5 6 7 8 9 0 - = {bksp}',
|
||||||
|
'{tab} q w e r t y u i o p [ ] \\',
|
||||||
|
'{lock} a s d f g h j k l ; \' {enter}',
|
||||||
|
'{shift} z x c v b n m , . / {shift}',
|
||||||
|
'.com @ {space}'
|
||||||
|
],
|
||||||
|
'shift': [
|
||||||
|
'~ ! @ # $ % ^ & * ( ) _ + {bksp}',
|
||||||
|
'{tab} Q W E R T Y U I O P { } |',
|
||||||
|
'{lock} A S D F G H J K L : " {enter}',
|
||||||
|
'{shift} Z X C V B N M < > ? {shift}',
|
||||||
|
'.com @ {space}'
|
||||||
|
]
|
||||||
|
};
|
||||||
|
} else if(layout === "numeric"){
|
||||||
|
return {
|
||||||
|
'default': [
|
||||||
|
'1 2 3',
|
||||||
|
'4 5 6',
|
||||||
|
'7 8 9',
|
||||||
|
'{//} 0 {bksp}'
|
||||||
|
]
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return KeyboardLayout.getLayout("qwerty");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default KeyboardLayout;
|
92
src/lib/services/Utilities.js
Normal file
92
src/lib/services/Utilities.js
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
class Utilities {
|
||||||
|
static normalizeString(string){
|
||||||
|
let output;
|
||||||
|
|
||||||
|
if(string === "@")
|
||||||
|
output = 'at';
|
||||||
|
else if(string === ",")
|
||||||
|
output = 'comma';
|
||||||
|
else if(string === ".")
|
||||||
|
output = 'dot';
|
||||||
|
else if(string === "\\")
|
||||||
|
output = 'backslash';
|
||||||
|
else if(string === "/")
|
||||||
|
output = 'fordardslash';
|
||||||
|
else if(string === "*")
|
||||||
|
output = 'asterisk';
|
||||||
|
else if(string === "&")
|
||||||
|
output = 'ampersand';
|
||||||
|
else if(string === "$")
|
||||||
|
output = 'dollarsign';
|
||||||
|
else if(string === "=")
|
||||||
|
output = 'equals';
|
||||||
|
else if(string === "+")
|
||||||
|
output = 'plus';
|
||||||
|
else if(string === "-")
|
||||||
|
output = 'minus';
|
||||||
|
else if(string === "'")
|
||||||
|
output = 'apostrophe';
|
||||||
|
else if(string === ";")
|
||||||
|
output = 'colon';
|
||||||
|
else if(string === "[")
|
||||||
|
output = 'openbracket';
|
||||||
|
else if(string === "]")
|
||||||
|
output = 'closebracket';
|
||||||
|
else if(string === "//")
|
||||||
|
output = 'emptybutton';
|
||||||
|
else
|
||||||
|
output = '';
|
||||||
|
|
||||||
|
return output ? ` hg-button-${output}` : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
static getButtonClass = button => {
|
||||||
|
let buttonTypeClass = (button.includes("{") && button !== '{//}') ? "functionBtn" : "standardBtn";
|
||||||
|
let buttonWithoutBraces = button.replace("{", "").replace("}", "");
|
||||||
|
|
||||||
|
let buttonNormalized =
|
||||||
|
buttonTypeClass === "standardBtn" ?
|
||||||
|
Utilities.normalizeString(buttonWithoutBraces) : ` hg-button-${buttonWithoutBraces}`;
|
||||||
|
|
||||||
|
return `hg-${buttonTypeClass}${buttonNormalized}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static getDefaultDiplay(){
|
||||||
|
return {
|
||||||
|
'{bksp}': 'delete',
|
||||||
|
'{enter}': '< enter',
|
||||||
|
'{shift}': 'shift',
|
||||||
|
'{s}': 'shift',
|
||||||
|
'{tab}': 'tab',
|
||||||
|
'{lock}': 'caps',
|
||||||
|
'{accept}': 'Submit',
|
||||||
|
'{space}': ' ',
|
||||||
|
'{//}': ' '
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static getButtonDisplayName = (button, display) => {
|
||||||
|
display = display || Utilities.getDefaultDiplay();
|
||||||
|
return display[button] || button;
|
||||||
|
}
|
||||||
|
|
||||||
|
static getUpdatedInput = (button, input, options) => {
|
||||||
|
let output = input;
|
||||||
|
let newLineOnEnter = options.newLineOnEnter;
|
||||||
|
|
||||||
|
if(button === "{bksp}" && output.length > 0)
|
||||||
|
output = output.slice(0, -1);
|
||||||
|
else if(button === "{space}")
|
||||||
|
output = output + ' ';
|
||||||
|
else if(button === "{tab}")
|
||||||
|
output = output + "\t";
|
||||||
|
else if(button === "{enter}" && newLineOnEnter)
|
||||||
|
output = output + "\n";
|
||||||
|
else if(!button.includes("{") && !button.includes("{"))
|
||||||
|
output = output + button;
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Utilities;
|
Loading…
Reference in New Issue
Block a user