bundle[hash].js 返回 HTML - 未捕获的语法错误:意外的标记 '<'

问题描述 投票:0回答:1

Java 新手,如果这是一个愚蠢的问题,请原谅>我正在尝试在 Vercel 上部署我的网页,并且它正在成功构建,但是每当我访问该网页时,我都会得到

Uncaught SyntaxError: Unexpected token '<'

我相信这是因为我的bundle.js 在不应该返回html 的时候返回了html。当我使用 npm build 或 npxserve 在本地部署站点时,它工作正常,一切都在它应该在的地方。任何建议都会受到重视,因为我现在完全迷失了。该网站目前托管在 https://test-73dfyec7n-omni212121s-projects.vercel.app/

这是 rollup.config.js

import fs from 'fs';
import svelte from 'rollup-plugin-svelte';
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 sveltePreprocess from 'svelte-preprocess';
import typescript from '@rollup/plugin-typescript';
import posthtml from 'posthtml';
import { hash } from 'posthtml-hash';
import rimraf from 'rimraf';
import copy from 'rollup-plugin-copy';

const production = !process.env.ROLLUP_WATCH;

function serve() {
    let server;
    
    function toExit() {
        if (server) server.kill(0);
    }

    return {
        writeBundle() {
            if (server) return;
            server = require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], {
                stdio: ['ignore', 'inherit', 'inherit'],
                shell: true
            });

            process.on('SIGTERM', toExit);
            process.on('exit', toExit);
        }
    };
}

function hashAssets() {
    return {
        name: 'hash-assets',
        buildStart() {
            rimraf.sync('build');
        },
        writeBundle() {
            posthtml([
                hash({ path: 'build/' }),
            ])
            .process(fs.readFileSync('./build/index.html'))
            .then((result) => fs.writeFileSync('./build/index.html', result.html));
        }
    }
}

export default {
    input: 'src/main.ts',
    output: {
        sourcemap: !production,
        format: 'iife',
        name: 'app',
        file: 'build/bundle.[hash].js'
    },
    plugins: [
        copy({
            targets: [{
                src: 'public/*',
                dest: 'build/',
            }],
        }),
        svelte({
            // enable run-time checks when not in production
            dev: !production,
            // we'll extract any component CSS out into
            // a separate file - better for performance
            css: css => {
                css.write('bundle.[hash].css', !production);
            },
            preprocess: sveltePreprocess(),
        }),

        // If you have external dependencies installed from
        // npm, you'll most likely need these plugins. In
        // some cases you'll need additional configuration -
        // consult the documentation for details:
        // https://github.com/rollup/plugins/tree/master/packages/commonjs
        resolve({
            browser: true,
            dedupe: ['svelte']
        }),
        commonjs(),
        typescript({
            sourceMap: !production,
            inlineSources: !production
        }),

        // In dev mode, call `npm run start` once
        // the bundle has been generated
        !production && serve(),

        // Watch the `public` directory and refresh the
        // browser on changes when not in production
        !production && livereload('build'),

        // If we're building for production (npm run build
        // instead of npm run dev), minify
        production && terser(),

        production && hashAssets()
    ],
    watch: {
        clearScreen: false
    }
};

这是index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">

    <title>SWGoH Status</title>

    <link rel="icon" type="image/png" href="/favicon_chewie.png">
    <link rel="stylesheet" href="/build/bundle.[hash].css">

    <script defer="" src="/build/bundle.[hash].js"></script>
</head>

<body>
</body>
</html>


这是main.ts

import App from './App.svelte'

const app = new App({
    target: document.body,
})

export default app

我觉得我已经尝试了一切,但可能没有,

我尝试使用 npxserve 进行故障排除,我尝试了另一个主机,我尝试了绝对路径。

我期望bundle[hash]不返回HTML

javascript typescript vercel rollupjs
1个回答
0
投票

对不起大家,我分享了错误的链接

https://test-7-mauve-23.vercel.app/

© www.soinside.com 2019 - 2024. All rights reserved.