GithubHelp home page GithubHelp logo

integration with SSG? about jetpack HOT 2 CLOSED

kidkarolis avatar kidkarolis commented on May 17, 2024
integration with SSG?

from jetpack.

Comments (2)

KidkArolis avatar KidkArolis commented on May 17, 2024

That's an interesting question.

You could indeed try to point to your 11ty generated index.html using the --html option. And in there, use a bit of handlebars syntax to include all the right assets:

{{#each assets.css}}
<link rel="stylesheet" href='{{{.}}}' />
{{/each}}

{{#if assets.runtime}}
<script type='text/javascript'>
{{{assets.runtime}}}
</script>
{{/if}}

{{#each assets.js}}
<script type='text/javascript' src='{{{.}}}' async></script>
{{/each}}

^ This is taken from the default template.

Alternatively, what jetpack does behind the scenes is it reads dist/manifest.json file to extract all the top level js/css to be included into the html, you could consider doing something similar:

jetpack/lib/options.js

Lines 207 to 251 in bd5e84e

function assets ({ root, production, modern, publicPath }) {
if (!production) {
return { js: [modern ? '/assets/bundle.js' : '/assets/bundle.legacy.js'], css: [], other: [], runtime: null }
}
const js = []
const css = []
const other = []
let runtime = null
let manifest
try {
manifest = JSON.parse(fs.readFileSync(path.join(root, modern ? 'manifest.json' : 'manifest.legacy.json')))
} catch (err) {
if (err.code === 'ENOENT') {
return { js, css, other, runtime }
}
throw err
}
Object.keys(manifest).forEach(asset => {
if (asset.endsWith('.js') && asset.startsWith('runtime~')) {
other.push(manifest[asset])
try {
runtime = String(fs.readFileSync(path.join(root, './' + manifest[asset].replace(publicPath, ''))))
// Since we inline the runtime at the root index html, correct the sourceMappingURL
runtime = runtime.replace('//# sourceMappingURL=', `//# sourceMappingURL=${publicPath}`)
} catch (err) {
if (err.code === 'ENOENT') {
return { js, css, other, runtime }
}
}
} else if (/^(bundle|vendor)[.~]?.*\.(js|css)$/.test(asset)) {
if (asset.endsWith('.js')) {
js.push(manifest[asset])
} else {
css.push(manifest[asset])
}
} else {
other.push(manifest[asset])
}
})
return { js, css, other, runtime }
}
.

from jetpack.

ckot avatar ckot commented on May 17, 2024

Cool beans. Glad to hear it's unlikely I'll need to do custom webpack stuff anymore. While it might take a while before I have time to convert from my custom stuff to using jetpack with one of the configurations you propose above, I'm closing this now. as I'm confident enough now, based on what you've shown, that I will be able to migrate to jetpack at some point soon.

from jetpack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.