gatsby-plugin-loadable-components-ssr
Version:
Server-side rendering loadable components in your gatsby application
64 lines (50 loc) • 1.93 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.pluginOptionsSchema = exports.onCreateWebpackConfig = exports.onCreateBabelConfig = void 0;
var _path = _interopRequireDefault(require("path"));
var _webpackPlugin = _interopRequireDefault(require("@loadable/webpack-plugin"));
var _constant = require("./constant");
const isWin = process.platform === "win32";
const onCreateWebpackConfig = ({
actions,
stage
}) => {
// for builds we point to stats file that will be produced by `build-javascript`
// for develop we point to empty mocked stats, just so gatsby-ssr continue to work
const fullPath = stage === `build-javascript` || stage === `build-html` ? _path.default.join(process.cwd(), _constant.LOADABLE_STATS_FILE_PATH) : require.resolve(`./develop-stats.json`);
const config = {
resolve: {
alias: {
"gatsby-plugin-loadable-components-ssr-stats-file": fullPath
}
}
};
if (stage === "build-javascript") {
config.plugins = [new _webpackPlugin.default({
filename: fullPath,
writeToDisk: true,
outputAsset: !isWin
})];
}
actions.setWebpackConfig(config);
};
exports.onCreateWebpackConfig = onCreateWebpackConfig;
const onCreateBabelConfig = ({
actions
}) => {
actions.setBabelPlugin({
name: "@loadable/babel-plugin"
});
};
exports.onCreateBabelConfig = onCreateBabelConfig;
const pluginOptionsSchema = ({
Joi
}) => {
return Joi.object({
useHydrate: Joi.boolean().description(`Whether replaceHydrateFunction should call ReactDOM.hydrate or ReactDOM.render.
Defaults to ReactDOM.render on develop and ReactDOM.hydrate on build`),
preloadTags: Joi.boolean().default(true).description(`Whether to enable preload links to the chunks created by loadable. Defaults to true.`)
});
};
exports.pluginOptionsSchema = pluginOptionsSchema;