如何浏览器化浏览器化的模块? [英] How to browserify a browserified module?
问题描述
标题似乎令人困惑,但我举一个例子。
假设我创建了一个使用ES6的模块,该模块在浏览器中运行,因此我将browserify与babelify来构建所有内容。
现在,我想在使用browserify但不使用Babel编译ES6的项目中包含相同的模块,因此我需要编译后的版本。
我尝试要求使用浏览器化模块,如下所示:
// es5-project.js
require('./ compiled-module-with-browserify');
但是当我运行 browserify es5-project.js
我开始遇到类似这样的错误:
错误:无法从'/ Users /中找到模块'./XXX' mauricio.oliveira / projects / project-name / dist-folder'
这很有意义,因为browserify
有人将这样的问题编译成一个文件吗?
谢谢!
找到答案!
这可以解决问题 https://github.com/substack/browserify-handbook#browser-field
只需在包中定义一个浏览器索引.json文件,并指向初始源文件。
:)
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!
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.
:)
这篇关于如何浏览器化浏览器化的模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!