Skip to content

Commit

Permalink
remove caching from build configuration and update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
bsokol-wl committed Mar 25, 2024
1 parent b291a4a commit 49b39c6
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 113 deletions.
37 changes: 0 additions & 37 deletions docs/webpack/configure-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,43 +203,6 @@ export default defineBuildConfig(swcConfig, {
});
```

### `cache`

- **Type**: `boolean`
- **Default**: `true`

Whether or not webpack [filesystem cache](https://webpack.js.org/configuration/cache/) is enabled.

```js !#7 webpack.build.js
// @ts-check

import { defineDevConfig } from "@workleap/webpack-configs";
import { swcConfig } from "./swc.build.js";

export default defineBuildConfig(swcConfig, {
cache: false
});
```

### `cacheDirectory`

- **Type**: `string`
- **Default**: `node_modules/.cache/webpack`

```js !#8 webpack.build.js
// @ts-check

import { defineBuildConfig } from "@workleap/webpack-configs";
import { swcConfig } from "./swc.build.js";
import path from "path";

export default defineBuildConfig(swcConfig, {
cacheDirectory: path.resolve("./custom-webpack-cache")
});
```

Set webpack [cacheDirectory option](https://webpack.js.org/configuration/cache/#cachecachedirectory) when `cache` is enabled.

### `moduleRules`

- **Type**: An array of webpack [moduleRule](https://webpack.js.org/configuration/module/#modulerules) objects
Expand Down
21 changes: 1 addition & 20 deletions docs/webpack/configure-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export default defineDevConfig(swcConfig, {
- **Type**: `boolean`
- **Default**: `true`

Whether or not webpack [filesystem cache](https://webpack.js.org/configuration/cache/) is enabled.
Whether or not webpack [memory cache](https://webpack.js.org/configuration/cache/#cache) is enabled. This will also set [maxGenerations](https://webpack.js.org/configuration/cache/#cachemaxgenerations) to 1 to remove cache entries from memory when they are no longer needed.

```js !#7 webpack.dev.js
// @ts-check
Expand All @@ -257,25 +257,6 @@ export default defineDevConfig(swcConfig, {
});
```

### `cacheDirectory`

- **Type**: `string`
- **Default**: `node_modules/.cache/webpack`

```js !#8 webpack.dev.js
// @ts-check

import { defineDevConfig } from "@workleap/webpack-configs";
import { swcConfig } from "./swc.dev.js";
import path from "path";

export default defineDevConfig(swcConfig, {
cacheDirectory: path.resolve("./custom-webpack-cache")
});
```

Set webpack [cacheDirectory option](https://webpack.js.org/configuration/cache/#cachecachedirectory) when `cache` is enabled.

### `moduleRules`

- **Type**: An array of webpack [moduleRule](https://webpack.js.org/configuration/module/#modulerules) objects
Expand Down
40 changes: 1 addition & 39 deletions packages/webpack-configs/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import HtmlWebpackPlugin from "html-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import { createRequire } from "node:module";
import path from "node:path";
import { fileURLToPath } from "node:url";
import TerserPlugin from "terser-webpack-plugin";
import type { Configuration as WebpackConfig } from "webpack";
import webpack from "webpack";
Expand All @@ -19,9 +18,6 @@ const DefinePlugin = webpack.DefinePlugin;
// is available
const require = createRequire(import.meta.url);

// The equivalent of __filename for CommonJS.
const __filename = fileURLToPath(import.meta.url);

export function defineBuildHtmlWebpackPluginConfig(options: HtmlWebpackPlugin.Options = {}): HtmlWebpackPlugin.Options {
const {
template = path.resolve("./public/index.html"),
Expand Down Expand Up @@ -107,8 +103,6 @@ export interface DefineBuildConfigOptions {
entry?: string;
outputPath?: string;
publicPath?: `${string}/` | "auto";
cache?: boolean;
cacheDirectory?: string;
moduleRules?: NonNullable<WebpackConfig["module"]>["rules"];
plugins?: WebpackConfig["plugins"];
htmlWebpackPlugin?: boolean | HtmlWebpackPlugin.Options;
Expand All @@ -127,8 +121,6 @@ export function defineBuildConfig(swcConfig: SwcConfig, options: DefineBuildConf
outputPath = path.resolve("dist"),
// The trailing / is very important, otherwise paths will not be resolved correctly.
publicPath = "http://localhost:8080/",
cache = true,
cacheDirectory = path.resolve("node_modules/.cache/webpack"),
moduleRules = [],
plugins = [],
htmlWebpackPlugin = defineBuildHtmlWebpackPluginConfig(),
Expand All @@ -153,37 +145,7 @@ export function defineBuildConfig(swcConfig: SwcConfig, options: DefineBuildConf
publicPath,
clean: true
},
cache: cache && {
type: "filesystem",
allowCollectingMemory: false,
cacheDirectory: cacheDirectory,
maxMemoryGenerations: 1,
// Took from https://webpack.js.org/configuration/cache/#cachebuilddependencies.
buildDependencies: {
config: [__filename]
}
},
// (ACTUALLY NOT FIXING ANYTHING AT THE MOMENT)
// Fixes caching for environmental variables using the DefinePlugin by forcing
// webpack caching to prioritize hashes over timestamps.
snapshot: cache ? {
buildDependencies: {
hash: true,
timestamp: true
},
module: {
hash: true,
timestamp: true
},
resolve: {
hash: true,
timestamp: true
},
resolveBuildDependencies: {
hash: true,
timestamp: true
}
} : undefined,
cache: false,
optimization: getOptimizationConfig(optimize),
infrastructureLogging: verbose ? {
appendOnly: true,
Expand Down
17 changes: 0 additions & 17 deletions packages/webpack-configs/tests/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,23 +179,6 @@ test("when cache is enabled, the cache configuration is included", () => {
expect(result.cache).toBeDefined();
});

test("when cache is disabled, the cache prop is false", () => {
const result = defineBuildConfig(SwcConfig, {
cache: false
});

expect(result.cache).toBeFalsy();
});

test("when a cache directory is provided and cache is enabled, use the provided cache directory value", () => {
const result = defineBuildConfig(SwcConfig, {
cache: true,
cacheDirectory: "a-custom-path"
});

expect((result.cache as FileCacheOptions).cacheDirectory).toBe("a-custom-path");
});

test("when htmlWebpackPlugin is \"false\", no html-webpack-plugin instance is added to the plugin array", () => {
const config = defineBuildConfig(SwcConfig, {
htmlWebpackPlugin: false
Expand Down

0 comments on commit 49b39c6

Please sign in to comment.