Skip to content

Instantly share code, notes, and snippets.

@adamay000
Last active December 16, 2019 11:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamay000/93c065061617297d30047ab27be9fb2e to your computer and use it in GitHub Desktop.
Save adamay000/93c065061617297d30047ab27be9fb2e to your computer and use it in GitHub Desktop.
webpackでjQueryプラグインを使う
// 使える!!
$('body').velocity();
// ただし、下記のようにどこかしらでVelocityを参照していないとプラグインを読み込んでくれない
// 結局のところエントリポイントのファイルとかでimport 'jquery-velocity';読んでおくのがベターな気がする
Velocity;
// いろいろ省略
webpack({
plugins: [
new webpack.ProvidePlugin({
jQuery: 'jquery',
$: 'jquery',
// プラグインを読み込んだ時にwindow.jQueryが存在している必要がある
'window.jQuery': 'jquery'
// velocity-animateを読み込んでみる
// ここではVelocityという名前にしているので、この名前が参照されて始めてモジュールが読み込まれる
// つまりソースの中でVelocityを一度も使っていなかった場合、$().velocityも使えない
Velocity: 'velocity-animate'
})
]
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment