-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The original index.html should not be modfied #5
Comments
The idea of the current implementation is to modify the built index. So if your build regime takes some I agree that the plugin should do a better job of writing artifacts. It currently abuses the Rollup API somewhat to accomplish its goals. PRs very welcome. |
This is what I did but I got:
|
I don't know all that much about svelte routify starter template can you provide more info? |
It's a svelte template which uses rollup. Here import svelte from 'rollup-plugin-svelte-hot';
import Hmr from 'rollup-plugin-hot'
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import livereload from 'rollup-plugin-livereload';
import { terser } from 'rollup-plugin-terser';
import { copySync, removeSync } from 'fs-extra'
import { spassr } from 'spassr'
import getConfig from '@roxi/routify/lib/utils/config'
import autoPreprocess from 'svelte-preprocess'
import postcssImport from 'postcss-import'
import { injectManifest } from 'rollup-plugin-workbox'
const { distDir } = getConfig()
const assetsDir = 'assets'
const buildDir = `assets/build`
const isNollup = !!process.env.NOLLUP
const production = !process.env.ROLLUP_WATCH;
// clear previous builds
removeSync(distDir)
removeSync(buildDir)
const serve = () => ({
writeBundle: async () => {
const options = {
assetsDir,
entrypoint: `${assetsDir}/__app.html`,
script: `${buildDir}/main.js`
}
spassr({ ...options, port: 5000 })
spassr({ ...options, ssr: true, port: 5005, ssrOptions: { inlineDynamicImports: true, dev: true } })
}
})
const copyToDist = () => ({ writeBundle() { copySync(assetsDir, distDir) } })
export default {
preserveEntrySignatures: false,
input: [`src/main.js`],
output: {
sourcemap: true,
format: 'esm',
dir: buildDir
},
plugins: [
svelte({
dev: !production, // run-time checks
// Extract component CSS — better performance
css: css => css.write(`${buildDir}/bundle.css`),
hot: isNollup,
preprocess:
autoPreprocess({
postcss: { plugins: [postcssImport()] },
defaults: { style: 'postcss' }
})
}),
// resolve matching modules from current working directory
resolve({
browser: true,
dedupe: importee => !!importee.match(/svelte(\/|$)/)
}),
commonjs(),
production && terser(),
!production && !isNollup && serve(),
!production && !isNollup && livereload(distDir), // refresh entire window when code is updated
!production && isNollup && Hmr({ inMemory: true, public: assetsDir, }), // refresh only updated code
{
transform: code => code.replace('process.env.NODE_ENV', `"${process.env.NODE_ENV}"`)
},
injectManifest({
globDirectory: assetsDir,
globPatterns: ['**/*.{js,css,svg}', '__app.html'],
swSrc: `src/sw.js`,
swDest: `assets/build/serviceworker.js`,
maximumFileSizeToCacheInBytes: 10000000, // 10 MB,
mode: 'production'
}),
production && copyToDist(),
],
watch: {
clearScreen: false,
buildDelay: 100,
}
} I added your plugin in the plugin array with the options: production && modulepreload({ prefix: 'build',
index: `dist/__app.html`, }) to modify the built __app.html file but I get:
Because the plugin begins its job before the index file has been built, apparently. |
yeah probably it's happening before svelte Unfortunately I don't have time to work on this at the moment, but PRs are welcome 👍 |
Only the build output should contain the generated preloads.
Is there a setting for that? Why does the plugin touch the index.html in the first place?
The text was updated successfully, but these errors were encountered: