Skip to content

Commit

Permalink
Merge #1877
Browse files Browse the repository at this point in the history
1877: feat(webpack): enable filesystem-based caching r=herschel666 a=herschel666

#### Production build of `packages/spec/integration/react`…

- with cold webpack cache: ~6.3s
- with warm webpack cache: ~2.3s

<details>
<summary>Bors merge bot cheat sheet</summary>

We are using [bors-ng](https://github.com/bors-ng/bors-ng) to automate merging of our pull requests. The following table provides a summary of commands that are available to reviewers (members of this repository with push access) and delegates (in case of `bors delegate+` or `bors delegate=[list]`).

| Syntax | Description |
| --- | --- |
| bors merge | Run the test suite and push to master if it passes. Short for "reviewed: looks good." |
| bors merge- | Cancel an r+, r=, merge, or merge= |
| bors try | Run the test suite without pushing to master. |
| bors try- | Cancel a try |
| bors delegate+ | Allow the pull request author to merge their changes. |
| bors delegate=[list] | Allow the listed users to r+ this pull request's changes. |
| bors retry | Run the previous command a second time. |

This is a short collection of opinionated commands. For a full list of the commands read the [bors reference](https://bors.tech/documentation/).

</details>


Co-authored-by: Emanuel Kluge <[email protected]>
  • Loading branch information
bors[bot] and Emanuel Kluge authored Jun 21, 2021
2 parents 5a92bc5 + 233ea89 commit c90d97e
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ exports.initialize = function initialize(overrides = {}, ...args) {
return define(strategies, mixins)(config, ...args);
};

exports.internal = { getConfig, ...require('./lib/utils') };
exports.internal = { getConfig, getMixins, ...require('./lib/utils') };
1 change: 1 addition & 0 deletions packages/webpack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,4 @@ Available tags for the [`debug`](https://www.npmjs.com/package/debug)-module are
- `hops:webpack:config:build`
- `hops:webpack:config:develop`
- `hops:webpack:config:node`
- `hops:webpack:dependencies`
14 changes: 11 additions & 3 deletions packages/webpack/lib/configs/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const getModules = require('../utils/modules');

const { HashedModuleIdsPlugin, NamedModuleIdsPlugin } = ids;

module.exports = function getConfig(config, name) {
module.exports = function getConfig(config, name, buildDependencies) {
const getAssetPath = (...arg) => trimSlashes(join(config.assetPath, ...arg));
const isProduction = process.env.NODE_ENV === 'production';

Expand Down Expand Up @@ -92,9 +92,17 @@ module.exports = function getConfig(config, name) {
devtoolModuleFilenameTemplate: (info) =>
relative(config.rootDir, info.absoluteResourcePath),
},
// fixme
cache: {
type: 'memory',
type: 'filesystem',
buildDependencies: {
config: [__filename].concat(buildDependencies),
},
},
snapshot: {
buildDependencies: {
hash: true,
timestamp: false,
},
},
resolve: {
modules: getModules(config.rootDir),
Expand Down
14 changes: 11 additions & 3 deletions packages/webpack/lib/configs/develop.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {
const { join, trimSlashes } = require('pathifist');
const getModules = require('../utils/modules');

module.exports = function getConfig(config, name) {
module.exports = function getConfig(config, name, buildDependencies) {
const getAssetPath = (...arg) => trimSlashes(join(config.assetPath, ...arg));

const jsLoaderConfig = {
Expand Down Expand Up @@ -91,9 +91,17 @@ module.exports = function getConfig(config, name) {
devtoolModuleFilenameTemplate: (info) =>
relative(config.rootDir, info.absoluteResourcePath),
},
// fixme
cache: {
type: 'memory',
type: 'filesystem',
buildDependencies: {
config: [__filename].concat(buildDependencies),
},
},
snapshot: {
buildDependencies: {
hash: false,
timestamp: true,
},
},
resolve: {
modules: getModules(config.rootDir),
Expand Down
14 changes: 11 additions & 3 deletions packages/webpack/lib/configs/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const getModules = require('../utils/modules');
const { LimitChunkCountPlugin } = optimize;
const { HashedModuleIdsPlugin, NamedModuleIdsPlugin } = ids;

module.exports = function getConfig(config, name) {
module.exports = function getConfig(config, name, buildDependencies) {
const getAssetPath = (...arg) => trimSlashes(join(config.assetPath, ...arg));
const isProduction = process.env.NODE_ENV === 'production';

Expand Down Expand Up @@ -118,9 +118,17 @@ module.exports = function getConfig(config, name) {
devtoolModuleFilenameTemplate: (info) =>
resolve(info.absoluteResourcePath),
},
// fixme
cache: {
type: 'memory',
type: 'filesystem',
buildDependencies: {
config: [__filename].concat(buildDependencies),
},
},
snapshot: {
buildDependencies: {
hash: true,
timestamp: !isProduction,
},
},
resolve: {
modules: getModules(config.rootDir),
Expand Down
35 changes: 32 additions & 3 deletions packages/webpack/mixins/config/mixin.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,45 @@ const { validate, invariant } = bootstrap;
const debugConfig = (target, config) =>
debug(`hops:webpack:config:${target}`)(config);

const collectWebpackBuildDependencies = (config) => {
const buildDependencies = bootstrap
.getMixins(config)
.reduce((acc, mixin, i) => {
if (typeof mixin.prototype.configureBuild === 'function') {
acc.push(config._mixins.core[i]);
}
return acc;
}, []);

debug('hops:webpack:dependencies')(buildDependencies);

return buildDependencies;
};

class WebpackConfigMixin extends Mixin {
getBuildConfig(target, baseConfig) {
const { loaderConfigs = {}, ...webpackConfig } = (() => {
const buildDependencies = collectWebpackBuildDependencies(this.config);

switch (baseConfig || target) {
case 'build':
return require('../../lib/configs/build')(this.config, target);
return require('../../lib/configs/build')(
this.config,
target,
buildDependencies
);
case 'develop':
return require('../../lib/configs/develop')(this.config, target);
return require('../../lib/configs/develop')(
this.config,
target,
buildDependencies
);
case 'node':
return require('../../lib/configs/node')(this.config, target);
return require('../../lib/configs/node')(
this.config,
target,
buildDependencies
);
default:
if (baseConfig && exists(baseConfig)) {
return require(baseConfig)(this.config, target);
Expand Down

0 comments on commit c90d97e

Please sign in to comment.