Skip to content

Commit

Permalink
refactor: replace cache-loader with persistent cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Weber committed May 26, 2021
1 parent 8469bc2 commit 61f30a2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 62 deletions.
9 changes: 9 additions & 0 deletions packages/@averjs/renderer/lib/config/base.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import path from 'path';
import webpack, { Configuration } from 'webpack';
import WebpackChain from 'webpack-chain';
import { VueLoaderPlugin } from 'vue-loader';
Expand Down Expand Up @@ -261,6 +262,14 @@ export default class WebpackBaseConfiguration {
this.optimization();
this.plugins();

this.chainConfig.cache({
type: 'filesystem',
cacheLocation: path.resolve(
this.cacheDir,
this.isServer ? '../webpack/server' : '../webpack/client'
)
});

if (typeof this.webpackConfig?.base === 'function')
this.webpackConfig.base(this.chainConfig);

Expand Down
28 changes: 14 additions & 14 deletions packages/@averjs/renderer/lib/utils/perf-loader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from 'path';
// import path from 'path';
import { warmup } from 'thread-loader';
import { Module, Rule } from 'webpack-chain';
import { AverWebpackConfig, InternalAverConfig } from '@averjs/config';
Expand Down Expand Up @@ -65,19 +65,19 @@ export default class PerformanceLoader {
apply(rule: Rule<Rule | Module>, name: string) {
const pool = this.pools[name];
if (pool) {
rule
.use('cache-loader')
.loader('cache-loader')
.options({
cacheDirectory: path.resolve(
process.env.PROJECT_PATH,
`../node_modules/.cache/cache-loader/${
this.isServer ? 'server' : 'client'
}/${name}`
),
cacheIdentifier: name
})
.end();
// rule
// .use('cache-loader')
// .loader('cache-loader')
// .options({
// cacheDirectory: path.resolve(
// process.env.PROJECT_PATH,
// `../node_modules/.cache/cache-loader/${
// this.isServer ? 'server' : 'client'
// }/${name}`
// ),
// cacheIdentifier: name
// })
// .end();

/* istanbul ignore if */
if (pool.useThread && process.env.NODE_ENV !== 'test') {
Expand Down
1 change: 0 additions & 1 deletion packages/@averjs/renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"@averjs/webpack-hot-middleware": "^3.0.1",
"@kazupon/vue-i18n-loader": "^0.5.0",
"babel-loader": "^8.2.2",
"cache-loader": "^4.1.0",
"chalk": "^4.1.1",
"copy-webpack-plugin": "^8.1.1",
"css-loader": "^5.2.4",
Expand Down
20 changes: 3 additions & 17 deletions packages/@averjs/typescript/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,10 @@ const plugin: PluginFunction = async function (
) {
const { tsLoaderOptions, forkTsCheckerOptions } = await mergeOptions(options);

const setLoader = (chain: Config, isServer: boolean): void => {
const name = 'ts';

const setLoader = (chain: Config): void => {
chain.module
.rule('ts-loader')
.test(/\.tsx?$/)
.use('cache-loader')
.loader('cache-loader')
.options({
cacheDirectory: path.resolve(
process.env.PROJECT_PATH,
`../node_modules/.cache/cache-loader/${
isServer ? 'server' : 'client'
}/${name}`
),
cacheIdentifier: name
})
.end()
.use('thread-loader')
.loader('thread-loader')
.options({
Expand Down Expand Up @@ -124,11 +110,11 @@ const plugin: PluginFunction = async function (
}

this.aver.tap('renderer:client-config', (chain) => {
setLoader(chain, false);
setLoader(chain);
});

this.aver.tap('renderer:server-config', (chain) => {
setLoader(chain, true);
setLoader(chain);
});

this.aver.tap('renderer:base-config', (chain) => {
Expand Down
38 changes: 8 additions & 30 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
resolved "https://registry.yarnpkg.com/@averjs/vuex-decorators/-/vuex-decorators-3.3.0.tgz#8ecce1fd6b0fc879f69822e74702ca76f4c4ce36"
integrity sha512-jOJPKU405AoNXleq0gVniZXnBlA/I4MZ27nl0suQ5y9mKNT/pRIidkG70c5YAkoOnz9eAO73AE0IxsFv42Gefw==

"@averjs/webpack-hot-middleware@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@averjs/webpack-hot-middleware/-/webpack-hot-middleware-3.0.0.tgz#e3e9455a94c2330cbf654e62a152cb8244f6023d"
integrity sha512-yAR+hly+c0+Pp5f+E8N6rOQzLgDRqPbUVylPpr5dqlXB5Fl/VN8bvHzHr8wwZgkpUMY/LMdsMFTCmpDe9mJHRQ==
"@averjs/webpack-hot-middleware@^3.0.1":
version "3.0.1"
resolved "https://registry.yarnpkg.com/@averjs/webpack-hot-middleware/-/webpack-hot-middleware-3.0.1.tgz#23091d1a7a2c27ffb72d4761a0b085a548ea0548"
integrity sha512-JO7OZBN77yq2RcjaDWR6eHDaBj4nj3iIrUdrdisrFaBDX//nxfYVcN6HVWppoAH2Scl6QJin3KYKMOb5/flRnA==
dependencies:
ansi-html "0.0.7"
html-entities "^2.1.0"
Expand Down Expand Up @@ -3023,11 +3023,6 @@
"@types/connect" "*"
"@types/webpack" "^4"

"@types/webpack-env@^1.16.0":
version "1.16.0"
resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.16.0.tgz#8c0a9435dfa7b3b1be76562f3070efb3f92637b4"
integrity sha512-Fx+NpfOO0CpeYX2g9bkvX8O5qh9wrU1sOF4g8sft4Mu7z+qfe387YlyY8w8daDyDsKY5vUxM0yxkAYnbkRbZEw==

"@types/webpack-node-externals@^2.5.1":
version "2.5.1"
resolved "https://registry.yarnpkg.com/@types/webpack-node-externals/-/webpack-node-externals-2.5.1.tgz#0f00036bce0f405ceabc092e415b734059fe5505"
Expand Down Expand Up @@ -4241,11 +4236,6 @@ [email protected], buffer-from@^1.0.0:
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==

buffer-json@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/buffer-json/-/buffer-json-2.0.0.tgz#f73e13b1e42f196fe2fd67d001c7d7107edd7c23"
integrity sha512-+jjPFVqyfF1esi9fvfUs3NqM0pH1ziZ36VP4hmA/y/Ssfo/5w5xHKfTw9BwQjoJ1w/oVtpLomqwUHKdefGyuHw==

buffer@^5.2.1, buffer@^5.5.0:
version "5.7.1"
resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.7.1.tgz#ba62e7c13133053582197160851a8f648e99eed0"
Expand Down Expand Up @@ -4355,18 +4345,6 @@ cache-base@^1.0.1:
union-value "^1.0.0"
unset-value "^1.0.0"

cache-loader@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/cache-loader/-/cache-loader-4.1.0.tgz#9948cae353aec0a1fcb1eafda2300816ec85387e"
integrity sha512-ftOayxve0PwKzBF/GLsZNC9fJBXl8lkZE3TOsjkboHfVHVkL39iUEs1FO07A33mizmci5Dudt38UZrrYXDtbhw==
dependencies:
buffer-json "^2.0.0"
find-cache-dir "^3.0.0"
loader-utils "^1.2.3"
mkdirp "^0.5.1"
neo-async "^2.6.1"
schema-utils "^2.0.0"

cacheable-request@^6.0.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/cacheable-request/-/cacheable-request-6.1.0.tgz#20ffb8bd162ba4be11e9567d823db651052ca912"
Expand Down Expand Up @@ -7227,7 +7205,7 @@ find-cache-dir@^2.0.0:
make-dir "^2.0.0"
pkg-dir "^3.0.0"

find-cache-dir@^3.0.0, find-cache-dir@^3.3.1:
find-cache-dir@^3.3.1:
version "3.3.1"
resolved "https://registry.yarnpkg.com/find-cache-dir/-/find-cache-dir-3.3.1.tgz#89b33fad4a4670daa94f855f7fbe31d6d84fe880"
integrity sha512-t2GDMt3oGC/v+BMwzmllWDuJF/xcDtE5j/fCGbqDD7OLuJkj0cfh1YSA5VKPvwMeLFLNDBkwOKZ2X85jGLVftQ==
Expand Down Expand Up @@ -9938,7 +9916,7 @@ loader-runner@^4.1.0, loader-runner@^4.2.0:
resolved "https://registry.yarnpkg.com/loader-runner/-/loader-runner-4.2.0.tgz#d7022380d66d14c5fb1d496b89864ebcfd478384"
integrity sha512-92+huvxMvYlMzMt0iIOukcwYBFpkYJdpl2xsZ7LrlayO7E8SOv+JJUEK17B/dJIHAOLMfh2dZZ/Y18WgmGtYNw==

loader-utils@^1.0.2, loader-utils@^1.1.0, loader-utils@^1.2.3, loader-utils@^1.4.0:
loader-utils@^1.0.2, loader-utils@^1.1.0, loader-utils@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.4.0.tgz#c579b5e34cb34b1a74edc6c1fb36bfa371d5a613"
integrity sha512-qH0WSMBtn/oHuwjy/NucEgbx5dbxxnxup9s4PVXJUDHZBQY+s0NWA9rJf53RBnQZxfch7euUui7hpoAPvALZdA==
Expand Down Expand Up @@ -11031,7 +11009,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.2.tgz#feacf7ccf525a77ae9634436a64883ffeca346fb"
integrity sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw==

neo-async@^2.6.0, neo-async@^2.6.1, neo-async@^2.6.2:
neo-async@^2.6.0, neo-async@^2.6.2:
version "2.6.2"
resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.2.tgz#b4aafb93e3aeb2d8174ca53cf163ab7d7308305f"
integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==
Expand Down Expand Up @@ -14170,7 +14148,7 @@ schema-utils@^1.0.0:
ajv-errors "^1.0.0"
ajv-keywords "^3.1.0"

schema-utils@^2.0.0, schema-utils@^2.6.5:
schema-utils@^2.6.5:
version "2.7.1"
resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-2.7.1.tgz#1ca4f32d1b24c590c203b8e7a50bf0ea4cd394d7"
integrity sha512-SHiNtMOUGWBQJwzISiVYKu82GiV4QYGePp3odlY1tuKO7gPtphAT5R/py0fA6xtbgLL/RvtJZnU9b8s0F1q0Xg==
Expand Down

0 comments on commit 61f30a2

Please sign in to comment.