Skip to content
This repository has been archived by the owner on Jul 24, 2019. It is now read-only.

Commit

Permalink
Add Beamery configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmckeb committed Dec 21, 2018
1 parent f3bb6fb commit 0e53136
Show file tree
Hide file tree
Showing 46 changed files with 653 additions and 218 deletions.
6 changes: 6 additions & 0 deletions config/beamery/jest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

var enzyme = require('enzyme');
var Adapter = require('enzyme-adapter-react-16');

enzyme.configure({ adapter: new Adapter() });
32 changes: 32 additions & 0 deletions config/beamery/paths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

const ENVS = {
DEVELOPMENT: 'development',
PRODUCTION: 'production',
STAGING: 'staging',
INDEPENDENT: 'independent',
};

const paths = {
buildPath: 'dist',
publicPath: false,
appIndexJs: 'src/index.full',
};

switch (process.env.BMR_ENV) {
case ENVS.PRODUCTION:
paths.publicPath = 'https://storage.googleapis.com/beamery/';
break;
case ENVS.STAGING:
paths.buildPath = '../app-bath/dist';
break;
case ENVS.DEVELOPMENT:
paths.buildPath = '../app-bath/dev';
break;
case ENVS.INDEPENDENT:
default:
paths.appIndexJs = 'src/index';
break;
}

module.exports = paths;
16 changes: 16 additions & 0 deletions config/beamery/prefixes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

const paths = require('../paths');
const appPackageJson = require(paths.appPackageJson);

// Use the `package.json` app name to simplify setup.
const appName = appPackageJson.name;
process.env.BMR_APP_NAME = appName;

module.exports = {
// Webpack allows us to define a path in sources. This can be useful for
// debugging against other applications.
devtoolRoot: appName ? appName + ':///' : '',
// This prefix is not used for `independent` builds.
filenamePrefix: appName ? appName : 'APP-NAME-UNDEFINED',
};
1 change: 1 addition & 0 deletions config/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function getClientEnvironment(publicUrl) {
// 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,
APP_NAME: process.env.BMR_APP_NAME,
}
);
// Stringify all values so we can feed into Webpack DefinePlugin
Expand Down
13 changes: 8 additions & 5 deletions config/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
const path = require('path');
const fs = require('fs');
const url = require('url');
const beameryPaths = require('./beamery/paths');

// Make sure any symlinks in the project folder are resolved:
// https://github.com/facebook/create-react-app/issues/637
Expand Down Expand Up @@ -42,7 +43,9 @@ const getPublicUrl = appPackageJson =>
function getServedPath(appPackageJson) {
const publicUrl = getPublicUrl(appPackageJson);
const servedUrl =
envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/');
beameryPaths.publicPath ||
envPublicUrl ||
(publicUrl ? url.parse(publicUrl).pathname : '/');
return ensureSlash(servedUrl, true);
}

