LoginSignup
6
6

More than 5 years have passed since last update.

【JS】smash

Last updated at Posted at 2014-08-06

複数のjavascriptを1つにまとめる「smash」を紹介。

smashの開発者はd3.jsの生みの親mbostockさんで,
d3.jsのビルド時にも利用されているようです。

smashは,簡単にいうと次のような事が出来ます。

  • helloJS.js
    
    var helloJS = function(){
    return "Hello Javascript!!";
    };
    
  • main.js
    
    import "helloJS";
    window.console.log(helloJS());
    
  • smashコマンド実行
    
    # smash main.js
    
  • 出力結果
    
    var helloJS = function(){
    return "Hello Javascript!!";
    };
    window.console.log(helloJS());
    

そう!Javascriptでimportが出来るのです!

これを使えば,jQueryのように,わざわざintro.jsとかoutro.jsとか作らなくても
個別のファイルで実装したモジュールを即実行無名関数でまとめる事が出来ます。

smashは,gruntのパッケージも存在するので,結合処理を自動化する事も出来ます。
https://github.com/cvisco/grunt-smash

ただ,smashは,

  • import記述部はindent使えない(必ず左端から書く)
  • 同じファイルは取り込めない
  • jsファイル自体に「import」とかくので,必ずsmashでビルドを行う必要がある

等,使いづらい所もあります。

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