現在、Safari Developer Preview(ES2015を100%サポートすると主張しています)でES2015をテストしています。Safari DPでES2015モジュールをインポートするにはファイルの拡張子が必要です
私は、ES2015コード(transpilingにはBabel.JS、バンドルにはBrowserifyと一緒に)を使用して開発していたときと同じ構文を使用して簡単なテストを行いました。
予期しないことに、importステートメントに.js
拡張子を含めないと、私のコードは機能しません。その標準的な行動ですか?私はあなたがそれを省略できると思った。
/* filename: scripts/alert.js */
export default class Alert {
constructor(message) {
this.message = message;
}
show() {
alert(this.message);
}
}
// Another file
/* filename: scripts/index.js */
import Alert from "./alert.js"; // this won't work if I change it to 'import Alert from "./alert";'
(new Alert("Hello, World!")).show();
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>ES2015 Modules</title>
</head>
<body>
<h1>ES2015 Modules</h1>
<script async="async" type="module" src"scripts/index.js">
</script>
</body>
</html>
* ModuleSpecifier *は、環境によってモジュールをロードするために使用されます。言語が規定するものではないので、環境には '.js'拡張が必要な場合とそうでない場合があります。 – CodingIntrigue
私はそれを知らなかった。私は開発中の良い練習(蒸散とバンドリングでさえ)として常に確実に '.js'拡張を置かなければならないと思います。 – Zorgatone