browserify

Compiling dynamically required modules with Browserify

有些话、适合烂在心里 提交于 2019-11-27 22:10:48
I am using Browserify to compile a large Node.js application into a single file (using options --bare and --ignore-missing [to avoid troubles with lib-cov in Express]). I have some code to dynamically load modules based on what is available in a directory: var fs = require('fs'), path = require('path'); fs.readdirSync(__dirname).forEach(function (file) { if (file !== 'index.js' && fs.statSync(path.join(__dirname, file)).isFile()) { module.exports[file.substring(0, file.length-3)] = require(path.join(__dirname, file)); } }); I'm getting strange errors in my application where aribtrary text

Catching Browserify parse error (standalone option)

我只是一个虾纸丫 提交于 2019-11-27 21:13:33
I'm using gulp + browserify to build and package my javascript library. Now there is one thing that bothers me: I'm running a simple server with livereload for development via gulp. This works fine, but whenever my javascript contains a syntax error, browserify throws an error causing the server to stop. The browserify code I use (note that I've added an error handler): browserify("./src/main.js") .bundle({standalone: "SomeName", debug: false}).on('error', notify.onError({ message: "Error: <%= error.message %>", title: "Failed running browserify" }) ); Now comes the interesting part: When I

How to use browserify to bundle a backbone app?

怎甘沉沦 提交于 2019-11-27 20:59:16
问题 I'm running into a little trouble with browserify. The Goal I'm trying to build the basic TodoMVC single-page app with Backbone, only instead of heaps of <script> tags in my index.html , I'm trying to bundle them all up with browserify. Here's what I have going so far. lib/models/todo.js var backbone = require("backbone"); var Todo = module.exports = backbone.Model.extend({ defaults: function() { return { title: "", completed: false, createdAt: Date.now(), }; }, }); lib/collections/todo.js

How do I exclude the “require('react')” from my Browserified bundle?

半世苍凉 提交于 2019-11-27 20:43:30
问题 I'm using Browserify to bundle a ReactJS application. All my components include a require("react") at the top. This causes Browserify to include the ReactJS source in my bundle. But I'd like to exclude it. How do I do that? Is this the right thing to do? 回答1: @NickTomlin gave this answer, but then deleted it. You can use external: browserify --external react src.js > dest.js An example using the api: var bundler = browserify('src.js'); bundler.external('react'); bundler.bundle(); This is a

Babelify throws ParseError on import a module from node_modules

落爺英雄遲暮 提交于 2019-11-27 20:03:10
I'm working with Babelify and Browserify . Also, I'm using ES6 style module features by node module system. I would like to put all my own modules into node_modules/libs . For instance: test.js in node_modules/libs export default () => { console.log('Hello'); }; main.js (will be compiled to bundle.js ) import test from 'libs/test'; test(); After that, I have compiled the above codes to bundle.js with this command: browserify -t babelify main.js -o bundle.js But unfortunately, I have got some error: export default () => { ^ ParseError: 'import' and 'export' may appear only with 'sourceType:

Should I use Browserify or Webpack for lazy loading of dependencies in angular 1.x [closed]

十年热恋 提交于 2019-11-27 19:50:28
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago . I would like to have async loading of angular dependencies in a large application and I'm trying to decide between Browserify or Webpack for this. I know angular 2.0 will support this natively but for now I'm looking for a well supported and popular solution. Can anyone give

Shimming dependencies of dependencies with browserify-shim

风流意气都作罢 提交于 2019-11-27 19:20:30
问题 I'm trying to refactor a library that uses Browserify by shimming certain modules out of the bundle using browserify-shim. Specifically, the library uses require("codemirror") but I want to provide a bundle that doesn't include CodeMirror but will rather use one that is provided via CDN. So I've got browserify-shim config in my package.json like "browserify-shim": { "jquery": "global:jQuery", "codemirror": "global:CodeMirror" } So far so good. require('jquery') and require('codemirror') have

Node/NPM: Can one npm package expose more than one file?

房东的猫 提交于 2019-11-27 17:58:05
问题 I have made a JS library for web development, it consists of several modules, which build up multiple distribution builds. It's fine when it is distributed over cdn or for example using Bower. But now I'm trying to publish it with NPM so that it can be consumed using Browserify. My question is how can I expose more than one main file statically so that they can be consumable by Browserify. 回答1: you don't need to do anything. require('my-library') // will require the `main` entry point require

What is the difference between browserify/requirejs modules and ES6 modules [closed]

为君一笑 提交于 2019-11-27 17:06:20
I'm still new to ES6 and module loaders and I'm currently looking at combining a browserify setup with ES6. I was wondering if I would still need browserify/requirejs if I'm using ES6 modules. Seems like both allow you to define modules and export them? What is the difference between browserify/requirejs modules and ES6 modules? After playing around for a while I did get a better understanding of things, also thanks to @Andy for the blog by Addy Osmani . There are different module systems : AMD (RequireJS), CommonJS (Node) and the new ES6 module syntax (and the old ES5 Global system of course)

Circular dependency issue with Typescript, CommonJS & Browserify

假装没事ソ 提交于 2019-11-27 16:47:07
问题 I'm in the process of moving a fairly large typescript project from internal modules to external modules. I do this because I want to create one core bundle, which, if and when required, can load other bundles. A seccond requirement which I'm keeping in mind is that I'd like to be able to run the bundles (with some modifications if required) on the server with nodeJS aswell. I first tried using AMD & require.js to build the core bundle, but I came across an issue with circular dependencies.