Permalink
Browse files

Upgrade to Webpack2, upgraded all node modules, updated create-react-app

files based on latest alpha version
  • Loading branch information...
TrafeX committed May 17, 2017
1 parent c0c14c4 commit 5d42b2a917638bed69a7046412c2f4959d36e18e
Showing with 1,928 additions and 1,431 deletions.
  1. +1 −0 .env.production
  2. +1 −1 .travis.yml
  3. +2 −1 README.md
  4. +53 −23 config/env.js
  5. +13 −13 config/paths.js
  6. +118 −81 config/webpack.config.dev.js
  7. +124 −97 config/webpack.config.prod.js
  8. +74 −0 config/webpackDevServer.config.js
  9. +40 −36 package.json
  10. +92 −52 scripts/build.js
  11. +129 −261 scripts/start.js
  12. +120 −0 scripts/utils/createWebpackCompiler.js
  13. +1,161 −866 yarn.lock
@@ -0,0 +1 @@
BACKEND_URL=http://vps01.trafex.nl:3001
@@ -14,7 +14,7 @@ before_install:
script:
- docker run --rm trafex/clipboard-frontend yarn lint
- 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-frontend
- docker ps -a
@@ -23,7 +23,7 @@ This is a work in progress rebuild of the [orginal clipboard.ninja app](https://
### Todo
- [ ] Webpack2
- [X] Webpack2
- [ ] Server side rendering
- [ ] React Native Android app
- [X] Continuous Integration
@@ -32,3 +32,4 @@ This is a work in progress rebuild of the [orginal clipboard.ninja app](https://
- [ ] Cleanup used packages and configs
- [ ] Better tests: http://facebook.github.io/jest/docs/en/tutorial-react-native.html#snapshot-test
- [ ] Send on ctrl + enter
- [ ] Dump/simplify create-react-app bootstrap
@@ -1,36 +1,66 @@
'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
// injected into the application via DefinePlugin in Webpack configuration.
var REACT_APP = /^REACT_APP_/i;
const REACT_APP = /^REACT_APP_/i;
function getClientEnvironment(publicUrl) {
var raw = Object
.keys(process.env)
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,
'BACKEND_URL': process.env.BACKEND_URL || 'http://localhost:3001'
});
.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
var stringified = {
'process.env': Object
.keys(raw)
.reduce((env, key) => {
const stringified = {
'process.env': Object.keys(raw).reduce(
(env, key) => {
env[key] = JSON.stringify(raw[key]);
return env;
}, {})
},
{}
),
};
return { raw, stringified };
@@ -1,12 +1,12 @@
'use strict';
var path = require('path');
var fs = require('fs');
var url = require('url');
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
var appDirectory = fs.realpathSync(process.cwd());
const appDirectory = fs.realpathSync(process.cwd());
function resolveApp(relativePath) {
return path.resolve(appDirectory, relativePath);
}
@@ -26,20 +26,20 @@ function resolveApp(relativePath) {
// 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
var nodePaths = (process.env.NODE_PATH || '')
const nodePaths = (process.env.NODE_PATH || '')
.split(process.platform === 'win32' ? ';' : ':')
.filter(Boolean)
.filter(folder => !path.isAbsolute(folder))
.map(resolveApp);
var envPublicUrl = process.env.PUBLIC_URL;
const envPublicUrl = process.env.PUBLIC_URL;
function ensureSlash(path, needsSlash) {
var hasSlash = path.endsWith('/');
const hasSlash = path.endsWith('/');
if (hasSlash && !needsSlash) {
return path.substr(path, path.length - 1);
} else if (!hasSlash && needsSlash) {
return path + '/';
return `${path}/`;
} else {
return path;
}
@@ -56,15 +56,15 @@ function getPublicUrl(appPackageJson) {
// 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) {
var publicUrl = getPublicUrl(appPackageJson);
var servedUrl = envPublicUrl || (
publicUrl ? url.parse(publicUrl).pathname : '/'
);
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'),
appPublic: resolveApp('public'),
appHtml: resolveApp('public/index.html'),
@@ -76,5 +76,5 @@ module.exports = {
appNodeModules: resolveApp('node_modules'),
nodePaths: nodePaths,
publicUrl: getPublicUrl(resolveApp('package.json')),
servedPath: getServedPath(resolveApp('package.json'))
servedPath: getServedPath(resolveApp('package.json')),
};
Oops, something went wrong.

0 comments on commit 5d42b2a

Please sign in to comment.