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);
});

请联系我 商务合作、广告投放、题目勘误、侵权投诉

点赞(0)

评论列表 共有 0 条评论

暂无评论
立即
投稿
发表
评论
返回
顶部