Skip to content

Commit

Permalink
quick save
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh committed Oct 26, 2022
1 parent ef78c99 commit f77df1f
Show file tree
Hide file tree
Showing 4 changed files with 249 additions and 187 deletions.
1 change: 1 addition & 0 deletions packages/gatsby/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ module.exports = async function build(
program,
buildActivityTimer.span
)
fs.writeFileSync(`moar-stats.json`, JSON.stringify(stats.toJson()))
closeJavascriptBundleCompilation = close

if (stats.hasWarnings()) {
Expand Down
189 changes: 95 additions & 94 deletions packages/gatsby/src/utils/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,30 +579,30 @@ module.exports = async (
cacheGroups: {
default: false,
defaultVendors: false,
framework: {
chunks: `all`,
name: `framework`,
// This regex ignores nested copies of framework libraries so they're bundled with their issuer.
test: new RegExp(
`(?<!node_modules.*)[\\\\/]node_modules[\\\\/](${FRAMEWORK_BUNDLES.join(
`|`
)})[\\\\/]`
),
priority: 40,
// Don't let webpack eliminate this chunk (prevents this chunk from becoming a part of the commons chunk)
enforce: true,
},
// Bundle all css & lazy css into one stylesheet to make sure lazy components do not break
// TODO make an exception for css-modules
styles: {
test(module) {
return isCssModule(module)
},

name: `commons`,
priority: 40,
enforce: true,
},
// framework: {
// chunks: `all`,
// name: `framework`,
// // This regex ignores nested copies of framework libraries so they're bundled with their issuer.
// test: new RegExp(
// `(?<!node_modules.*)[\\\\/]node_modules[\\\\/](${FRAMEWORK_BUNDLES.join(
// `|`
// )})[\\\\/]`
// ),
// priority: 40,
// // Don't let webpack eliminate this chunk (prevents this chunk from becoming a part of the commons chunk)
// enforce: true,
// },
// // Bundle all css & lazy css into one stylesheet to make sure lazy components do not break
// // TODO make an exception for css-modules
// styles: {
// test(module) {
// return isCssModule(module)
// },

// name: `commons`,
// priority: 40,
// enforce: true,
// },
},
},
minimize: false,
Expand Down Expand Up @@ -631,77 +631,77 @@ module.exports = async (
cacheGroups: {
default: false,
defaultVendors: false,
framework: {
chunks: `all`,
name: `framework`,
// This regex ignores nested copies of framework libraries so they're bundled with their issuer.
test: new RegExp(
`(?<!node_modules.*)[\\\\/]node_modules[\\\\/](${FRAMEWORK_BUNDLES.join(
`|`
)})[\\\\/]`
),
priority: 40,
// Don't let webpack eliminate this chunk (prevents this chunk from becoming a part of the commons chunk)
enforce: true,
},
// if a module is bigger than 160kb from node_modules we make a separate chunk for it
lib: {
test(module) {
return (
!isCssModule(module) &&
module.size() > 160000 &&
/node_modules[/\\]/.test(module.identifier())
)
},
name(module) {
const hash = crypto.createHash(`sha1`)
if (!module.libIdent) {
throw new Error(
`Encountered unknown module type: ${module.type}. Please open an issue.`
)
}

hash.update(module.libIdent({ context: program.directory }))

return hash.digest(`hex`).substring(0, 8)
},
priority: 30,
minChunks: 1,
reuseExistingChunk: true,
},
commons: {
name: `commons`,
// if a chunk is used on all components we put it in commons (we need at least 2 components)
minChunks: Math.max(componentsCount, 2),
priority: 20,
},
// If a chunk is used in at least 2 components we create a separate chunk
shared: {
test: module => !isCssModule(module),
name(module, chunks) {
const hash = crypto
.createHash(`sha1`)
.update(chunks.reduce((acc, chunk) => acc + chunk.name, ``))
.digest(`hex`)

return hash
},
priority: 10,
minChunks: 2,
reuseExistingChunk: true,
},

// Bundle all css & lazy css into one stylesheet to make sure lazy components do not break
// TODO make an exception for css-modules
styles: {
test(module) {
return isCssModule(module)
},
// framework: {
// chunks: `all`,
// name: `framework`,
// // This regex ignores nested copies of framework libraries so they're bundled with their issuer.
// test: new RegExp(
// `(?<!node_modules.*)[\\\\/]node_modules[\\\\/](${FRAMEWORK_BUNDLES.join(
// `|`
// )})[\\\\/]`
// ),
// priority: 40,
// // Don't let webpack eliminate this chunk (prevents this chunk from becoming a part of the commons chunk)
// enforce: true,
// },
// // if a module is bigger than 160kb from node_modules we make a separate chunk for it
// lib: {
// test(module) {
// return (
// !isCssModule(module) &&
// module.size() > 160000 &&
// /node_modules[/\\]/.test(module.identifier())
// )
// },
// name(module) {
// const hash = crypto.createHash(`sha1`)
// if (!module.libIdent) {
// throw new Error(
// `Encountered unknown module type: ${module.type}. Please open an issue.`
// )
// }

name: `styles`,
priority: 40,
enforce: true,
},
// hash.update(module.libIdent({ context: program.directory }))

// return hash.digest(`hex`).substring(0, 8)
// },
// priority: 30,
// minChunks: 1,
// reuseExistingChunk: true,
// },
// commons: {
// name: `commons`,
// // if a chunk is used on all components we put it in commons (we need at least 2 components)
// minChunks: Math.max(componentsCount, 2),
// priority: 20,
// },
// // If a chunk is used in at least 2 components we create a separate chunk
// shared: {
// test: module => !isCssModule(module),
// name(module, chunks) {
// const hash = crypto
// .createHash(`sha1`)
// .update(chunks.reduce((acc, chunk) => acc + chunk.name, ``))
// .digest(`hex`)

// return hash
// },
// priority: 10,
// minChunks: 2,
// reuseExistingChunk: true,
// },

// // Bundle all css & lazy css into one stylesheet to make sure lazy components do not break
// // TODO make an exception for css-modules
// styles: {
// test(module) {
// return isCssModule(module)
// },

// name: `styles`,
// priority: 40,
// enforce: true,
// },
},
// We load our pages async through async-requires, maxInitialRequests doesn't have an effect on chunks derived from page components.
// By default webpack has set maxAsyncRequests to 6, in some cases this isn't enough an actually makes the bundle size blow up.
Expand All @@ -713,6 +713,7 @@ module.exports = async (
}

config.optimization = {
// concatenateModules: false,
runtimeChunk: {
name: `webpack-runtime`,
},
Expand Down
15 changes: 12 additions & 3 deletions packages/gatsby/src/utils/webpack/loaders/virtual.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const Template = require(`webpack/lib/Template`)

module.exports = async function virtual(source, sourceMap): string {
console.log({ options: this.getOptions() })
const { modules } = this.getOptions()
Expand All @@ -6,9 +8,14 @@ module.exports = async function virtual(source, sourceMap): string {

const code = requests
// Filter out css files on the server
.map(
request => `import(/* webpackMode: "eager" */ ${JSON.stringify(request)})`
)
.map(request => {
const chunkName = Template.toPath(request)
console.log({ chunkName })

return `import(/* webpackChunkName: "${chunkName}" */ ${JSON.stringify(
request
)})`
})
.join(`;\n`)

// const buildInfo = getModuleBuildInfo(this._module)
Expand All @@ -24,5 +31,7 @@ module.exports = async function virtual(source, sourceMap): string {
// requests: resolvedRequests,
// }

console.log({ code })

return code
}
Loading

0 comments on commit f77df1f

Please sign in to comment.