Can I tell browser-sync to always use one .html file? (for html5mode links)

前端 未结 3 1755
死守一世寂寞
死守一世寂寞 2021-02-01 23:46

I use browser-sync (https://github.com/shakyShane/browser-sync) in my gulp file for development purposes. I want to use html5mode within my angular app. For that server needs to

相关标签:
3条回答
  • 2021-02-02 00:16

    You can use https://github.com/tinganho/connect-modrewrite.

    var modRewrite  = require('connect-modrewrite');
    
    gulp.task('serve', function () {
        browserSync.init(null, {
            server: {
                baseDir: [APP_PATH],
                middleware: [
                    modRewrite([
                        '!\\.\\w+$ /index.html [L]'
                    ])
                ]
            }
        });
    
       // watch only for app specific codes;
       ...
    });
    
    0 讨论(0)
  • 2021-02-02 00:28

    From https://github.com/BrowserSync/browser-sync/issues/204#issuecomment-102623643

    First install connect-history-api-fallback:

    npm --save-dev install connect-history-api-fallback
    

    Then add it to your gulpfile.js:

    var historyApiFallback = require('connect-history-api-fallback');
    
    gulp.task('serve', function() {
      browserSync.init({
        server: {
          baseDir: "app",
          middleware: [ historyApiFallback() ]
        }
      });
    });
    
    0 讨论(0)
  • 2021-02-02 00:28

    In version 2.23.0 you can use single option, like this:

    gulp.task('serve', function () {
        browserSync.init(null, {
            server: {
                baseDir: [APP_PATH]
            },
            single: true
        });
    
        // watch only for app specific codes;
        ...
    });
    

    Reference: https://browsersync.io/docs/options#option-single

    0 讨论(0)
提交回复
热议问题