vue中npm插件如何作为本地资源引入

在npm上下载了一个编辑器的插件,由于有需求 把源码改动了,
clipboard.png
通常vue中引入都是这样写的,改动完的npm包应该如何引用
clipboard.png

阅读 9.6k
4 个回答

下载源码,修改,重新打包,覆盖mode_modules中的文件

我看这个模块的package.json里的main指向的是release/wangEditor.js,这也就意味着你import E from 'wangEditor' === import E from 'wangEditor/release/wangEditor.js'

如果你修改了源码指的是修改了release/wangEditor.js,那你大可以把release/wangEditor.js拷贝到本地文件夹然后用相对路径引用。

又或者,将release/wangEditor.js放到public/文件夹或者发布到cdn,然后在html文件<head>中用<script>引入,然后在vue中使用var E = window.wangEditor

你可以查看一下 npm 的文档。可以使用本地路径引入包的。

As of version 2.0.0 you can provide a path to a local directory that contains a package. Local paths can be saved using npm install -S or npm install --save, using any of these forms:
../foo/bar
~/foo/bar
./foo/bar
/foo/bar
in which case they will be normalized to a relative path and added to your package.json. For example:
{
  "name": "baz",
  "dependencies": {
    "bar": "file:../foo/bar"
  }
}

npm Local Paths

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题