LoginSignup
1
1

More than 5 years have passed since last update.

lodashの特定のメソッドをファイルサイズを抑えつつ使いたい

Posted at

lodashが各メソッド毎にモジュールとして分割されていたらしく、特定のメソッドだけを使いたい場合はその分割されたモジュールだけをインストールすれば良いようになったみたいだ。

$ npm install lodash.template
$ node
> require('lodash.template')('<ul><% var i = 0; while (i++ < 5) { %><li><%= i %></li><% } %></ul>')()
'<ul><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li></ul>'

lodashのtemplate()だけ使いたい場合はlodash.templateをインストールすれば良い。

$ du -ch node_modules/lodash
...
1.9M total
$ du -ch node_modules/lodash.template
...
228K total

ファイルサイズが抑えられて良いかも。


lodash-nodeの他にlodash-amdというリポジトリもあるのでブラウザ上でもAMDで似たようなことができるみたいだ。

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