Skip to content

Commit

Permalink
Upgrade to Webpack2, upgraded all node modules, updated create-react-app
Browse files Browse the repository at this point in the history
files based on latest alpha version
  • Loading branch information
TrafeX committed May 17, 2017
1 parent c0c14c4 commit 5d42b2a
Show file tree
Hide file tree
Showing 13 changed files with 1,928 additions and 1,431 deletions.
1 change: 1 addition & 0 deletions .env.production
@@ -0,0 +1 @@
BACKEND_URL=http://vps01.trafex.nl:3001
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -14,7 +14,7 @@ before_install:
script: script:
- docker run --rm trafex/clipboard-frontend yarn lint - docker run --rm trafex/clipboard-frontend yarn lint
- docker run --rm trafex/clipboard-frontend yarn test-coverage - docker run --rm trafex/clipboard-frontend yarn test-coverage
- docker run --rm -e "BACKEND_URL=http://vps01.trafex.nl:3001" -v `pwd`/build:/usr/src/app/build trafex/clipboard-frontend yarn build - docker run --rm -v `pwd`/build:/usr/src/app/build trafex/clipboard-frontend yarn build
- docker run -d trafex/clipboard-backend - docker run -d trafex/clipboard-backend
- docker run -d trafex/clipboard-frontend - docker run -d trafex/clipboard-frontend
- docker ps -a - docker ps -a
Expand Down
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -23,7 +23,7 @@ This is a work in progress rebuild of the [orginal clipboard.ninja app](https://


### Todo ### Todo


- [ ] Webpack2 - [X] Webpack2
- [ ] Server side rendering - [ ] Server side rendering
- [ ] React Native Android app - [ ] React Native Android app
- [X] Continuous Integration - [X] Continuous Integration
Expand All @@ -32,3 +32,4 @@ This is a work in progress rebuild of the [orginal clipboard.ninja app](https://
- [ ] Cleanup used packages and configs - [ ] Cleanup used packages and configs
- [ ] Better tests: http://facebook.github.io/jest/docs/en/tutorial-react-native.html#snapshot-test - [ ] Better tests: http://facebook.github.io/jest/docs/en/tutorial-react-native.html#snapshot-test
- [ ] Send on ctrl + enter - [ ] Send on ctrl + enter
- [ ] Dump/simplify create-react-app bootstrap
76 changes: 53 additions & 23 deletions config/env.js
@@ -1,36 +1,66 @@
'use strict'; 'use strict';


var fs = require('fs');
var paths = require('./paths');

var 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,
paths.dotenv + '.local',
paths.dotenv,
];
// 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,
});
}
});

// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be // Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
// injected into the application via DefinePlugin in Webpack configuration. // injected into the application via DefinePlugin in Webpack configuration.

const REACT_APP = /^REACT_APP_/i;
var REACT_APP = /^REACT_APP_/i;


