3
3

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.

Atom Shellでの絶対パスの扱い

Last updated at Posted at 2015-01-08

背景

俺がtmlib.jsの公式エディタのrunstantをオフライン対応のデスクトップアプリにするの前編の後編を書こうと、いざ、Atom Shellに組み込んで動かそうとしたら、ハマった。

Atom Shell内のhtmlでのパスの指定

main.js
mainWindow.loadUrl('file://' + __dirname + '/alpha/index.html');

のように記述した場合、index.htmlで

<img src="/tmp/hoge.jpg">

とは、ローカルのPCの上の/tmp/hoge.jpgを参照する事になる。

自分は、てっきり、index.htmlから相対パスでいうところの、

../tmp/hoge.jpg

が参照されると思い込んでいた。

.
├── alpha
│   └── index.html
├── tmp
│   └── hoge.jpg <-- これが/tmp/hoge.jpgで参照できると思っていた。
├── index.html
├── main.js
├── package.json

上記のtmp/hoge.jpgを参照するには

../tmp/hoge.jpg

まとめ

まぁ、mainWindow#loadUrlの時点でパスの指定が、ローカルPCの絶対パス
指定なんだから気がつけるのかも。

関連記事

3
3
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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?