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}
'' + "\n" + baseWebpackConfig;
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
stdenv.mkDerivation {
inherit name;
@ -78,6 +85,7 @@ let
patchPhase = ''
ln -sf ${nodeSource}/node_modules .
cp ${webpackConfigFile} webpack.config.js
cp ${wandInit} wand.js
'';
shellHook = ''

View File

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