最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Jade - set base directory depending on environment - Stack Overflow

programmeradmin0浏览0评论

I have a jade page, and the first thing I do is set a variable which determines the base directory used by all links.

if ! base
  base = '/klog/'
  // base = '/website-clear/klog/'

This is actually for a github page, so every time I render the page to html, I have to remember to change the base, and then change it back again for local editing.

There must be a better way of doing it. Currently I am thinking to have an untracked file in the local copy, that includes the base - but is that really necessary?

What is the best way to handle this issue?

I have a jade page, and the first thing I do is set a variable which determines the base directory used by all links.

if ! base
  base = '/klog/'
  // base = '/website-clear/klog/'

This is actually for a github page, so every time I render the page to html, I have to remember to change the base, and then change it back again for local editing.

There must be a better way of doing it. Currently I am thinking to have an untracked file in the local copy, that includes the base - but is that really necessary?

What is the best way to handle this issue?

Share Improve this question edited Sep 16, 2012 at 22:08 Billy Moon asked Sep 16, 2012 at 20:45 Billy MoonBilly Moon 58.6k27 gold badges148 silver badges244 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

A more robust solution would be checking for environment variables. Have NODE_ENV=production set on the production server, and do not set it on the dev server.

Then in your jade template, render different paths if the environment variable exists.

if 'production' == process.env.NODE_ENV
    - base = '/website-clear/klog/'

or

- base = ( 'production' == process.env.NODE_ENV ? '/website-clear/klog/' : '/klog' );
发布评论

评论列表(0)

  1. 暂无评论