gatsby-plugin-material-ui
Version:
Gatsby plugin for Material-UI with built-in server-side rendering support
65 lines (49 loc) • 1.9 kB
JavaScript
;
var fs = require("fs");
var path = require("path");
var os = require("os");
var didRunAlready = false;
exports.onPreInit = function () {
if (didRunAlready) {
throw new Error("You can only have a single instance of gatsby-plugin-material-ui in your gatsby-config.js");
}
didRunAlready = true;
};
exports.pluginOptionsSchema = function (_ref) {
var Joi = _ref.Joi;
return Joi.object({
pathToEmotionCacheProps: Joi.string().default("").description("The path to the emotion cache props (See https://emotion.sh/docs/@emotion/cache#createcache).")
});
}; // Copy and past from https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-typography
exports.onPreBootstrap = function (_ref2, pluginOptions) {
var store = _ref2.store,
cache = _ref2.cache;
var program = store.getState().program;
var module;
if (pluginOptions.pathToEmotionCacheProps) {
module = "module.exports = require(\"" + (path.isAbsolute(pluginOptions.pathToEmotionCacheProps) ? pluginOptions.pathToEmotionCacheProps : path.join(program.directory, pluginOptions.pathToEmotionCacheProps)) + "\")";
if (os.platform() === "win32") {
module = module.split("\\").join("\\\\");
}
} else {
module = "module.exports = null";
}
var dir = cache.directory;
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
fs.writeFileSync(path.join(dir, "emotion-cache-props.js"), module);
}; // Copy and past from https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-typography
exports.onCreateWebpackConfig = function (_ref3) {
var actions = _ref3.actions,
cache = _ref3.cache;
var cacheFile = path.join(cache.directory, "emotion-cache-props.js");
var setWebpackConfig = actions.setWebpackConfig;
setWebpackConfig({
resolve: {
alias: {
"material-ui-plugin-cache-endpoint": cacheFile
}
}
});
};