Skip to content

Commit

Permalink
Load the styles in dev.
Browse files Browse the repository at this point in the history
  • Loading branch information
huwshimi committed Jun 3, 2020
1 parent 2656069 commit 3f58992
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 14 deletions.
4 changes: 0 additions & 4 deletions legacy/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ module.exports = {
new CopyWebpackPlugin([
{ from: path.resolve(__dirname, "./src/assets"), to: "assets" },
]),
new MiniCssExtractPlugin({
// This file is relative to output.path above.
filename: "assets/css/[name].[contenthash].css",
}),
new webpack.ProvidePlugin({
"window.jQuery": "jquery",
}),
Expand Down
6 changes: 6 additions & 0 deletions legacy/webpack.dev.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const merge = require("webpack-merge");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const path = require("path");

const common = require("./webpack.common.js");
Expand All @@ -14,4 +15,9 @@ module.exports = merge(common, {
writeToDisk: true,
},
devtool: "eval-source-map",
plugins: [
new MiniCssExtractPlugin({
filename: "assets/css/[name].css",
}),
],
});
8 changes: 7 additions & 1 deletion legacy/webpack.prod.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const merge = require("webpack-merge");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");

const common = require("./webpack.common.js");
Expand All @@ -10,5 +11,10 @@ module.exports = merge(common, {
optimization: {
minimizer: [new OptimizeCSSAssetsPlugin({})],
},
plugins: [new CleanWebpackPlugin()],
plugins: [
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: "assets/css/[name].[contenthash].css",
}),
],
});
20 changes: 12 additions & 8 deletions root/src/root-application.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ window.addEventListener("single-spa:before-app-change", (evt) => {
} = evt.detail.newAppStatuses;
const uiStylesheet = document.querySelector(".ui-stylesheet");
const legacyStylesheet = document.querySelector(".legacy-stylesheet");
if (ui === "MOUNTED") {
uiStylesheet.disabled = false;
} else {
uiStylesheet.disabled = true;
if (uiStylesheet) {
if (ui === "MOUNTED") {
uiStylesheet.disabled = false;
} else {
uiStylesheet.disabled = true;
}
}
if (legacy === "MOUNTED") {
legacyStylesheet.disabled = false;
} else {
legacyStylesheet.disabled = true;
if (legacyStylesheet) {
if (legacy === "MOUNTED") {
legacyStylesheet.disabled = false;
} else {
legacyStylesheet.disabled = true;
}
}
});

Expand Down
2 changes: 2 additions & 0 deletions root/webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ module.exports = merge(common, {
template: path.resolve(__dirname, "src", "index.ejs"),
inject: false,
templateParameters: {
legacyStylesheet: `/MAAS/assets/css/maas.css`,
publicPath,
uiStylesheet: null,
},
}),
],
Expand Down
5 changes: 4 additions & 1 deletion root/webpack.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ const publicPath = "/MAAS/r/";

const getStylesheet = (dir) => {
const outputPath = path.resolve(process.cwd(), dir);
return fs.readdirSync(outputPath).find((file) => file.endsWith(".css"));
const stylesheet = fs
.readdirSync(outputPath)
.find((file) => file.endsWith(".css"));
return `${publicPath}assets/css/${stylesheet}`;
};

module.exports = merge(common, {
Expand Down

0 comments on commit 3f58992

Please sign in to comment.