function getClientEnvironment(publicUrl) { function getClientEnvironment(publicUrl) {
var raw = Object const raw = Object.keys(process.env)
.keys(process.env)
.filter(key => REACT_APP.test(key)) .filter(key => REACT_APP.test(key))
.reduce((env, key) => { .reduce(
env[key] = process.env[key]; (env, key) => {
return env; 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 determining whether we’re running in production mode.
// Useful for resolving the correct path to static assets in `public`. // Most importantly, it switches React into the correct mode.
// For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />. NODE_ENV: process.env.NODE_ENV || 'development',
// This should only be used as an escape hatch. Normally you would put // Useful for resolving the correct path to static assets in `public`.
// images into the `src` and `import` them in code to get their paths. // For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
'PUBLIC_URL': publicUrl, // This should only be used as an escape hatch. Normally you would put
'BACKEND_URL': process.env.BACKEND_URL || 'http://localhost:3001' // 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 // Stringify all values so we can feed into Webpack DefinePlugin
var stringified = { const stringified = {
'process.env': Object 'process.env': Object.keys(raw).reduce(
.keys(raw) (env, key) => {
.reduce((env, key) => {
env[key] = JSON.stringify(raw[key]); env[key] = JSON.stringify(raw[key]);
return env; return env;
}, {}) },
{}
),
}; };


return { raw, stringified }; return { raw, stringified };
Expand Down
26 changes: 13 additions & 13 deletions config/paths.js
@@ -1,12 +1,12 @@
'use strict'; 'use strict';


var path = require('path'); const path = require('path');
var fs = require('fs'); const fs = require('fs');
var url = require('url'); const url = require('url');


// Make sure any symlinks in the project folder are resolved: // Make sure any symlinks in the project folder are resolved:
// https://github.com/facebookincubator/create-react-app/issues/637 // https://github.com/facebookincubator/create-react-app/issues/637
var appDirectory = fs.realpathSync(process.cwd()); const appDirectory = fs.realpathSync(process.cwd());
function resolveApp(relativePath) { function resolveApp(relativePath) {
return path.resolve(appDirectory, relativePath); return path.resolve(appDirectory, relativePath);
} }
Expand All @@ -26,20 +26,20 @@ function resolveApp(relativePath) {
// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims. // 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 // https://github.com/facebookincubator/create-react-app/issues/1023#issuecomment-265344421


var nodePaths = (process.env.NODE_PATH || '') const nodePaths = (process.env.NODE_PATH || '')
.split(process.platform === 'win32' ? ';' : ':') .split(process.platform === 'win32' ? ';' : ':')
.filter(Boolean) .filter(Boolean)
.filter(folder => !path.isAbsolute(folder)) .filter(folder => !path.isAbsolute(folder))
.map(resolveApp); .map(resolveApp);


var envPublicUrl = process.env.PUBLIC_URL; const envPublicUrl = process.env.PUBLIC_URL;


function ensureSlash(path, needsSlash) { function ensureSlash(path, needsSlash) {
var hasSlash = path.endsWith('/'); const hasSlash = path.endsWith('/');
if (hasSlash && !needsSlash) { if (hasSlash && !needsSlash) {
return path.substr(path, path.length - 1); return path.substr(path, path.length - 1);
} else if (!hasSlash && needsSlash) { } else if (!hasSlash && needsSlash) {
return path + '/'; return `${path}/`;
} else { } else {
return path; return path;
} }
Expand All @@ -56,15 +56,15 @@ function getPublicUrl(appPackageJson) {
// We can't use a relative path in HTML because we don't want to load something // 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. // like /todos/42/static/js/bundle.7289d.js. We have to know the root.
function getServedPath(appPackageJson) { function getServedPath(appPackageJson) {
var publicUrl = getPublicUrl(appPackageJson); const publicUrl = getPublicUrl(appPackageJson);
var servedUrl = envPublicUrl || ( const servedUrl = envPublicUrl ||
publicUrl ? url.parse(publicUrl).pathname : '/' (publicUrl ? url.parse(publicUrl).pathname : '/');
);
return ensureSlash(servedUrl, true); return ensureSlash(servedUrl, true);
} }


// config after eject: we're in ./config/ // config after eject: we're in ./config/
module.exports = { module.exports = {
dotenv: resolveApp('.env'),
appBuild: resolveApp('build'), appBuild: resolveApp('build'),
appPublic: resolveApp('public'), appPublic: resolveApp('public'),
appHtml: resolveApp('public/index.html'), appHtml: resolveApp('public/index.html'),
Expand All @@ -76,5 +76,5 @@ module.exports = {
appNodeModules: resolveApp('node_modules'), appNodeModules: resolveApp('node_modules'),
nodePaths: nodePaths, nodePaths: nodePaths,
publicUrl: getPublicUrl(resolveApp('package.json')), publicUrl: getPublicUrl(resolveApp('package.json')),
servedPath: getServedPath(resolveApp('package.json')) servedPath: getServedPath(resolveApp('package.json')),
}; };

0 comments on commit 5d42b2a

Please sign in to comment.