Skip to content

Commit

Permalink
ci: move to webpack 5 (flyteorg#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
anrusina committed Mar 15, 2022
1 parent 3a24eec commit 5c6b833
Show file tree
Hide file tree
Showing 5 changed files with 1,391 additions and 1,441 deletions.
3 changes: 3 additions & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module.exports = {
core: {
builder: 'webpack5'
},
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
addons: ['@storybook/addon-links', '@storybook/addon-essentials', '@storybook/addon-interactions'],
framework: '@storybook/react',
Expand Down
153 changes: 77 additions & 76 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,100 +18,101 @@ app.get(`${env.BASE_URL}/healthz`, (_req, res) => res.status(200).send());
app.use(corsProxy(`${env.BASE_URL}${env.CORS_PROXY_PREFIX}`));

if (typeof applyMiddleware === 'function') {
console.log('Found middleware plugins, applying...');
applyMiddleware(app);
console.log('Found middleware plugins, applying...');
applyMiddleware(app);
}

if (process.env.NODE_ENV === 'production') {
const path = require('path');
const expressStaticGzip = require('express-static-gzip');
const serverRenderer = require('./dist/server.js').default;
const clientStats = require('./dist/client-stats.json');
const distPath = path.join(__dirname, 'dist');
app.use(
`${env.BASE_URL}/assets`,
expressStaticGzip(distPath, {
maxAge: '1d'
})
);
app.use(serverRenderer({ clientStats, currentDirectory: __dirname }));
const path = require('path');
const expressStaticGzip = require('express-static-gzip');
const serverRenderer = require('./dist/server.js').default;
const clientStats = require('./dist/client-stats.json');
const distPath = path.join(__dirname, 'dist');
app.use(
`${env.BASE_URL}/assets`,
expressStaticGzip(distPath, {
maxAge: '1d'
})
);
app.use(serverRenderer({ clientStats, currentDirectory: __dirname }));
} else {
process.env.NODE_ENV = 'development';
console.log('Server is running in development mode');
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleWare = require('webpack-hot-middleware');
const webpackHotServerMiddleware = require('webpack-hot-server-middleware');
process.env.NODE_ENV = 'development';
console.log('Server is running in development mode');
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleWare = require('webpack-hot-middleware');
const webpackHotServerMiddleware = require('webpack-hot-server-middleware');

require('ts-node').register({
compilerOptions: { module: 'commonjs' },
cacheDirectory: '/tmp'
});
const { default: configs, clientConfig } = require('./webpack.config');
require('ts-node').register({
compilerOptions: { module: 'commonjs' },
cacheDirectory: '/tmp'
});
const { default: configs, clientConfig } = require('./webpack.config');

const compiler = webpack(
configs.map(c =>
Object.assign({}, c, {
mode: 'development'
})
)
);
const clientCompiler = compiler.compilers.find(
({ name }) => name === 'client'
);
const compiler = webpack(
configs.map(c =>
Object.assign({}, c, {
mode: 'development'
})
)
);
const clientCompiler = compiler.compilers.find(({ name }) => name === 'client');

const devMiddleware = webpackDevMiddleware(compiler, {
serverSideRender: true,
noInfo: true,
publicPath: clientConfig.output.publicPath,
serverRenderer: true
});
const devMiddleware = webpackDevMiddleware(compiler, {
serverSideRender: true,
publicPath: clientConfig.output.publicPath
});

app.use(devMiddleware);
app.use(webpackHotMiddleWare(clientCompiler));
app.use(
webpackHotServerMiddleware(compiler, {
serverRendererOptions: {
// Send client compiler FS for reading index.html for emitted assets
fileSystem: clientCompiler.outputFileSystem,
// Helps with finding the output folder in memory-fs
currentDirectory: __dirname
}
})
);
app.use(devMiddleware);
app.use(webpackHotMiddleWare(clientCompiler));
app.use(
webpackHotServerMiddleware(compiler, {
serverRendererOptions: {
// Send client compiler FS for reading index.html for emitted assets
fileSystem: clientCompiler.outputFileSystem,
// Helps with finding the output folder in memory-fs
currentDirectory: __dirname
}
})
);
}

/* Set ADMIN_API_USE_SSL to https for CORS support */
let server;
const port = process.env.PORT || 3000;
if(env.ADMIN_API_USE_SSL == "https"){
const fs = require('fs')
const https = require('https')
var privateKey = fs.readFileSync('script/server.key');
var certificate = fs.readFileSync('script/server.crt');
if (env.ADMIN_API_USE_SSL == 'https') {
const fs = require('fs');
const https = require('https');
var privateKey = fs.readFileSync('script/server.key');
var certificate = fs.readFileSync('script/server.crt');

server = https.createServer({
server = https
.createServer(
{
key: privateKey,
cert: certificate
}, app).listen(port);
console.log(`Server started with SSL: https://localhost:${port}/`);
},
app
)
.listen(port);
console.log(`Server started with SSL: https://localhost:${port}/`);
} else {
server = app.listen(port, error => {
if (error) {
throw error;
}
console.log(`Server started: http://localhost:${port}/`);
});
server = app.listen(port, error => {
if (error) {
throw error;
}
console.log(`Server started: http://localhost:${port}/`);
});
}

process.on('SIGTERM', () => {
console.info('SIGTERM signal received. Shutting down.');
server.close(error => {
if (error) {
console.error('Failed to close server:', error);
process.exit(1);
}
console.log('Server closed');
process.exit(0);
});
console.info('SIGTERM signal received. Shutting down.');
server.close(error => {
if (error) {
console.error('Failed to close server:', error);
process.exit(1);
}
console.log('Server closed');
process.exit(0);
});
});
48 changes: 22 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,18 @@
"@storybook/addon-essentials": "^6.4.19",
"@storybook/addon-interactions": "^6.4.19",
"@storybook/addon-links": "^6.4.19",
"@storybook/builder-webpack5": "^6.4.19",
"@storybook/manager-webpack5": "^6.4.19",
"@storybook/react": "^6.4.19",
"@storybook/testing-library": "^0.0.9",
"@testing-library/jest-dom": "^5.5.0",
"@testing-library/react": "^10.0.3",
"@types/cheerio": "^0.22.2",
"@types/compression-webpack-plugin": "^2.0.1",
"@types/compression-webpack-plugin": "^9.1.1",
"@types/d3-shape": "^1.2.6",
"@types/debug": "^0.0.30",
"@types/dom-helpers": "^3.4.1",
"@types/express": "^4.17.2",
"@types/html-webpack-plugin": "^2.28.0",
"@types/jest": "^26.0.0",
"@types/js-yaml": "^3.10.1",
"@types/linkify-it": "^2.1.0",
Expand All @@ -115,7 +116,7 @@
"@types/memoize-one": "^4.1.0",
"@types/memory-fs": "^0.3.0",
"@types/moment-timezone": "^0.5.13",
"@types/node": "^14.0.10",
"@types/node": "^14.14.31",
"@types/object-hash": "^1.2.0",
"@types/pure-render-decorator": "^0.2.27",
"@types/react": "^16.9.34",
Expand All @@ -129,14 +130,11 @@
"@types/react-virtualized": "^9.21.4",
"@types/serve-static": "^1.7.31",
"@types/shallowequal": "^0.2.3",
"@types/webpack": "^4.1.3",
"@types/webpack-dev-middleware": "^1.9.2",
"@types/webpack-env": "^1.13.1",
"@types/webpack-hot-middleware": "^2.15.0",
"@types/webpack-hot-middleware": "^2.25.6",
"@typescript-eslint/eslint-plugin": "^4.9.1",
"@typescript-eslint/parser": "^4.9.1",
"@xstate/react": "^1.0.0",
"add-asset-html-webpack-plugin": "^2.1.3",
"add-asset-html-webpack-plugin": "^3.2.0",
"autoprefixer": "^8.3.0",
"axios": "^0.21.2",
"axios-mock-adapter": "^1.16.0",
Expand All @@ -145,7 +143,7 @@
"babel-loader": "^8.2.3",
"camelcase-keys": "^6.1.1",
"classnames": "^2.3.1",
"compression-webpack-plugin": "^3.0.1",
"compression-webpack-plugin": "^9.2.0",
"contrast": "^1.0.1",
"copy-to-clipboard": "^3.0.8",
"cronstrue": "^1.31.0",
Expand All @@ -158,11 +156,10 @@
"eslint-plugin-jest": "^24.1.3",
"eslint-plugin-react": "^7.21.5",
"eslint-plugin-react-hooks": "^4.2.0",
"favicons-webpack-plugin": "2.0",
"file-loader": "^1.1.11",
"fork-ts-checker-webpack-plugin": "^4.0.3",
"html-webpack-externals-plugin": "^3.7.0",
"html-webpack-plugin": "^3.2.0",
"favicons": "^6.2.0",
"favicons-webpack-plugin": "^5.0.2",
"fork-ts-checker-webpack-plugin": "^7.2.1",
"html-webpack-plugin": "^5.5.0",
"husky": "^4.2.5",
"identity-obj-proxy": "^3.0.0",
"intersection-observer": "^0.7.0",
Expand Down Expand Up @@ -191,26 +188,25 @@
"react-router-dom": "^5.0.1",
"react-test-renderer": "^16.9.0",
"react-virtualized": "^9.21.1",
"resolve-url-loader": "^2.3.0",
"resolve-url-loader": "^5.0.0",
"semantic-release": "^17.2.3",
"shallowequal": "^1.1.0",
"snakecase-keys": "^3.1.0",
"source-map-loader": "^0.2.1",
"source-map-loader": "^3.0.1",
"ts-jest": "^26.3.0",
"ts-loader": "^6.2.1",
"ts-loader": "^9.2.6",
"ts-node": "^8.0.2",
"typescript": "^4.1.2",
"uglifyjs-webpack-plugin": "^1.2.5",
"url-search-params": "^0.10.0",
"use-react-router": "^1.0.7",
"webpack": "^4.41.5",
"webpack-cli": "^3.2.1",
"webpack-dev-middleware": "^3.5.1",
"webpack-hot-middleware": "^2.24.3",
"webpack-hot-server-middleware": "^0.5.0",
"webpack-node-externals": "^1.7.2",
"webpack-plugin-serve": "^1.5.0",
"webpack-stats-plugin": "^0.2.1",
"webpack": "^5.68.0",
"webpack-cli": "^4.9.2",
"webpack-dev-middleware": "^5.3.1",
"webpack-hot-middleware": "^2.25.1",
"webpack-hot-server-middleware": "^0.6.1",
"webpack-node-externals": "^3.0.0",
"webpack-plugin-serve": "^1.6.0",
"webpack-stats-plugin": "^1.0.3",
"xstate": "^4.11.0"
},
"resolutions": {
Expand Down
Loading

0 comments on commit 5c6b833

Please sign in to comment.