1

我正在为我的苗条应用程序使用汇总。我将包rollup-plugin-serve从 npm 安装给我们,historyApiFallback这样我就可以在我的 spa 应用程序中提供任何 url。

https://github.com/thgh/rollup-plugin-serve

我的配置如下所示:

import serve from 'rollup-plugin-serve'

serve({
   contentBase: 'dist',
   port: 5000,
   historyApiFallback: true,
   historyApiFallback: 'index.html'
}),

这是我的完整rollup.config.js

import commonjs from 'rollup-plugin-commonjs';
import livereload from 'rollup-plugin-livereload';
import postcss from 'rollup-plugin-postcss';
import resolve from 'rollup-plugin-node-resolve';
import svelte from 'rollup-plugin-svelte';
import {terser} from 'rollup-plugin-terser';
import svelte_preprocess_postcss from 'svelte-preprocess-postcss';
import serve from 'rollup-plugin-serve'

const production = !process.env.ROLLUP_WATCH;
export default {
   input: 'src/main.js',
   output: {
      format: 'iife',
      sourcemap: true,
      name: 'app',
      file: 'dist/main.js',
   },
   plugins: [
      svelte({
         dev: !production,
         preprocess: {
            style: svelte_preprocess_postcss(),
         },
         css: css => {
            css.write('dist/components.css');
         },
      }),
      resolve(),
      commonjs(),
      postcss({
         extract: true,
      }),
      serve({
         contentBase: 'dist',
         host: 'localhost',
         port: 5000,
         historyApiFallback: true
      }),
      !production && livereload('dist'),
      production && terser(),
   ],
};

但是这段代码不起作用。当我发球时,localhost:5000/solutions/technic我仍然收到 404 Not Found 错误。

有什么想法吗?

4

1 回答 1

2

尝试使用'/index.html'而不是'index.html',例如:

serve({
   contentBase: 'dist',
   port: 5000,
   historyApiFallback: '/index.html'
}),

或使用historyApiFallback: true/index.html用作默认值):

serve({
   contentBase: 'dist',
   port: 5000,
   historyApiFallback: true
}),
于 2019-09-03T17:28:35.220 回答