Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(gatsby): move cache folders to .cache #25192

Merged
merged 1 commit into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Object {
"loader": StringContaining "babel-loader",
"options": Object {
"babelrc": false,
"cacheDirectory": "<TEMP_DIR>/test/.cache/webpack/babel",
"cacheIdentifier": "[email protected]",
"compact": false,
"configFile": false,
Expand Down Expand Up @@ -37,6 +38,7 @@ Object {
Object {
"loader": StringContaining "babel-loader",
"options": Object {
"cacheDirectory": "<TEMP_DIR>/test/.cache/webpack/babel",
"compact": false,
"configFile": true,
"stage": "develop",
Expand Down
5 changes: 4 additions & 1 deletion packages/gatsby/src/utils/__tests__/webpack-utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as os from "os"
import { createWebpackUtils } from "../webpack-utils"
import { Stage, IProgram } from "../../commands/types"

Expand Down Expand Up @@ -27,7 +28,9 @@ jest.mock(`autoprefixer`, () =>
let config

beforeAll(() => {
config = createWebpackUtils(Stage.Develop, {} as IProgram)
config = createWebpackUtils(Stage.Develop, {
directory: `${os.tmpdir()}/test`,
} as IProgram)
})

describe(`webpack utils`, () => {
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/src/utils/__tests__/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ beforeEach(() => {
const getConfig = (args = {}) =>
webpackConfig(
{
directory: process.cwd(),
extensions: [`.js`],
},
process.cwd(),
Expand Down
1 change: 0 additions & 1 deletion packages/gatsby/src/utils/babel-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ module.exports = babelLoader.custom(babel => {
stage,
},
loader: {
cacheDirectory: true,
sidharthachatterjee marked this conversation as resolved.
Show resolved Hide resolved
sourceType: `unambiguous`,
...getCustomOptions(stage),
...options,
Expand Down
22 changes: 20 additions & 2 deletions packages/gatsby/src/utils/webpack-utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as path from "path"
import { Loader, RuleSetRule, Plugin } from "webpack"
import { GraphQLSchema } from "graphql"
import postcss from "postcss"
Expand Down Expand Up @@ -267,6 +268,13 @@ export const createWebpackUtils = (
return {
options: {
stage,
// TODO add proper cache keys
cacheDirectory: path.join(
program.directory,
`.cache`,
`webpack`,
`babel`
),
...options,
},
loader: require.resolve(`./babel-loader`),
Expand All @@ -275,7 +283,16 @@ export const createWebpackUtils = (

dependencies: options => {
return {
options,
options: {
// TODO add proper cache keys
cacheDirectory: path.join(
program.directory,
`.cache`,
`webpack`,
`babel`
),
...options,
},
loader: require.resolve(`babel-loader`),
}
},
Expand Down Expand Up @@ -541,7 +558,8 @@ export const createWebpackUtils = (
...options
}: { terserOptions?: TerserPlugin.TerserPluginOptions } = {}): Plugin =>
new TerserPlugin({
cache: true,
// TODO add proper cache keys
cache: path.join(program.directory, `.cache`, `webpack`, `terser`),
// We can't use parallel in WSL because of https://github.com/gatsbyjs/gatsby/issues/6540
// This issue was fixed in https://github.com/gatsbyjs/gatsby/pull/12636
parallel: !isWsl,
Expand Down