99'use strict' ;
1010
1111const fs = require ( 'fs' ) ;
12- const isWsl = require ( 'is-wsl' ) ;
1312const path = require ( 'path' ) ;
1413const webpack = require ( 'webpack' ) ;
1514const resolve = require ( 'resolve' ) ;
@@ -83,40 +82,11 @@ module.exports = function(webpackEnv) {
8382 const isEnvProductionProfile =
8483 isEnvProduction && process . argv . includes ( '--profile' ) ;
8584
86- // wptheme added - start
87- const publicPathWithTrailingSlash = isEnvProduction
88- ? wpThemeUserConfig . homepage . endsWith ( '/' )
89- ? wpThemeUserConfig . homepage
90- : `${ wpThemeUserConfig . homepage } /`
91- : paths . servedPath ;
92- // wptheme added - end
93-
94- // Webpack uses `publicPath` to determine where the app is being served from.
95- // It requires a trailing slash, or the file assets will get an incorrect path.
96- // In development, we always serve from the root. This makes config easier.
97- // wptheme remarked out - start
98- // const publicPath = isEnvProduction
99- // ? paths.servedPath
100- // : isEnvDevelopment && '/';
101- // wptheme remarked out - end
102- const publicPath = publicPathWithTrailingSlash ; // wptheme added
103-
104- // Some apps do not use client-side routing with pushState.
105- // For these, "homepage" can be set to "." to enable relative asset paths.
106- const shouldUseRelativeAssetPaths = publicPath === './' ;
107-
108- // `publicUrl` is just like `publicPath`, but we will provide it to our app
85+ // We will provide `paths.publicUrlOrPath` to our app
10986 // as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
11087 // Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
111- // wptheme remarked out - start
112- // const publicUrl = isEnvProduction
113- // ? publicPath.slice(0, -1)
114- // : isEnvDevelopment && '';
115- // wptheme remarked out - end
116- const publicUrl = publicPathWithTrailingSlash . slice ( 0 , - 1 ) ; // wptheme added
117-
11888 // Get environment variables to inject into our app.
119- const env = getClientEnvironment ( publicUrl ) ;
89+ const env = getClientEnvironment ( paths . publicUrlOrPath . slice ( 0 , - 1 ) ) ;
12090
12191 // common function to get style loaders
12292 const getStyleLoaders = ( cssOptions , preProcessor ) => {
@@ -125,7 +95,11 @@ module.exports = function(webpackEnv) {
12595 // isEnvProduction && // wptheme remarked out -- always use MiniCssExtractPlugin to generate css
12696 {
12797 loader : MiniCssExtractPlugin . loader ,
128- options : shouldUseRelativeAssetPaths ? { publicPath : '../../' } : { } ,
98+ // css is located in `static/css`, use '../../' to locate index.html folder
99+ // in production `paths.publicUrlOrPath` can be a relative path
100+ options : paths . publicUrlOrPath . startsWith ( '.' )
101+ ? { publicPath : '../../' }
102+ : { } ,
129103 } ,
130104 {
131105 loader : require . resolve ( 'css-loader' ) ,
@@ -219,8 +193,7 @@ module.exports = function(webpackEnv) {
219193 // There are also additional JS chunk files if you use code splitting.
220194 chunkFilename : 'static/js/[name].chunk.js' , // wptheme modified... always use cache busting via the HtmlWebpackPlugin config, way below here
221195 // We inferred the "public path" (such as / or /my-project) from homepage.
222- // We use "/" in development.
223- publicPath : publicPath ,
196+ publicPath : paths . publicUrlOrPath ,
224197 // Point sourcemap entries to original disk location (format as URL on Windows)
225198 devtoolModuleFilenameTemplate : isEnvProduction
226199 ? info =>
@@ -229,7 +202,7 @@ module.exports = function(webpackEnv) {
229202 . replace ( / \\ / g, '/' )
230203 : isEnvDevelopment &&
231204 ( info => path . resolve ( info . absoluteResourcePath ) . replace ( / \\ / g, '/' ) ) ,
232- // Prevents conflicts when multiple Webpack runtimes (from different apps)
205+ // Prevents conflicts when multiple webpack runtimes (from different apps)
233206 // are used on the same page.
234207 jsonpFunction : `webpackJsonp${ appPackageJson . name } ` ,
235208 // this defaults to 'window', but by setting it to 'this' then
@@ -315,7 +288,7 @@ module.exports = function(webpackEnv) {
315288 } ,
316289 } ,
317290 resolve : {
318- // This allows you to set a fallback for where Webpack should look for modules.
291+ // This allows you to set a fallback for where webpack should look for modules.
319292 // We placed these paths second because we want `node_modules` to "win"
320293 // if there are any conflicts. This matches Node resolution mechanism.
321294 // https://github.com/facebook/create-react-app/issues/253
@@ -356,7 +329,7 @@ module.exports = function(webpackEnv) {
356329 } ,
357330 resolveLoader : {
358331 plugins : [
359- // Also related to Plug'n'Play, but this time it tells Webpack to load its loaders
332+ // Also related to Plug'n'Play, but this time it tells webpack to load its loaders
360333 // from the current package.
361334 PnpWebpackPlugin . moduleLoader ( module ) ,
362335 ] ,
@@ -649,9 +622,8 @@ module.exports = function(webpackEnv) {
649622 // Makes some environment variables available in index.html.
650623 // The public URL is available as %PUBLIC_URL% in index.html, e.g.:
651624 // <link rel="icon" href="%PUBLIC_URL%/favicon.ico">
652- // In production, it will be an empty string unless you specify "homepage"
625+ // It will be an empty string unless you specify "homepage"
653626 // in `package.json`, in which case it will be the pathname of that URL.
654- // In development, this will be an empty string.
655627 new InterpolateHtmlPlugin ( HtmlWebpackPlugin , env . raw ) ,
656628 // This gives some necessary context to module not found errors, such as
657629 // the requesting resource.
@@ -673,7 +645,7 @@ module.exports = function(webpackEnv) {
673645 // touchFile is used to force WebPack to do a rebuild. It must be a file that WebPack is watching.
674646 new FileWatcherPlugin ( fileWatcherPluginConfig ) ,
675647 // If you require a missing module and then `npm install` it, you still have
676- // to restart the development server for Webpack to discover it. This plugin
648+ // to restart the development server for webpack to discover it. This plugin
677649 // makes the discovery automatic so you don't have to restart.
678650 // See https://github.com/facebook/create-react-app/issues/186
679651 isEnvDevelopment &&
@@ -695,7 +667,7 @@ module.exports = function(webpackEnv) {
695667 // can be used to reconstruct the HTML if necessary
696668 new ManifestPlugin ( {
697669 fileName : 'asset-manifest.json' ,
698- publicPath : publicPath ,
670+ publicPath : paths . publicUrlOrPath ,
699671 generate : ( seed , files , entrypoints ) => {
700672 const manifestFiles = files . reduce ( ( manifest , file ) => {
701673 manifest [ file . name ] = file . path ;
@@ -712,19 +684,19 @@ module.exports = function(webpackEnv) {
712684 } ,
713685 } ) ,
714686 // Moment.js is an extremely popular library that bundles large locale files
715- // by default due to how Webpack interprets its code. This is a practical
687+ // by default due to how webpack interprets its code. This is a practical
716688 // solution that requires the user to opt into importing specific locales.
717689 // https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
718690 // You can remove this if you don't use Moment.js:
719691 new webpack . IgnorePlugin ( / ^ \. \/ l o c a l e $ / , / m o m e n t $ / ) ,
720692 // Generate a service worker script that will precache, and keep up to date,
721- // the HTML & assets that are part of the Webpack build.
693+ // the HTML & assets that are part of the webpack build.
722694 isEnvProduction &&
723695 new WorkboxWebpackPlugin . GenerateSW ( {
724696 clientsClaim : true ,
725697 exclude : [ / \. m a p $ / , / a s s e t - m a n i f e s t \. j s o n $ / ] ,
726698 importWorkboxFrom : 'cdn' ,
727- navigateFallback : publicUrl + '/index.php' , // wptheme added php support
699+ navigateFallback : paths . publicUrlOrPath + '/index.php' , // wptheme added php support
728700 navigateFallbackBlacklist : [
729701 // Exclude URLs starting with /_, as they're likely an API call
730702 new RegExp ( '^/_' ) ,
@@ -758,14 +730,13 @@ module.exports = function(webpackEnv) {
758730 '!**/src/setupProxy.*' ,
759731 '!**/src/setupTests.*' ,
760732 ] ,
761- watch : paths . appSrc ,
762733 silent : true ,
763734 // The formatter is invoked directly in WebpackDevServerUtils during development
764735 formatter : isEnvProduction ? typescriptFormatter : undefined ,
765736 } ) ,
766737 ] . filter ( Boolean ) ,
767738 // Some libraries import Node modules but don't use them in the browser.
768- // Tell Webpack to provide empty mocks for them so importing them works.
739+ // Tell webpack to provide empty mocks for them so importing them works.
769740 node : {
770741 module : 'empty' ,
771742 dgram : 'empty' ,
0 commit comments