Skip to content

Instantly share code, notes, and snippets.

@shimmerjs
Last active March 31, 2019 22:34
Show Gist options
  • Save shimmerjs/d1925091e0a7e124ff055979d6557187 to your computer and use it in GitHub Desktop.
Save shimmerjs/d1925091e0a7e124ff055979d6557187 to your computer and use it in GitHub Desktop.
godpack
yarn run v1.15.2
$ /Users/shimmerjs/code/tmp/node_modules/.bin/webpack --config-register tsconfig-paths/register --config-name packages
Hash: 873bf5d0da749619fb00
Version: webpack 4.29.6
Time: 3423ms
Built at: 03/31/2019 6:11:04 PM
Asset Size Chunks Chunk Names
@bcs-infra/cli-logger.js 270 KiB @bcs-infra/cli-logger [emitted] @bcs-infra/cli-logger
@bcs-infra/config.js 910 KiB @bcs-infra/config [emitted] @bcs-infra/config
@bcs-infra/logger.js 2.2 MiB @bcs-infra/logger [emitted] @bcs-infra/logger
@bcs-infra/request-logger.js 3.72 MiB @bcs-infra/request-logger [emitted] @bcs-infra/request-logger
@bcs-infra/utils.js 150 KiB @bcs-infra/utils [emitted] @bcs-infra/utils
Entrypoint @bcs-infra/cli-logger = @bcs-infra/cli-logger.js
Entrypoint @bcs-infra/config = @bcs-infra/config.js
Entrypoint @bcs-infra/logger = @bcs-infra/logger.js
Entrypoint @bcs-infra/request-logger = @bcs-infra/request-logger.js
Entrypoint @bcs-infra/utils = @bcs-infra/utils.js
[./packages/cli-logger/index.ts] 180 bytes {@bcs-infra/cli-logger} [built]
[./packages/config/base.ts] 690 bytes {@bcs-infra/config} {@bcs-infra/logger} {@bcs-infra/request-logger} [built]
[./packages/config/constants.ts] 691 bytes {@bcs-infra/config} {@bcs-infra/logger} {@bcs-infra/request-logger} [built]
[./packages/config/github.ts] 742 bytes {@bcs-infra/config} {@bcs-infra/logger} {@bcs-infra/request-logger} [built]
[./packages/config/index.ts] 329 bytes {@bcs-infra/config} {@bcs-infra/logger} {@bcs-infra/request-logger} [built]
[./packages/config/server.ts] 365 bytes {@bcs-infra/config} {@bcs-infra/logger} {@bcs-infra/request-logger} [built]
[./packages/config/vault.ts] 665 bytes {@bcs-infra/config} {@bcs-infra/logger} {@bcs-infra/request-logger} [built]
[./packages/logger/decorator.ts] 3.17 KiB {@bcs-infra/logger} {@bcs-infra/request-logger} [built]
[./packages/logger/index.ts] 340 bytes {@bcs-infra/logger} {@bcs-infra/request-logger} [built]
[./packages/logger/logger.ts] 1000 bytes {@bcs-infra/logger} {@bcs-infra/request-logger} [built]
[./packages/logger/stream.ts] 375 bytes {@bcs-infra/logger} {@bcs-infra/request-logger} [built]
[./packages/request-logger/index.ts] 163 bytes {@bcs-infra/request-logger} [built]
[./packages/request-logger/logger.ts] 2.68 KiB {@bcs-infra/request-logger} [built]
[./packages/utils/colors.ts] 1.99 KiB {@bcs-infra/logger} {@bcs-infra/request-logger} {@bcs-infra/utils} [built]
[./packages/utils/index.ts] 390 bytes {@bcs-infra/utils} {@bcs-infra/logger} {@bcs-infra/request-logger} [built]
+ 322 hidden modules
Done in 6.14s.
yarn run v1.15.2
$ /Users/shimmerjs/code/tmp/node_modules/.bin/webpack --config-register tsconfig-paths/register --config-name services
Hash: 027afec47db3e6eed8d7
Version: webpack 4.29.6
Time: 3476ms
Built at: 03/31/2019 6:11:31 PM
Asset Size Chunks Chunk Names
services/overseer/dist/index.js 5.36 MiB @bcs-infra/overseer [emitted] @bcs-infra/overseer
Entrypoint @bcs-infra/overseer = services/overseer/dist/index.js
[./packages/config/base.ts] 690 bytes {@bcs-infra/overseer} [built]
[./packages/config/constants.ts] 691 bytes {@bcs-infra/overseer} [built]
[./packages/config/github.ts] 742 bytes {@bcs-infra/overseer} [built]
[./packages/config/index.ts] 329 bytes {@bcs-infra/overseer} [built]
[./packages/config/server.ts] 365 bytes {@bcs-infra/overseer} [built]
[./packages/config/vault.ts] 665 bytes {@bcs-infra/overseer} [built]
[./packages/logger/decorator.ts] 3.17 KiB {@bcs-infra/overseer} [built]
[./packages/logger/index.ts] 340 bytes {@bcs-infra/overseer} [built]
[./packages/logger/logger.ts] 1000 bytes {@bcs-infra/overseer} [built]
[./packages/logger/stream.ts] 375 bytes {@bcs-infra/overseer} [built]
[./packages/request-logger/index.ts] 163 bytes {@bcs-infra/overseer} [built]
[./packages/request-logger/logger.ts] 2.68 KiB {@bcs-infra/overseer} [built]
[./services/overseer/index.ts] 1.39 KiB {@bcs-infra/overseer} [built]
[./services/overseer/routes/health.ts] 476 bytes {@bcs-infra/overseer} [built]
[./services/overseer/routes/metrics.ts] 658 bytes {@bcs-infra/overseer} [built]
+ 433 hidden modules
Done in 6.21s.
yarn run v1.15.2
$ /Users/shimmerjs/code/tmp/node_modules/.bin/webpack --config-register tsconfig-paths/register
Hash: 027afec47db3e6eed8d7873bf5d0da749619fb00
Version: webpack 4.29.6
Child services:
Hash: 027afec47db3e6eed8d7
Time: 6080ms
Built at: 03/31/2019 6:09:56 PM
Asset Size Chunks Chunk Names
services/overseer/dist/index.js 5.36 MiB @bcs-infra/overseer [emitted] @bcs-infra/overseer
Entrypoint @bcs-infra/overseer = services/overseer/dist/index.js
[./packages/config/base.ts] 690 bytes {@bcs-infra/overseer} [built]
[./packages/config/constants.ts] 691 bytes {@bcs-infra/overseer} [built]
[./packages/config/github.ts] 742 bytes {@bcs-infra/overseer} [built]
[./packages/config/index.ts] 329 bytes {@bcs-infra/overseer} [built]
[./packages/config/server.ts] 365 bytes {@bcs-infra/overseer} [built]
[./packages/config/vault.ts] 665 bytes {@bcs-infra/overseer} [built]
[./packages/logger/decorator.ts] 3.17 KiB {@bcs-infra/overseer} [built]
[./packages/logger/index.ts] 340 bytes {@bcs-infra/overseer} [built]
[./packages/logger/logger.ts] 1000 bytes {@bcs-infra/overseer} [built]
[./packages/logger/stream.ts] 375 bytes {@bcs-infra/overseer} [built]
[./packages/request-logger/index.ts] 163 bytes {@bcs-infra/overseer} [built]
[./packages/request-logger/logger.ts] 2.68 KiB {@bcs-infra/overseer} [built]
[./services/overseer/index.ts] 1.39 KiB {@bcs-infra/overseer} [built]
[./services/overseer/routes/health.ts] 476 bytes {@bcs-infra/overseer} [built]
[./services/overseer/routes/metrics.ts] 658 bytes {@bcs-infra/overseer} [built]
+ 433 hidden modules
Child packages:
Hash: 873bf5d0da749619fb00
Time: 6023ms
Built at: 03/31/2019 6:09:56 PM
Asset Size Chunks Chunk Names
@bcs-infra/cli-logger.js 270 KiB @bcs-infra/cli-logger [emitted] @bcs-infra/cli-logger
@bcs-infra/config.js 910 KiB @bcs-infra/config [emitted] @bcs-infra/config
@bcs-infra/logger.js 2.2 MiB @bcs-infra/logger [emitted] @bcs-infra/logger
@bcs-infra/request-logger.js 3.72 MiB @bcs-infra/request-logger [emitted] @bcs-infra/request-logger
@bcs-infra/utils.js 150 KiB @bcs-infra/utils [emitted] @bcs-infra/utils
Entrypoint @bcs-infra/cli-logger = @bcs-infra/cli-logger.js
Entrypoint @bcs-infra/config = @bcs-infra/config.js
Entrypoint @bcs-infra/logger = @bcs-infra/logger.js
Entrypoint @bcs-infra/request-logger = @bcs-infra/request-logger.js
Entrypoint @bcs-infra/utils = @bcs-infra/utils.js
[./packages/cli-logger/index.ts] 180 bytes {@bcs-infra/cli-logger} [built]
[./packages/config/base.ts] 690 bytes {@bcs-infra/config} {@bcs-infra/logger} {@bcs-infra/request-logger} [built]
[./packages/config/constants.ts] 691 bytes {@bcs-infra/config} {@bcs-infra/logger} {@bcs-infra/request-logger} [built]
[./packages/config/github.ts] 742 bytes {@bcs-infra/config} {@bcs-infra/logger} {@bcs-infra/request-logger} [built]
[./packages/config/index.ts] 329 bytes {@bcs-infra/config} {@bcs-infra/logger} {@bcs-infra/request-logger} [built]
[./packages/config/server.ts] 365 bytes {@bcs-infra/config} {@bcs-infra/logger} {@bcs-infra/request-logger} [built]
[./packages/config/vault.ts] 665 bytes {@bcs-infra/config} {@bcs-infra/logger} {@bcs-infra/request-logger} [built]
[./packages/logger/decorator.ts] 3.17 KiB {@bcs-infra/logger} {@bcs-infra/request-logger} [built]
[./packages/logger/index.ts] 340 bytes {@bcs-infra/logger} {@bcs-infra/request-logger} [built]
[./packages/logger/logger.ts] 1000 bytes {@bcs-infra/logger} {@bcs-infra/request-logger} [built]
[./packages/logger/stream.ts] 375 bytes {@bcs-infra/logger} {@bcs-infra/request-logger} [built]
[./packages/request-logger/index.ts] 163 bytes {@bcs-infra/request-logger} [built]
[./packages/request-logger/logger.ts] 2.68 KiB {@bcs-infra/request-logger} [built]
[./packages/utils/colors.ts] 1.99 KiB {@bcs-infra/logger} {@bcs-infra/request-logger} {@bcs-infra/utils} [built]
[./packages/utils/index.ts] 390 bytes {@bcs-infra/utils} {@bcs-infra/logger} {@bcs-infra/request-logger} [built]
+ 322 hidden modules
Done in 10.05s.
yarn run v1.15.2
$ /Users/shimmerjs/code/tmp/node_modules/.bin/webpack --config-register tsconfig-paths/register --env.ws=@bcs-infra/overseer
Hash: 027afec47db3e6eed8d7
Version: webpack 4.29.6
Child services:
Hash: 027afec47db3e6eed8d7
Time: 3541ms
Built at: 03/31/2019 6:10:21 PM
Asset Size Chunks Chunk Names
services/overseer/dist/index.js 5.36 MiB @bcs-infra/overseer [emitted] @bcs-infra/overseer
Entrypoint @bcs-infra/overseer = services/overseer/dist/index.js
[./packages/config/base.ts] 690 bytes {@bcs-infra/overseer} [built]
[./packages/config/constants.ts] 691 bytes {@bcs-infra/overseer} [built]
[./packages/config/github.ts] 742 bytes {@bcs-infra/overseer} [built]
[./packages/config/index.ts] 329 bytes {@bcs-infra/overseer} [built]
[./packages/config/server.ts] 365 bytes {@bcs-infra/overseer} [built]
[./packages/config/vault.ts] 665 bytes {@bcs-infra/overseer} [built]
[./packages/logger/decorator.ts] 3.17 KiB {@bcs-infra/overseer} [built]
[./packages/logger/index.ts] 340 bytes {@bcs-infra/overseer} [built]
[./packages/logger/logger.ts] 1000 bytes {@bcs-infra/overseer} [built]
[./packages/logger/stream.ts] 375 bytes {@bcs-infra/overseer} [built]
[./packages/request-logger/index.ts] 163 bytes {@bcs-infra/overseer} [built]
[./packages/request-logger/logger.ts] 2.68 KiB {@bcs-infra/overseer} [built]
[./services/overseer/index.ts] 1.39 KiB {@bcs-infra/overseer} [built]
[./services/overseer/routes/health.ts] 476 bytes {@bcs-infra/overseer} [built]
[./services/overseer/routes/metrics.ts] 658 bytes {@bcs-infra/overseer} [built]
+ 433 hidden modules
Done in 7.16s.
yarn run v1.15.2
$ /Users/shimmerjs/code/tmp/node_modules/.bin/webpack --config-register tsconfig-paths/register --env.ws=@bcs-infra/utils
Hash: eccbaf75578734625821
Version: webpack 4.29.6
Child packages:
Hash: eccbaf75578734625821
Time: 2010ms
Built at: 03/31/2019 6:10:36 PM
Asset Size Chunks Chunk Names
@bcs-infra/utils.js 150 KiB @bcs-infra/utils [emitted] @bcs-infra/utils
Entrypoint @bcs-infra/utils = @bcs-infra/utils.js
[./node_modules/webpack/buildin/module.js] (webpack)/buildin/module.js 497 bytes {@bcs-infra/utils} [built]
[./packages/utils/colors.ts] 1.99 KiB {@bcs-infra/utils} [built]
[./packages/utils/hook.ts] 3.71 KiB {@bcs-infra/utils} [built]
[./packages/utils/index.ts] 390 bytes {@bcs-infra/utils} [built]
[child_process] external "child_process" 42 bytes {@bcs-infra/utils} [built]
[os] external "os" 42 bytes {@bcs-infra/utils} [built]
[util] external "util" 42 bytes {@bcs-infra/utils} [built]
+ 10 hidden modules
Done in 4.91s.
/**
* Project level `webpack` configuration that allows you to:
*
* - build all of a certain type of project (`clis`, `services`, `packages`).
* - build a specific workspace, e.g. `@bcs-infra/utils`
* - build all workspaces
*/
import { Configuration, ConfigurationFunc, Environment, coreConfig, generateEntrypoints } from './hack/webpack';
const isEmpty = (obj: any) => Object.keys(obj).length === 0;
// builds webpack configuration for the entire project
// will be exported as `module.exports` to be used by webpack CLI
const projectConfig: ConfigurationFunc = (env: Environment = {}, argv: any) => {
const core = coreConfig(env, argv);
const configs: Configuration[] = [];
// services bundling configuration
const svcConfig = Object.assign({}, core, {
name: 'services',
entry: generateEntrypoints('services', env.ws)
}) as Configuration;
// empty entry will cause webpack to fail
if (!isEmpty(svcConfig.entry)) configs.push(svcConfig);
// packages bundling configuration
const pkgConfig = Object.assign({}, core, {
name: 'packages',
entry: generateEntrypoints('packages', env.ws),
output: {
// universal module bundle
libraryTarget: 'umd',
// tell webpack to use the existing exports on each package
library: ''
}
}) as Configuration;
if (!isEmpty(pkgConfig.entry)) configs.push(pkgConfig);
return configs;
};
module.exports = projectConfig;
/**
* Base `webpack`configuration that is imported by specific webpack configs
* for bundling packages, CLIs, and services.
*/
import { resolve } from 'path';
import { TsconfigPathsPlugin } from 'tsconfig-paths-webpack-plugin/lib';
// @ts-ignore
import TerserPlugin from 'terser-webpack-plugin';
import { constants } from './hack/project-constants';
import { Entry } from 'webpack';
import { getWorkspacesSync } from './hack/yarn-workspace-utils';
import { logger } from 'packages/cli-logger';
import webpack = require('webpack');
// patch Output type cuz @types/webpack wrong
// `Output.filename` can be a function that returns a string:
// https://webpack.js.org/configuration/output#outputfilename
declare module patchedWebpack {
type FilenameFunc = (chunkData: any) => string;
interface Output {
filename: string | FilenameFunc;
}
interface Configuration {
// in our patched interface, we always have an output because it is
// present in our core configuration
output: Output;
}
}
// merge patch with imported module, then we can use our local patched types
// as if they were the original imported types
type Output = webpack.Output & patchedWebpack.Output;
type Configuration = webpack.Configuration & patchedWebpack.Configuration;
// we will use the workspace map so that when we set entry points and outputs
// we dont ever tightly couple the workspace name and its path
// we get it now to avoid multiple expensive calls by each config
const ws = getWorkspacesSync();
// convenience functions
const isProd = (argv: any) => argv.mode === 'production';
const exists = (name: string) => ws[name] !== undefined;
const isEmpty = (obj: any) => Object.keys(obj).length === 0;
// provide friendly error if user provides invalid workspace name
class InvalidWorkspaceError extends Error {
constructor(name: string) {
super();
logger.fatal(`${name} is an invalid workspace name`);
process.exit(1);
}
}
// types for building webpack configs, we dont include these in patches `webpack.Configuration`
// module because we don't want to pollute original interface with members that
// dont exist out of the box
// provide interface for options we pass to our config via `--env` webpack CLI flag
// helps future developers know what env fields are used for other things
// and provides some validation
interface Environment {
ws?: string;
}
// provide type for our top-level functions that generate configuration
type ConfigurationFunc = (env: Environment, argv: any) => (Configuration | Configuration[]);
/**
* Performs naive filter of workspaces via `.indexOf()` on each location
* @param filter `string` the string to filter on
* @param name `string` individual workspace name passed in via webpack `--env`
*/
function generateEntrypoints(filter: string, name?: string): Entry {
// immediately check if its a valid workspace name, if one was provided
if (name) {
if (!exists(name)) throw new InvalidWorkspaceError(name);
}
const entry: any = {};
// first create a stripped down workspaces object based on filter name
// to avoid doing more work when iterating over entrypoints
const cws: any = {};
Object.keys(ws)
.filter(key => ws[key].location.includes(filter))
.forEach(key => cws[key] = ws[key]);
if (name) {
if (cws[name]) entry[name] = cws[name].location;
// return empty object if single workspace was provided that isnt valid
// for this config
return entry;
}
// if no workspace is given, return all valid entrypoints for a given config
Object.keys(cws)
.forEach(key => {
entry[key] = ws[key].location;
});
return entry;
}
const coreConfig: ConfigurationFunc = (env: Environment = {}, argv: any) => {
// provide const external to config so we can reference mode in building config
// rationale for default being development: easy to provide `--mode production`
// on actual production builds, but dev builds will be called much more frequently
const mode = argv.mode || 'development';
return {
mode,
// use this devtool based on webpack recommendation here:
// https://webpack.js.org/configuration/devtool/
devtool: isProd(mode) ? 'cheap-module-source-map' : 'inline-source-map',
// by default the config name (`packages`, `clis`, `services`) will filter
// the workspaces object
entry: {},
module: {
rules: [
{
test: /\.ts$/,
use: [
{
loader: 'ts-loader',
options: {
context: constants.paths.root,
configFile: constants.paths.tsconfig,
},
},
],
exclude: /node_modules|hack/
},
],
},
resolve: {
extensions: ['.ts', '.js', '.json'],
plugins: [
new TsconfigPathsPlugin({ configFile: constants.paths.tsconfig }),
],
modules: [
// explicitly set this even though we are at root in case anyone extends
// this configuration that is *not* at root
resolve(constants.paths.root, 'node_modules'),
'node_modules'
],
},
target: 'node',
node: {
__dirname: false,
},
output: {
path: constants.paths.root,
filename: (chunkData: any) => {
return `${ws[chunkData.chunk.name].location}/dist/index.js`;
}
} as Output,
// run terser in production
optimization: isProd(mode) ? {
minimizer: [
new TerserPlugin({
parallel: true,
sourceMap: true,
cache: true,
terserOptions: {
compress: false,
ecma: 8,
},
}),
]
} : {}
// cast it to our patched type
} as Configuration;
};
// builds webpack configuration for the entire project
// will be exported as `module.exports` to be used by webpack CLI
const projectConfig: ConfigurationFunc = (env: Environment = {}, argv: any) => {
const core = coreConfig(env, argv);
const configs: Configuration[] = [];
// services bundling configuration
const svcConfig = Object.assign({}, core, {
name: 'services',
entry: generateEntrypoints('services', env.ws)
}) as Configuration;
// empty entry will cause webpack to fail
if (!isEmpty(svcConfig.entry)) configs.push(svcConfig);
// packages bundling configuration
const pkgConfig = Object.assign({}, core, {
name: 'packages',
entry: generateEntrypoints('packages', env.ws),
output: {
// universal module bundle
libraryTarget: 'umd',
// tell webpack to use the existing exports on each package
library: ''
}
}) as Configuration;
if (!isEmpty(pkgConfig.entry)) configs.push(pkgConfig);
return configs;
};
module.exports = projectConfig;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment