简体   繁体   English

如何在浏览器中使用Dropbox-sdk-js?

[英]How to use Dropbox-sdk-js in the browser?

I have been trying to get the dropbox-sdk-js running in the browser. 我一直试图在浏览器中运行dropbox-sdk-js The sdk is developped for node. 为节点开发了sdk。

What I need is to include the sdk in a <script> tag and start using the SDK in JS. 我需要将sdk包含在<script>标记中并开始在JS中使用SDK。

I tried Webpack and Browserify. 我尝试了Webpack和Browserify。 But none of them seem to unentangle the Dropbox js object from require for me to use in the browser. 但是它们似乎都没有使Dropbox js对象脱离require让我在浏览器中使用。 Simply requre is undefined both after webpack and browsify. 在webpack和浏览后,简单的requre都未定义。

-- Reproduce -- -复制-

  1. Go to the root folder of the repo and execute webpack . 转到webpack的根文件夹并执行webpack This will read webpack.config.js and create dropbox-sdk.js in dist folder 这将读取webpack.config.js并在dist文件夹中创建dropbox-sdk.js

  2. Include the file in my script <script src="dropbox-sdk.js"></script> 在我的脚本<script src="dropbox-sdk.js"></script>包含文件

  3. Undefined error come when I try to execute var Dropbox = require('dropbox'); 当我尝试执行var Dropbox = require('dropbox');时,出现不确定的错误var Dropbox = require('dropbox');

The script is guaranteed to be included correctly. 保证脚本正确包含。 Even tried to use a precompiled one from this CDN. 甚至尝试使用 CDN中的预编译版本。

Any help is appreciated. 任何帮助表示赞赏。

If you want to use the dropbox-sdk in browser you either have to use 如果要在浏览器中使用dropbox-sdk,则必须使用

  • with a module bundler like webpack or browserify 与一个模块捆绑等的WebPackbrowserify
  • or to avoid the module builder you can reference /dropbox/dist/dropbox-sdk.min.js in the node_modules 或避免模块生成器,你可以参考/dropbox/dist/dropbox-sdk.min.js在node_modules

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM