-
Notifications
You must be signed in to change notification settings - Fork 812
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lazy-images: Use the new webpack-config package
Mostly as a proof of concept. But I also took the opportunity to clean a few things up: * Name the built JS as ".min.js" like it should be. * Use copy-webpack-plugin to copy the src version of intersection-observer. * Use @wordpress/dependency-extraction-webpack-plugin to handle the cache-buster version in `wp_enqueue_script()`.
- Loading branch information
Showing
5 changed files
with
76 additions
and
58 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
projects/packages/lazy-images/changelog/add-webpack-config-js-package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: changed | ||
|
||
Update webpack build config. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,43 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
const getBaseWebpackConfig = require( '@automattic/calypso-build/webpack.config.js' ); | ||
const jetpackWebpackConfig = require( '@automattic/jetpack-webpack-config/webpack' ); | ||
const path = require( 'path' ); | ||
|
||
const baseConfig = getBaseWebpackConfig( | ||
{ WP: false }, | ||
{ | ||
entry: {}, // We'll override later | ||
'output-filename': '[name].js', | ||
'output-path': path.join( __dirname, './dist' ), | ||
} | ||
); | ||
const CopyWebpackPlugin = require( 'copy-webpack-plugin' ); | ||
|
||
module.exports = [ | ||
{ | ||
...baseConfig, | ||
entry: { | ||
'lazy-images': './src/js/lazy-images.js', | ||
'intersection-observer': require.resolve( 'intersection-observer/intersection-observer.js' ), | ||
}, | ||
mode: jetpackWebpackConfig.mode, | ||
devtool: jetpackWebpackConfig.devtool, | ||
output: { | ||
...jetpackWebpackConfig.output, | ||
path: path.resolve( './dist' ), | ||
}, | ||
optimization: { | ||
...jetpackWebpackConfig.optimization, | ||
}, | ||
resolve: { | ||
...baseConfig.resolve, | ||
modules: [ 'node_modules' ], | ||
...jetpackWebpackConfig.resolve, | ||
}, | ||
entry: { | ||
'lazy-images': path.join( __dirname, './src/js/lazy-images.js' ), | ||
'intersection-observer': path.join( | ||
__dirname, | ||
'./node_modules/intersection-observer/intersection-observer.js' | ||
), | ||
node: false, | ||
plugins: [ | ||
...jetpackWebpackConfig.StandardPlugins(), | ||
new CopyWebpackPlugin( { | ||
patterns: [ | ||
{ | ||
from: require.resolve( 'intersection-observer/intersection-observer.js' ), | ||
to: 'intersection-observer.src.js', | ||
}, | ||
], | ||
} ), | ||
], | ||
module: { | ||
strictExportPresence: true, | ||
rules: [ | ||
// Transpile JavaScript, including node_modules. | ||
jetpackWebpackConfig.TranspileRule(), | ||
], | ||
}, | ||
}, | ||
]; |