In case if anyone's still struggling to make it work with requirejs, here's how it's done:
1) Your requirejs config file should look like this:
"use strict";
require.config({
baseUrl: '',
paths: {
'jquery': 'vendor/jquery/jquery.min',
'clipboard': 'vendor/clipboard/clipboard.min',
'modules/clipboard': 'js/modules/clipboard',
},
shim : {
'jquery': {
exports: '$'
},
'clipboard': {
exports: 'ClipboardJS',
deps: ['jquery']
},
},
priority : ['jquery']
});
In the 'modules/clipboard' file: (Notice the parameters in the function below, you need to pass the constructor as a parameter)
define([
'jquery',
'clipboard'
], function ($,ClipboardJS){ //Notice the parameters $ is for jquery plugin and ClipboardJS is for clipboard plugin
new ClipboardJS('.btn);
});
发表评论 取消回复