fix: ipfs

This commit is contained in:
Danil Kovtonyuk 2021-10-28 02:59:55 +10:00
parent 885a2a2f68
commit ad02c432a3
No known key found for this signature in database
GPG Key ID: E72A919BF08C3746
4 changed files with 80 additions and 5 deletions

41
app.html Normal file
View File

@ -0,0 +1,41 @@
<!DOCTYPE html>
<html {{ HTML_ATTRS }}>
<head {{ HEAD_ATTRS }}>
<script>
if (window.location.search) {
console.log('redirect')
window.location = window.location.origin + window.location.pathname
}
function addScript(src) {
const s = document.createElement('script')
s.setAttribute('src', src)
document.body.appendChild(s)
}
document.addEventListener('DOMContentLoaded', () => {
const ipfsPathRegExp = /^(\/(?:ipfs|ipns)\/[^/]+)/
const ipfsPathPrefix =
(window.location.pathname.match(ipfsPathRegExp) || [])[1] || ''
if (ipfsPathPrefix) {
const scripts = [...document.getElementsByTagName('script')]
for (let i = 0; i < scripts.length; i++) {
if (scripts[i].src) {
const source = new URL(scripts[i].src)
console.log('Loading', source.pathname)
const newSource =
window.location.origin + ipfsPathPrefix + source.pathname
addScript(newSource)
}
}
console.log('Finished')
}
})
</script>
{{ HEAD }}
</head>
<body {{ BODY_ATTRS }}>
{{ APP }}
</body>
</html>

View File

@ -5,6 +5,10 @@ export default {
// Target (https://go.nuxtjs.dev/config-target)
target: 'static',
generate: {
fallback: true,
},
// Global page headers (https://go.nuxtjs.dev/config-head)
head: {
title: 'Tornado.cash',
@ -37,7 +41,7 @@ export default {
css: ['@/assets/styles/app.scss'],
// Plugins to run before rendering page (https://go.nuxtjs.dev/config-plugins)
plugins: ['~/plugins/i18n.js'],
plugins: ['~/plugins/i18n.js', '~/plugins/ipfs.js'],
// Auto import components (https://go.nuxtjs.dev/config-components)
components: true,
@ -85,9 +89,21 @@ export default {
extend(config, ctx) {
config.output.publicPath = './_nuxt/'
},
// splitChunks: {
// commons: false
// }
html: {
minify: {
collapseWhitespace: true, // as @dario30186 mentioned
removeComments: true, // 👈 add this line
},
},
loaders: {
fontUrl: { limit: 25000 },
imgUrl: { limit: 15000 },
},
splitChunks: {
layouts: false,
pages: false,
commons: false,
},
},
router: {

View File

@ -6,7 +6,7 @@
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate",
"generate": "nuxt generate && cp dist/404.html dist/ipfs-404.html",
"lint:js": "eslint --ext .js,.vue --ignore-path .gitignore .",
"lint": "yarn lint:js",
"deploy-prod": "npm run generate && push-dir --allow-unclean --dir=dist --branch=gh-pages --cleanup --remote=temp"

18
plugins/ipfs.js Normal file
View File

@ -0,0 +1,18 @@
/* eslint-disable camelcase, no-undef */
export default (context, inject) => {
const ipfsPathRegExp = /^(\/(?:ipfs|ipns)\/[^/]+)/
const ipfsPathPrefix =
(window.location.pathname.match(ipfsPathRegExp) || [])[1] || ''
console.log('plugin __webpack_public_path__', __webpack_public_path__)
if (ipfsPathPrefix) {
__webpack_public_path__ = ipfsPathPrefix + '/_nuxt/'
if (typeof window !== 'undefined') {
context.app.router.history.base = ipfsPathPrefix || window.location.host
}
}
console.log('plugin __webpack_public_path__', __webpack_public_path__)
}