-
Notifications
You must be signed in to change notification settings - Fork 107
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
Add unminified source JS files to builds #1643
Changes from all commits
a15db87
9ba7400
236c61f
b686515
a3ab16a
1b0731d
b7e8e30
b7127d7
888ecdb
693e1db
163082f
232e227
9747f7b
c34ac17
37d8078
0a1354b
6e18901
04f7a75
7af4b07
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ nbproject/ | |
|
||
build | ||
.wp-env.override.json | ||
*.min.js | ||
*.asset.php | ||
|
||
############ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,82 @@ const sharedConfig = { | |
}; | ||
|
||
// Store plugins that require build process. | ||
const pluginsWithBuild = [ 'optimization-detective', 'web-worker-offloading' ]; | ||
const pluginsWithBuild = [ | ||
'embed-optimizer', | ||
'image-prioritizer', | ||
'optimization-detective', | ||
'web-worker-offloading', | ||
]; | ||
|
||
/** | ||
* Webpack Config: Embed Optimizer | ||
* | ||
* @param {*} env Webpack environment | ||
* @return {Object} Webpack configuration | ||
*/ | ||
const embedOptimizer = ( env ) => { | ||
if ( env.plugin && env.plugin !== 'embed-optimizer' ) { | ||
return defaultBuildConfig; | ||
} | ||
|
||
const pluginDir = path.resolve( __dirname, 'plugins/embed-optimizer' ); | ||
|
||
return { | ||
...sharedConfig, | ||
name: 'embed-optimizer', | ||
plugins: [ | ||
new CopyWebpackPlugin( { | ||
patterns: [ | ||
{ | ||
from: `${ pluginDir }/detect.js`, | ||
to: `${ pluginDir }/detect.min.js`, | ||
}, | ||
{ | ||
from: `${ pluginDir }/lazy-load.js`, | ||
to: `${ pluginDir }/lazy-load.min.js`, | ||
}, | ||
], | ||
} ), | ||
new WebpackBar( { | ||
name: 'Building Embed Optimizer Assets', | ||
color: '#2196f3', | ||
} ), | ||
], | ||
}; | ||
}; | ||
|
||
/** | ||
* Webpack Config: Image Prioritizer | ||
* | ||
* @param {*} env Webpack environment | ||
* @return {Object} Webpack configuration | ||
*/ | ||
const imagePrioritizer = ( env ) => { | ||
if ( env.plugin && env.plugin !== 'image-prioritizer' ) { | ||
return defaultBuildConfig; | ||
} | ||
|
||
const pluginDir = path.resolve( __dirname, 'plugins/image-prioritizer' ); | ||
|
||
return { | ||
...sharedConfig, | ||
name: 'image-prioritizer', | ||
plugins: [ | ||
new CopyWebpackPlugin( { | ||
patterns: [ | ||
{ | ||
from: `${ pluginDir }/lazy-load.js`, | ||
to: `${ pluginDir }/lazy-load.min.js`, | ||
}, | ||
], | ||
} ), | ||
new WebpackBar( { | ||
name: 'Building Image Prioritizer Assets', | ||
color: '#2196f3', | ||
} ), | ||
], | ||
}; | ||
}; | ||
|
||
/** | ||
* Webpack Config: Optimization Detective | ||
|
@@ -50,7 +125,7 @@ const optimizationDetective = ( env ) => { | |
const source = path.resolve( __dirname, 'node_modules/web-vitals' ); | ||
const destination = path.resolve( | ||
__dirname, | ||
'plugins/optimization-detective/build' | ||
'plugins/optimization-detective' | ||
); | ||
|
||
return { | ||
|
@@ -61,16 +136,21 @@ const optimizationDetective = ( env ) => { | |
patterns: [ | ||
{ | ||
from: `${ source }/dist/web-vitals.js`, | ||
to: `${ destination }/web-vitals.js`, | ||
to: `${ destination }/build/web-vitals.js`, | ||
info: { minimized: true }, | ||
}, | ||
{ | ||
from: `${ source }/package.json`, | ||
to: `${ destination }/web-vitals.asset.php`, | ||
to: `${ destination }/build/web-vitals.asset.php`, | ||
transform: { | ||
transformer: assetDataTransformer, | ||
cache: false, | ||
}, | ||
}, | ||
{ | ||
from: `${ destination }/detect.js`, | ||
to: `${ destination }/detect.min.js`, | ||
}, | ||
], | ||
} ), | ||
new WebpackBar( { | ||
|
@@ -110,6 +190,7 @@ const webWorkerOffloading = ( env ) => { | |
{ | ||
from: `${ source }/lib/`, | ||
to: `${ destination }`, | ||
info: { minimized: true }, | ||
}, | ||
{ | ||
from: `${ source }/package.json`, | ||
|
@@ -164,6 +245,7 @@ const buildPlugin = ( env ) => { | |
{ | ||
from, | ||
to, | ||
info: { minimized: true }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This won't attempt to create a minified version of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, actually it's the opposite - setting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, thank you. I'm a little confused. We want to create minified versions of all the scripts, except for those which are copied from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me clarify the current state and what needs to be fixed:
I'll update this PR to handle both these cases. Would that address your concerns? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I believe so! |
||
globOptions: { | ||
dot: true, | ||
ignore: [ | ||
|
@@ -203,4 +285,10 @@ const buildPlugin = ( env ) => { | |
}; | ||
}; | ||
|
||
module.exports = [ optimizationDetective, webWorkerOffloading, buildPlugin ]; | ||
module.exports = [ | ||
embedOptimizer, | ||
imagePrioritizer, | ||
optimizationDetective, | ||
webWorkerOffloading, | ||
buildPlugin, | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this missing the flag to say it is minified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! I just realized this. I should probably make this change in the config for Web Worker Offloading as well, which is copying the partytown files.