diff --git a/common/webpack.factory.ts b/common/webpack.factory.ts index c378025..faa2a72 100755 --- a/common/webpack.factory.ts +++ b/common/webpack.factory.ts @@ -222,10 +222,10 @@ function createDefaultSettings( ...plugins .filter(({ location }) => location === pwd) .reduce((map: { [key: string]: Options.CacheGroupsOptions }, obj) => { - map[`vendor~${obj.entrypointName}`] = { + map[`vendor-${obj.entrypointName}`] = { test: /node_modules.*(? chunk.name === obj.entrypointName, - name: `vendor~${obj.entrypointName}`, + name: `vendor-${obj.entrypointName}`, enforce: true }; return map; @@ -234,6 +234,10 @@ function createDefaultSettings( : { vendor: { test: /node_modules.*(? { + const allChunksNames = chunks.map((item: any) => item.name).join("-"); + return `${cacheGroupKey}-${allChunksNames}`; + }, chunks: "initial", enforce: true } diff --git a/packages/utils/src/Assets.php b/packages/utils/src/Assets.php index 719b9cc..1749d29 100755 --- a/packages/utils/src/Assets.php +++ b/packages/utils/src/Assets.php @@ -131,14 +131,7 @@ public function enqueueReact() { public function enqueueUtils() { $this->enqueueReact(); $this->enqueueMobx(); - $scriptDeps = [ - self::$HANDLE_REACT, - self::$HANDLE_REACT_DOM, - self::$HANDLE_MOBX, - 'moment', - 'wp-i18n', - 'jquery' - ]; + $scriptDeps = [self::$HANDLE_REACT, self::$HANDLE_REACT_DOM, self::$HANDLE_MOBX, 'moment', 'wp-i18n', 'jquery']; $handleUtils = $this->enqueueComposerScript('utils', $scriptDeps); array_push($scriptDeps, $handleUtils); return $scriptDeps; @@ -156,7 +149,7 @@ public function enqueueMobx() { } /** - * Checks if a `vendor~` file is created for a given script and enqueue it. + * Checks if a `vendor-` file is created for a given script and enqueue it. * * @param string $handle * @param boolean $isLib @@ -167,7 +160,7 @@ public function enqueueMobx() { */ protected function probablyEnqueueChunk($handle, $isLib, $src, &$deps, $in_footer, $media) { if (!$isLib) { - $handle = $this->enqueue('vendor~' . $handle, 'vendor~' . $src, $deps, false, 'script', $in_footer, $media); + $handle = $this->enqueue('vendor-' . $handle, 'vendor-' . $src, $deps, false, 'script', $in_footer, $media); if ($handle !== false) { array_push($deps, $handle); } @@ -314,7 +307,7 @@ public function enqueueLibraryStyle($handle, $src, $deps = [], $media = 'all') { } /** - * Checks if a `vendor~` file is created for a given script in a composer package and enqueue it. + * Checks if a `vendor-` file is created for a given script in a composer package and enqueue it. * * @param string $handle * @param string $src @@ -327,12 +320,12 @@ protected function probablyEnqueueComposerChunk($handle, $src, &$deps, $in_foote $scriptSuffix = $src === 'index.js' || $src === 'index.css' ? '' : '-' . pathinfo($src, PATHINFO_FILENAME); $handle = $this->enqueueComposer( $handle, - 'vendor~' . $src, + 'vendor-' . $src, $deps, 'script', $in_footer, $media, - 'vendor~' . $rootSlug . '-' . $handle . $scriptSuffix + 'vendor-' . $rootSlug . '-' . $handle . $scriptSuffix ); if ($handle !== false) { array_push($deps, $handle); diff --git a/packages/utils/test/phpunit/AssetsTest.php b/packages/utils/test/phpunit/AssetsTest.php index 4a785d9..2946ca7 100755 --- a/packages/utils/test/phpunit/AssetsTest.php +++ b/packages/utils/test/phpunit/AssetsTest.php @@ -364,8 +364,8 @@ public function testProbablyEnqueueChunk() { $this->assets ->shouldReceive('enqueue') ->once() - ->with('vendor~admin', 'vendor~admin.js', $deps, false, 'script', true, 'all') - ->andReturn('vendor~admin'); + ->with('vendor-admin', 'vendor-admin.js', $deps, false, 'script', true, 'all') + ->andReturn('vendor-admin'); $method = new ReflectionMethod(AssetsImpl::class, 'probablyEnqueueChunk'); $method->setAccessible(true); @@ -398,7 +398,7 @@ public function testProbablyEnqueueChunkFailing() { $this->assets ->shouldReceive('enqueue') ->once() - ->with('vendor~admin', 'vendor~admin.js', $deps, false, 'script', true, 'all') + ->with('vendor-admin', 'vendor-admin.js', $deps, false, 'script', true, 'all') ->andReturnFalse(); $method = new ReflectionMethod(AssetsImpl::class, 'probablyEnqueueChunk'); @@ -861,8 +861,8 @@ public function testProbablyEnqueueComposerChunk() { $this->assets ->shouldReceive('enqueueComposer') ->once() - ->with('utils', 'vendor~index.js', $deps, 'script', true, 'all', 'vendor~' . PHPUNIT_ROOT_SLUG . '-utils') - ->andReturn('phpunit-vendor~admin'); + ->with('utils', 'vendor-index.js', $deps, 'script', true, 'all', 'vendor-' . PHPUNIT_ROOT_SLUG . '-utils') + ->andReturn('phpunit-vendor-admin'); $method = new ReflectionMethod(AssetsImpl::class, 'probablyEnqueueComposerChunk'); $method->setAccessible(true); @@ -904,7 +904,7 @@ public function testEnqueueComposer() { $this->assets->shouldReceive('useNonMinifiedSources')->andReturnTrue(); $self = $this->expectCallbacksReached(['devDirExists', 'isLernaRepo']); - redefine('is_dir', function($dir) use ($self, $packageDir) { + redefine('is_dir', function ($dir) use ($self, $packageDir) { $self->addCallbackReached('devDirExists', $dir === PHPUNIT_PATH . '/' . $packageDir . 'dev'); return true; }); @@ -970,7 +970,7 @@ public function testEnqueueComposerDevFolderNotExists() { $this->assets->shouldReceive('useNonMinifiedSources')->andReturnTrue(); $self = $this->expectCallbacksReached(['devDirExists', 'isLernaRepo']); - redefine('is_dir', function($dir) use ($self, $packageDir) { + redefine('is_dir', function ($dir) use ($self, $packageDir) { $self->addCallbackReached('devDirExists', $dir === PHPUNIT_PATH . '/' . $packageDir . 'dev'); return false; });