How to browserify a browserified module?

落花浮王杯 提交于 2020-01-16 03:48:06

问题


The title seems confusing but I'll give an example.

Let's say I create a module that uses ES6 that runs in the browser, so I use browserify with babelify to build everything.

Now I want to include that same module in a project that uses browserify, but does not uses Babel to compile ES6, so I need the compiled version.

I tried to require the "browserified" module like this:

// es5-project.js
require('./compiled-module-with-browserify');

But when I run browserify es5-project.js I start to get some errors like this:

Error: Cannot find module './XXX' from '/Users/mauricio.oliveira/projects/project-name/dist-folder'

And that makes sense, since browserify compiled all modules into one file, it won't find the modules inside the compiled file.

Does anyone have faced a problem like this one? if you did, how you solved it?

Thanks!


回答1:


Found the answer!

This will do the trick https://github.com/substack/browserify-handbook#browser-field

Just define a "browser" index in the package.json file, and point to the initial source file.

:)



来源:https://stackoverflow.com/questions/32846788/how-to-browserify-a-browserified-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!