Skip to content

Commit

Permalink
fix(workflow): only copies static files if dir exists
Browse files Browse the repository at this point in the history
Fixes double compile bug on startup of dev server with empty static dir
Double compile seems to be result of using glob instead of copying file by file
webpack-contrib/copy-webpack-plugin#602 (comment)
  • Loading branch information
chrishavekost committed Nov 16, 2021
1 parent ede2b45 commit fbb482c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
5 changes: 4 additions & 1 deletion packages/workflow/helpers/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ const resolveApp = (relativePath) => path.resolve(appDirectory, relativePath);

module.exports = {
// TODO: add other common paths
appNodeModules: resolveApp('node_modules')
project: resolveApp(''),
app: resolveApp('project/app'),
appNodeModules: resolveApp('node_modules'),
appStatic: resolveApp('project/app/static')
};
5 changes: 3 additions & 2 deletions packages/workflow/settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const fs = require('fs');
const yargs = require('yargs');
const getPort = require('get-port');
const Joi = require('joi');
const paths = require('../helpers/paths');

function argv() {
return yargs.argv;
Expand Down Expand Up @@ -43,7 +44,7 @@ const settings = {
ekkoServerPort: null,

app() {
return path.join(this.project(), 'project/app');
return paths.app;
},

include() {
Expand Down Expand Up @@ -153,7 +154,7 @@ const settings = {
},

project() {
return process.cwd();
return paths.project;
},

version() {
Expand Down
16 changes: 11 additions & 5 deletions packages/workflow/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const { existsSync } = require('fs');
Expand Down Expand Up @@ -170,19 +171,24 @@ const plugin = (settings) => {
baseConfig: {
extends: 'availity/workflow'
}
}),
})
]
};

if (fs.existsSync(paths.appStatic)) {
config.plugins.push(
new CopyWebpackPlugin({
patterns: [
{
context: `${settings.app()}/static`, // copy from this directory
context: paths.appStatic, // copy from this directory
from: '**/*', // copy all files
to: 'static', // copy into {output}/static folder
noErrorOnMissing: true
noErrorOnMissing: false
}
]
})
]
};
);
}

config.plugins.push(new ReactRefreshWebpackPlugin());

Expand Down
15 changes: 10 additions & 5 deletions packages/workflow/webpack.config.production.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
const webpack = require('webpack');
const babelPreset = require('./babel-preset');
const paths = require('./helpers/paths');
const resolveModule = require('./helpers/resolve-module');
const html = require('./html');
const loaders = require('./loaders');
Expand Down Expand Up @@ -259,20 +260,24 @@ const plugin = (settings) => {

new loaders.MiniCssExtractPlugin({
filename: 'css/[name]-[contenthash:8].chunk.css'
}),
})
]
};

if (fs.existsSync(paths.appStatic)) {
config.plugins.push(
new CopyWebpackPlugin({
patterns: [
{
context: `${settings.app()}/static`, // copy from this directory
context: paths.appStatic, // copy from this directory
from: '**/*', // copy all files
to: 'static', // copy into {output}/static folder
noErrorOnMissing: true
noErrorOnMissing: false
}
]
})
]
};
);
}

if (settings.isProduction() && !settings.shouldMimicStaging) {
config.optimization.minimizer.push(
Expand Down

0 comments on commit fbb482c

Please sign in to comment.