-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from humanmade/cra2
Create React App v2
- Loading branch information
Showing
13 changed files
with
12,347 additions
and
7,898 deletions.
There are no files selected for viewing
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 +1,12 @@ | ||
module.exports = require( 'react-scripts/config/paths.js' ); | ||
const paths = require('react-scripts/config/paths.js'); | ||
|
||
module.exports = Object.assign( paths, { | ||
// We point this to the template file in react-scripts to bypass the | ||
// start and build script checks for the existence of this file. The | ||
// index.html & public folder are of no use in a WP context. | ||
appHtml: require.resolve('react-scripts/template/public/index.html'), | ||
// Force the served path to a relative URL to generate the correct | ||
// service worker precache manifest and also correct paths in the | ||
// asset-manifest.json file. | ||
servedPath: './', | ||
} ); |
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 +1,17 @@ | ||
module.exports = require( 'react-scripts/config/webpack.config.prod.js' ); | ||
const config = require( 'react-scripts/config/webpack.config.prod.js' ); | ||
const { GenerateSW } = require( 'workbox-webpack-plugin' ); | ||
const applyWpConfig = require( '../overrides/applyWpConfig' ); | ||
|
||
// Remove default Workbox plugin. | ||
config.plugins = config.plugins.filter( plugin => ! ( plugin instanceof GenerateSW ) ); | ||
|
||
// Generate a service worker script that will precache, and keep up to date, | ||
// the HTML & assets that are part of the Webpack build without the navigation | ||
// fallback. | ||
config.plugins.push( new GenerateSW( { | ||
clientsClaim: true, | ||
exclude: [ /\.map$/, /asset-manifest\.json$/ ], | ||
importWorkboxFrom: 'cdn', | ||
} ) ); | ||
|
||
module.exports = applyWpConfig( 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const paths = require( '../config/paths' ); | ||
const HtmlWebpackPlugin = require( 'html-webpack-plugin' ); | ||
const InterpolateHtmlPlugin = require( 'react-dev-utils/InterpolateHtmlPlugin' ); | ||
const { DefinePlugin } = require( 'webpack' ); | ||
|
||
module.exports = config => { | ||
const appNameVar = require(paths.appPackageJson).name.replace( /[\W]+/g, '' ); | ||
|
||
// Remove HTML file output plugins. | ||
config.plugins = config.plugins.filter( plugin => ! ( plugin instanceof HtmlWebpackPlugin ) ); | ||
config.plugins = config.plugins.filter( plugin => ! ( plugin instanceof InterpolateHtmlPlugin ) ); | ||
|
||
// Change the optimization settings to only output async chunks. This means | ||
// only the runtime and main bundle file need to be enqueued and helps us | ||
// avoid the possiblity of enqueuing the wrong initial chunk file. | ||
config.optimization.splitChunks.chunks = 'async'; | ||
|
||
// Set a default JSONP function name to avoid conflicts with other instances | ||
// of react-wp-scripts using code splitting. | ||
config.output.jsonpFunction = `${appNameVar}JSONP`; | ||
|
||
// Set some useful externals based on what WP provides in v5.x. | ||
config.externals = Object.assign( config.externals || {}, { | ||
wp: 'wp', | ||
react: 'React', | ||
'react-dom': 'ReactDOM', | ||
moment: 'moment', | ||
lodash: 'lodash', | ||
} ); | ||
|
||
return config; | ||
}; |
Oops, something went wrong.