webpackでnode_modules配下のcssをimportするときのpathにチルダを入れる
npm install
やyarn install
で追加したcssを@import
するとき、../../node_modules/normalize.css/normalize.css
のようにnode_modules
までのディレクトリを辿っていくのは面倒。
So using the prefix ~ at the start of the path tells the Webpack loader to resolve the import “like a module”.
~
をパスの先頭につけると、node_modules
配下のパスを解決してくれる。
@import "~normalize.css/normalize.css";
なので、このように~
付きにすればnormalize.cssがimportできるようになる。