22
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

jade で IE の Conditional Comments(条件付きコメント)を効かせる

Last updated at Posted at 2014-04-09

追記あり

以前はこのように書けば

// if lt IE 9
      script(src="/javascripts/html5shiv.js")

↓こうなった

<!--[if lt IE 9]>
<script src="/javascripts/html5shiv.js"></script>
<![endif]-->

jade 1.0 からはこの記法が使えない。

ここを見ると...
https://github.com/visionmedia/jade/issues/1345

以下のように書けと書いてある

<!--[if lt IE 9]>
script(src="/javascripts/html5shiv.js")
<![endif]-->

たしかにコンパイルはされるけど↓のように先頭が前の行のうしろにくっついてしまった
(こうなりませんか?)

<link rel="stylesheet" href="stylesheets/styles.css"><!--[if lt IE 9]>
<script src="/javascripts/html5shiv.js"></script><![endif]-->

不細工なうえに、これだと conditinal comments だと解釈されない(みたい)。

なので、これで強引に解決

//[if lt IE 9]><script src="/javascripts/html5shiv.js"></script><![endif]

<!--[if lt IE 9]><script src="/javascripts/html5shiv.js"></script><![endif]-->

2014/4/10追記

上記の方法でも conditinal comments が読めていないようでした
いろいろ試した結果、以下の書き方なら問題ない様子です

!= '\n<!--[if lt IE 9]>'
script(src="./javascripts/html5shiv.js")
!= '\n<![endif]-->\n'
22
21
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
22
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?