Expand Down Expand Up @@ -77,10 +80,10 @@ const resolveModule = (resolveFn, filePath) => {
module.exports = {
dotenv: resolveApp('.env'),
appPath: resolveApp('.'),
appBuild: resolveApp('build'),
appBuild: resolveApp(beameryPaths.buildPath),
appPublic: resolveApp('public'),
appHtml: resolveApp('public/index.html'),
appIndexJs: resolveModule(resolveApp, 'src/index'),
appIndexJs: resolveModule(resolveApp, beameryPaths.appIndexJs),
appPackageJson: resolveApp('package.json'),
appSrc: resolveApp('src'),
appTsConfig: resolveApp('tsconfig.json'),
Expand All @@ -99,10 +102,10 @@ const resolveOwn = relativePath => path.resolve(__dirname, '..', relativePath);
module.exports = {
dotenv: resolveApp('.env'),
appPath: resolveApp('.'),
appBuild: resolveApp('build'),
appBuild: resolveApp(beameryPaths.buildPath),
appPublic: resolveApp('public'),
appHtml: resolveApp('public/index.html'),
appIndexJs: resolveModule(resolveApp, 'src/index'),
appIndexJs: resolveModule(resolveApp, beameryPaths.appIndexJs),
appPackageJson: resolveApp('package.json'),
appSrc: resolveApp('src'),
appTsConfig: resolveApp('tsconfig.json'),
Expand Down
101 changes: 55 additions & 46 deletions config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ const resolve = require('resolve');
const PnpWebpackPlugin = require('pnp-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
const InlineChunkHtmlPlugin = require('react-dev-utils/InlineChunkHtmlPlugin');
// const InlineChunkHtmlPlugin = require('react-dev-utils/InlineChunkHtmlPlugin');
const TerserPlugin = require('terser-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
// const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const safePostCssParser = require('postcss-safe-parser');
const ManifestPlugin = require('webpack-manifest-plugin');
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
const WorkboxWebpackPlugin = require('workbox-webpack-plugin');
// const ManifestPlugin = require('webpack-manifest-plugin');
// const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
// const WorkboxWebpackPlugin = require('workbox-webpack-plugin');
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent');
Expand All @@ -34,12 +34,13 @@ const typescriptFormatter = require('react-dev-utils/typescriptFormatter');
// @remove-on-eject-begin
const getCacheIdentifier = require('react-dev-utils/getCacheIdentifier');
// @remove-on-eject-end
const beameryConfig = require('./beamery/prefixes');

// Source maps are resource heavy and can cause out of memory issue for large source files.
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
// Some apps do not need the benefits of saving a web request, so not inlining the chunk
// makes for a smoother build process.
const shouldInlineRuntimeChunk = process.env.INLINE_RUNTIME_CHUNK !== 'false';
// const shouldInlineRuntimeChunk = process.env.INLINE_RUNTIME_CHUNK !== 'false';

// Check if TypeScript is setup
const useTypeScript = fs.existsSync(paths.appTsConfig);
Expand All @@ -64,7 +65,7 @@ module.exports = function(webpackEnv) {
: isEnvDevelopment && '/';
// 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 === './';
// const shouldUseRelativeAssetPaths = 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.
Expand All @@ -78,14 +79,15 @@ module.exports = function(webpackEnv) {
// common function to get style loaders
const getStyleLoaders = (cssOptions, preProcessor) => {
const loaders = [
isEnvDevelopment && require.resolve('style-loader'),
require.resolve('style-loader'),
/* isEnvDevelopment && require.resolve('style-loader'),
isEnvProduction && {
loader: MiniCssExtractPlugin.loader,
options: Object.assign(
{},
shouldUseRelativeAssetPaths ? { publicPath: '../../' } : undefined
),
},
}, */
{
loader: require.resolve('css-loader'),
options: cssOptions,
Expand Down Expand Up @@ -145,8 +147,8 @@ module.exports = function(webpackEnv) {
// 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'),
isEnvDevelopment &&
require.resolve('react-dev-utils/webpackHotDevClient'),
/* isEnvDevelopment &&
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
Expand All @@ -161,23 +163,29 @@ module.exports = function(webpackEnv) {
// There will be one main bundle, and one file per asynchronous chunk.
// In development, it does not produce real files.
filename: isEnvProduction
? 'static/js/[name].[chunkhash:8].js'
: isEnvDevelopment && 'static/js/bundle.js',
? `${beameryConfig.filenamePrefix}.[name]${
process.env.BMR_ENV === 'development' ? '' : '.[chunkhash:8]'
}.bundle.js`
: isEnvDevelopment && `${beameryConfig.filenamePrefix}.bundle.js`,
// There are also additional JS chunk files if you use code splitting.
chunkFilename: isEnvProduction
? 'static/js/[name].[chunkhash:8].chunk.js'
: isEnvDevelopment && 'static/js/[name].chunk.js',
/* chunkFilename: isEnvProduction
? `static/js/[name].[chunkhash:8].chunk.js`
: isEnvDevelopment &&
`static/js/[name].chunk.js`, */
// We inferred the "public path" (such as / or /my-project) from homepage.
// We use "/" in development.
publicPath: publicPath,
// Point sourcemap entries to original disk location (format as URL on Windows)
devtoolModuleFilenameTemplate: isEnvProduction
? info =>
beameryConfig.devtoolRoot +
path
.relative(paths.appSrc, info.absoluteResourcePath)
.replace(/\\/g, '/')
: isEnvDevelopment &&
(info => path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')),
(info =>
beameryConfig.devtoolRoot +
path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')),
},
optimization: {
minimize: isEnvProduction,
Expand Down Expand Up @@ -245,13 +253,13 @@ module.exports = function(webpackEnv) {
// Automatically split vendor and commons
// https://twitter.com/wSokra/status/969633336732905474
// https://medium.com/webpack/webpack-4-code-splitting-chunk-graph-and-the-splitchunks-optimization-be739a861366
splitChunks: {
/* splitChunks: {
chunks: 'all',
name: false,
},
}, */
// Keep the runtime chunk seperated to enable long term caching
// https://twitter.com/wSokra/status/969679223278505985
runtimeChunk: true,
// runtimeChunk: true,
},
resolve: {
// This allows you to set a fallback for where Webpack should look for modules.
Expand Down Expand Up @@ -334,11 +342,11 @@ module.exports = function(webpackEnv) {
// 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$/],
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/, /\.svg$/],
loader: require.resolve('url-loader'),
options: {
limit: 10000,
name: 'static/media/[name].[hash:8].[ext]',
// limit: 10000,
name: `static/media/[name].[hash:8].[ext]`,
},
},
// Process application JS with Babel.
Expand Down Expand Up @@ -508,7 +516,7 @@ module.exports = function(webpackEnv) {
// by webpacks internal loaders.
exclude: [/\.(js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/],
options: {
name: 'static/media/[name].[hash:8].[ext]',
name: `static/media/[name].[hash:8].[ext]`,
},
},
// ** STOP ** Are you adding a new loader?
Expand All @@ -519,14 +527,15 @@ module.exports = function(webpackEnv) {
},
plugins: [
// Generates an `index.html` file with the <script> injected.
new HtmlWebpackPlugin(
Object.assign(
{},
{
inject: true,
template: paths.appHtml,
},
isEnvProduction
isEnvDevelopment &&
new HtmlWebpackPlugin(
Object.assign(
{},
{
inject: true,
template: paths.appHtml,
}
/* isEnvProduction
? {
minify: {
removeComments: true,
Expand All @@ -541,21 +550,21 @@ module.exports = function(webpackEnv) {
minifyURLs: true,
},
}
: undefined
)
),
: undefined */
)
),
// Inlines the webpack runtime script. This script is too small to warrant
// a network request.
isEnvProduction &&
/* isEnvProduction &&
shouldInlineRuntimeChunk &&
new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/runtime~.+[.]js/]),
new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/runtime~.+[.]js/]), */
// 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 production, it will be an empty string unless you specify "homepage"
// in `package.json`, in which case it will be the pathname of that URL.
// In development, this will be an empty string.
new InterpolateHtmlPlugin(HtmlWebpackPlugin, env.raw),
// new InterpolateHtmlPlugin(HtmlWebpackPlugin, env.raw),
// This gives some necessary context to module not found errors, such as
// the requesting resource.
new ModuleNotFoundPlugin(paths.appPath),
Expand All @@ -577,20 +586,20 @@ module.exports = function(webpackEnv) {
// See https://github.com/facebook/create-react-app/issues/186
isEnvDevelopment &&
new WatchMissingNodeModulesPlugin(paths.appNodeModules),
isEnvProduction &&
/* isEnvProduction &&
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: 'static/css/[name].[contenthash:8].css',
chunkFilename: 'static/css/[name].[contenthash:8].chunk.css',
}),
filename: `static/css/[name].[contenthash:8].css`,
chunkFilename: `static/css/[name].[contenthash:8].chunk.css`,
}), */
// Generate a manifest file which contains a mapping of all asset filenames
// to their corresponding output file so that tools can pick it up without
// having to parse `index.html`.
new ManifestPlugin({
/* new ManifestPlugin({
fileName: 'asset-manifest.json',
publicPath: publicPath,
}),
}), */
// 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.
Expand All @@ -599,7 +608,7 @@ module.exports = function(webpackEnv) {
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
// Generate a service worker script that will precache, and keep up to date,
// the HTML & assets that are part of the Webpack build.
isEnvProduction &&
/* isEnvProduction &&
new WorkboxWebpackPlugin.GenerateSW({
clientsClaim: true,
exclude: [/\.map$/, /asset-manifest\.json$/],
Expand All @@ -612,7 +621,7 @@ module.exports = function(webpackEnv) {
// public/ and not a SPA route
new RegExp('/[^/]+\\.[^/]+$'),
],
}),
}), */
// TypeScript type checking
useTypeScript &&
new ForkTsCheckerWebpackPlugin({
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "react-scripts",
"name": "bmr-react-scripts",
"version": "2.1.1",
"description": "Configuration and scripts for Create React App.",
"repository": "facebook/create-react-app",
"repository": "SeedJobs/create-react-app",
"license": "MIT",
"engines": {
"node": ">=6"
},
"bugs": {
"url": "https://github.com/facebook/create-react-app/issues"
"url": "https://github.com/SeedJobs/create-react-app/issues"
},
"files": [
"bin",
Expand Down
Loading

0 comments on commit 0e53136

Please sign in to comment.