grunt-connect: serve files with base url added

只谈情不闲聊 提交于 2019-12-04 18:34:17

问题


I am developing jekyll-based site using grunt as my task manager. I am using grunt-contrib-connect to serve my files locally for development because of its livereload functionality. Those files are accessible in the browser at: http://localhost:8081/index.html

On my server, my files are located within a sub-directory, so have a base url prepended to all urls: http://path.to.server/mysite/index.html

I cannot figure out a way to simulate the base url on my local dev setup with grunt-connect. Without that, I don't know how to reference my css or js files without the urls being invalid on either the server or my dev box.

I know that jekyll's serve function can add a base url, but it does not give me the livereload functionality.

Any tips?


回答1:


If you use Grunt Jekyll to run the Jekyll build commands it has a raw option that lets you append things to your _config.yml. That way you can effectively remove {{ site.baseurl }} for local development

jekyll: {
    development: {
        options: {
            config: '_config.yml',
            raw: 'baseurl: '
        }
    },
    production: {
        options: {
            config: '_config.yml'
        }
    }
},



回答2:


I answered a similar question at: https://stackoverflow.com/a/20864020/79790

Basically, you can set open in your livereload options to be the base URL for the server you want.



来源:https://stackoverflow.com/questions/21032405/grunt-connect-serve-files-with-base-url-added

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!