Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
528 views
in Technique[技术] by (71.8m points)

pug - Auto-compile Jade in Webstorm on Windows

I recently discovered Jade and want to give it a try for a new static website. I like the terse syntax and the templating capabilities, so much better than raw HTML. I'm editing in Webstorm 6, which has support for file watchers, and can run e.g. Sass out of the box. I've been able to run Jade via the command line to watch my Jade files:

jade --watch --out public jade

I'm now trying to configure my project in Webstorm to handle this automatically, and I'm running into problems.

To keep the source files separate from the generated ones, I'm aiming for a layout like this:

  • root
    • jade
      • index.jade
      • subdir
        • subdir.jade
    • public
      • index.html
      • subdir
        • subdir.html

With the Arguments field set as:

--out $ProjectFileDir$public$FileNameWithoutExtension$.html $FileDir$$FileName$

To start with, I have the following within my jade folder:

  • index.jade
  • subdir
    • index.jade

The result in my public folder is:

  • index.html (folder)
    • index.html (file)
  • subdir.html (folder)
    • subdir.html (file)

This is the first time I've tried to use the file watcher feature, and the available macros are confusing me. Has anyone with experience in a similar situation any suggestions?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

jade --out option specifies the directory, not the file:

-O, --out <dir>    output the compiled html to <dir>

To retain the directories structure you will have to use $FileDirPathFromParent$ macro that takes a parameter.

For example, for the C:projectpublicjadesubdirsubdir.jade file we need it to return the path right to the jade directory, that would be the parameter for the macro: $FileDirPathFromParent(jade)$, and the result would be subdir.

Now if you set the Working directory to $FileDir$, the Arguments would be:

$FileName$ --out $ProjectFileDir$public$FileDirPathFromParent(jade)$

And the complete Jade File Watcher for this specific project layout would look like this:

Jade file watcher


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...