Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External prod stylesheet #1161

Merged
merged 3 commits into from
May 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"build-ui": "cd ui && yarn install && yarn build",
"cypress-open": "cd proxy && yarn cypress-open",
"cypress-run": "cd proxy && yarn cypress-run",
"copy-build": "mkdir -p build && cp -R root/dist/* build/ && cp -R legacy/dist/assets build/",
"copy-build": "mkdir -p build && cp -R root/dist/* build/ && cp -R legacy/dist/assets build/ && cp ui/dist/static/css/main.*.css.map build/assets/css/ui.css.map && cp ui/dist/static/css/main.*.css build/assets/css/ui.css",
"release": "cd ui && yarn run release",
"serve": "cd proxy && yarn start",
"start": "yarn serve",
Expand Down
71 changes: 12 additions & 59 deletions ui/config-overrides.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,4 @@
const webpack = require("webpack");
const path = require("path");
const { edit, remove, getPaths } = require("@rescripts/utilities");
Copy link
Contributor

@squidsoup squidsoup May 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @rescripts/utilities dependency can be dropped, although you may find it useful if we need to reconfigure mini-css-extract-plugin.


const addLoaders = (loaderOptions = {}) => (config) => {
const sassRegex = /\.(sass|scss)$/;

//Matchers to find the array of rules and sass-file loader
const loadersMatcher = (inQuestion) =>
inQuestion.rules &&
inQuestion.rules.find((rule) => Array.isArray(rule.oneOf));
const sassMatcher = (inQuestion) =>
inQuestion.test && inQuestion.test.toString() === sassRegex.toString();

//Return set of loaders needed to process sass files
const getStyleLoader = () => [
{
loader: "style-loader",
},
{
loader: require.resolve("css-loader"),
options: { importLoaders: 2 },
},
{
loader: "sass-loader",
options: {
sourceMap: process.env.NODE_ENV !== "production",
},
},
];

//Transformer function
const transform = (match) => ({
...match,
rules: [
...match.rules.filter((rule) => !Array.isArray(rule.oneOf)),
{
oneOf: [
{
test: sassRegex,
exclude: [path.resolve(__dirname, "node_modules")],
use: getStyleLoader(),
sideEffects: true,
},
...match.rules.find((rule) => Array.isArray(rule.oneOf)).oneOf,
],
},
],
});

//Remove the set of already configured loaders to process sass files
config = remove(getPaths(sassMatcher, config), config);

//Add our set of newly configured loaders
config = edit(transform, getPaths(loadersMatcher, config), config);

return config;
};

module.exports = {
webpack: function (config, env) {
Expand All @@ -65,7 +8,18 @@ module.exports = {
filename: "ui.js",
libraryTarget: "umd",
};
delete config.optimization;
config.optimization = {
splitChunks: {
cacheGroups: {
styles: {
name: "styles",
test: /\.css$/,
chunks: "all",
enforce: true,
},
},
},
};
config.plugins = config.plugins.filter(
(plugin) => plugin.constructor.name !== "HtmlWebpackPlugin"
);
Expand All @@ -74,7 +28,6 @@ module.exports = {
maxChunks: 1,
})
);
config = addLoaders()(config);
return config;
},
devServer: function (configFunction) {
Expand Down
1 change: 0 additions & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
]
},
"devDependencies": {
"@rescripts/utilities": "0.0.7",
"css-loader": "3.5.3",
"enzyme": "3.11.0",
"enzyme-adapter-react-16": "1.15.2",
Expand Down
14 changes: 13 additions & 1 deletion ui/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,23 @@ sagaMiddleware.run(rootSaga);

const Root = () => {
console.info(`${appName} ${appVersion} (${process.env.REACT_APP_GIT_SHA}).`);
let styles;
if (process.env.NODE_ENV === "production") {
styles = (
<link
href={`${process.env.REACT_APP_BASENAME}/assets/css/ui.css`}
rel="stylesheet"
/>
);
}
return (
<Provider store={store}>
<ConnectedRouter history={history}>
<React.StrictMode>
<App />
<>
{styles}
<App />
</>
</React.StrictMode>
</ConnectedRouter>
</Provider>
Expand Down
9 changes: 1 addition & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2499,13 +2499,6 @@
redux-thunk "^2.3.0"
reselect "^4.0.0"

"@rescripts/[email protected]":
version "0.0.7"
resolved "https://registry.yarnpkg.com/@rescripts/utilities/-/utilities-0.0.7.tgz#fac07a981fcc9674c9b55cedb9da67f03dadda52"
integrity sha512-kdk4qvNYXOH7mVJCP/URokp5J+1HCR+tT1Zgtp8X9hLywn6WoKlU/tQ2ECB/NPOHrZjp/DGXWeQBAchLXV8q2w==
dependencies:
ramda "^0.26.0"

"@samverschueren/stream-to-observable@^0.3.0":
version "0.3.0"
resolved "https://registry.yarnpkg.com/@samverschueren/stream-to-observable/-/stream-to-observable-0.3.0.tgz#ecdf48d532c58ea477acfcab80348424f8d0662f"
Expand Down Expand Up @@ -13163,7 +13156,7 @@ railroad-diagrams@^1.0.0:
resolved "https://registry.yarnpkg.com/railroad-diagrams/-/railroad-diagrams-1.0.0.tgz#eb7e6267548ddedfb899c1b90e57374559cddb7e"
integrity sha1-635iZ1SN3t+4mcG5Dlc3RVnN234=

[email protected], ramda@^0.26.0:
[email protected]:
version "0.26.1"
resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.26.1.tgz#8d41351eb8111c55353617fc3bbffad8e4d35d06"
integrity sha512-hLWjpy7EnsDBb0p+Z3B7rPi3GDeRG5ZtiI33kJhTt+ORCd38AbAIjB/9zRIUoeTbE/AVX5ZkU7m6bznsvrf8eQ==
Expand Down