use special wand init to fix links

This commit is contained in:
notgne2 2019-12-12 13:17:54 -07:00
parent c488276de8
commit e0e3b70e78
2 changed files with 12 additions and 4 deletions

View File

@ -63,6 +63,13 @@ let
const ROUTES = ${builtins.toJSON routes} const ROUTES = ${builtins.toJSON routes}
'' + "\n" + baseWebpackConfig; '' + "\n" + baseWebpackConfig;
webpackConfigFile = pkgs.writeText "${name}-webpack-config" webpackConfig; webpackConfigFile = pkgs.writeText "${name}-webpack-config" webpackConfig;
wandInit = pkgs.writeText "wand.js" ''
document.body.innerHTML = '''
const sourceTarget = document.createElement('script')
sourceTarget.src = '/main.js'
document.body.appendChild(sourceTarget)
'';
in in
stdenv.mkDerivation { stdenv.mkDerivation {
inherit name; inherit name;
@ -78,6 +85,7 @@ let
patchPhase = '' patchPhase = ''
ln -sf ${nodeSource}/node_modules . ln -sf ${nodeSource}/node_modules .
cp ${webpackConfigFile} webpack.config.js cp ${webpackConfigFile} webpack.config.js
cp ${wandInit} wand.js
''; '';
shellHook = '' shellHook = ''

View File

@ -27,7 +27,7 @@ module.exports =
}, },
plugins: [ plugins: [
new HtmlWebpackPlugin(), new HtmlWebpackPlugin(),
new CopyPlugin([{ from: 'data', to: 'data' }]), new CopyPlugin([{ from: 'data', to: 'data' }, { from: 'wand.js', to: 'wand.js' }]),
new PrerenderSPAPlugin({ new PrerenderSPAPlugin({
staticDir: path.join(__dirname, 'dist'), staticDir: path.join(__dirname, 'dist'),
routes: ROUTES, routes: ROUTES,
@ -40,9 +40,9 @@ module.exports =
postProcess(renderedRoute) { postProcess(renderedRoute) {
const dom = new JSDOM(renderedRoute.html, { runScripts: 'outside-only' }) const dom = new JSDOM(renderedRoute.html, { runScripts: 'outside-only' })
dom.window.eval(` dom.window.eval(`
const sourceTarget = document.createElement('script') const wandTarget = document.createElement('script')
sourceTarget.src = '/main.js' wandTarget.src = '/wand.js'
document.body.appendChild(sourceTarget) document.body.appendChild(wandTarget)
`) `)
return { return {
...renderedRoute, ...renderedRoute,