@@ -2,7 +2,7 @@ const webpack = require('webpack');
22const { resolve, join } = require ( 'path' ) ;
33const { existsSync } = require ( 'fs' ) ;
44const { isInstalledVersionPreactXOrAbove } = require ( './utils' ) ;
5- const merge = require ( 'webpack-merge' ) ;
5+ const { merge } = require ( 'webpack-merge' ) ;
66const { filter } = require ( 'minimatch' ) ;
77const SizePlugin = require ( 'size-plugin' ) ;
88const CopyWebpackPlugin = require ( 'copy-webpack-plugin' ) ;
@@ -78,6 +78,22 @@ async function clientConfig(env) {
7878 ] ;
7979 }
8080
81+ let copyPatterns = [
82+ existsSync ( source ( 'manifest.json' ) ) && { from : 'manifest.json' } ,
83+ // copy any static files
84+ existsSync ( source ( 'assets' ) ) && { from : 'assets' , to : 'assets' } ,
85+ // copy sw-debug
86+ ! isProd && {
87+ from : resolve ( __dirname , '../../resources/sw-debug.js' ) ,
88+ to : 'sw-debug.js' ,
89+ } ,
90+ // copy files from static to build directory
91+ existsSync ( source ( 'static' ) ) && {
92+ from : resolve ( source ( 'static' ) ) ,
93+ to : '.' ,
94+ } ,
95+ ] . filter ( Boolean ) ;
96+
8197 return {
8298 entry : entry ,
8399 output : {
@@ -130,25 +146,12 @@ async function clientConfig(env) {
130146 new PushManifestPlugin ( env ) ,
131147 ...( await renderHTMLPlugin ( env ) ) ,
132148 ...getBabelEsmPlugin ( env ) ,
133- new CopyWebpackPlugin (
134- [
135- existsSync ( source ( 'manifest.json' ) ) && { from : 'manifest.json' } ,
136- // copy any static files
137- existsSync ( source ( 'assets' ) ) && { from : 'assets' , to : 'assets' } ,
138- // copy sw-debug
139- ! isProd && {
140- from : resolve ( __dirname , '../../resources/sw-debug.js' ) ,
141- to : 'sw-debug.js' ,
142- } ,
143- // copy files from static to build directory
144- existsSync ( source ( 'static' ) ) && {
145- from : resolve ( source ( 'static' ) ) ,
146- to : '.' ,
147- } ,
148- ] . filter ( Boolean )
149- ) ,
149+ copyPatterns . length !== 0 &&
150+ new CopyWebpackPlugin ( {
151+ patterns : copyPatterns ,
152+ } ) ,
150153 ...swInjectManifest ,
151- ] ,
154+ ] . filter ( Boolean ) ,
152155 } ;
153156}
154157
@@ -165,13 +168,7 @@ function getBabelEsmPlugin(config) {
165168 beforeStartExecution : ( plugins , newConfig ) => {
166169 const babelPlugins = newConfig . plugins ;
167170 newConfig . plugins = babelPlugins . filter ( plugin => {
168- if (
169- Array . isArray ( plugin ) &&
170- plugin [ 0 ] . indexOf ( 'fast-async' ) !== - 1
171- ) {
172- return false ;
173- }
174- return true ;
171+ return ! ( Array . isArray ( plugin ) && plugin [ 0 ] . includes ( 'fast-async' ) ) ;
175172 } ) ;
176173 plugins . forEach ( plugin => {
177174 if (
@@ -319,7 +316,7 @@ function isDev(config) {
319316 } ;
320317}
321318
322- module . exports = async function ( env ) {
319+ module . exports = async function createClientConfig ( env ) {
323320 return merge (
324321 baseConfig ( env ) ,
325322 await clientConfig ( env ) ,
0 commit comments