browserify

Browserify: Use module.exports if required, otherwise expose global

不想你离开。 提交于 2019-12-03 04:43:56
问题 I'm considering adopting browserify for some of my projects, but would like to make sure that others don't have to use browserify if they want to use the (bundled) code. The obvious way to do this is to both expose the modules exports through module.exports as well as through a window. global. However, I'd rather not pollute the global namespace for those who are require ing the script. Is it possible to detect if a script is being require d? If it is, then I could do something like: var

Generating source maps from browserify using grunt

时光怂恿深爱的人放手 提交于 2019-12-03 04:36:31
I have followed the instructions here: https://www.npmjs.org/package/grunt-browserify , to try and set up source maps for browserify on grunt. The options for browserify in my gruntfile are : browserify: { options: { bundleOptions : { debug: true } }, dist: { files: { "public/client.bundle.js": ["bundle.js"] } } } The generation of bundle.js happens without any issues, however the source map generation does not happen. Is there anything wrong with my grunt-browserify options. Thanks for looking. use browserifyOptions instead of bundleOptions browserify: { options: { browserifyOptions: { debug:

Exporting a class with ES6 (Babel)

五迷三道 提交于 2019-12-03 04:23:16
I'm writing some frontend code with ECMAScript 6 (transpiled with BabelJS, and then browserified with Browserify) so that I can have a class in one file, export it and import it in another file. The way I'm doing this is: export class Game { constructor(settings) { ... } } And then on the file that imports the class I do: import {Game} from "../../lib/pentagine_browserified.js"; var myGame = new Game(settings); I then compile it with grunt , this is my Gruntfile : module.exports = function(grunt) { "use strict"; grunt.loadNpmTasks('grunt-babel'); grunt.loadNpmTasks('grunt-browserify'); grunt

How do I build a single js file for AWS Lambda nodejs runtime

怎甘沉沦 提交于 2019-12-03 03:51:13
问题 We are working on a project/framework that aids in deploying and maintaining code in AWS Lambda. I want to build/bundle all node.js code for a lambda function into one js file because: Smaller codebases help with lambda cold start issues Lambda has code zip size limit of 50MB We don't want to create a custom bundler to do this because there are many options already out there (systemjs,browserify,webpack etc). HOWEVER we are concerned with issues with some node modules not playing well with

Browserify with jQuery >= 2 produces “jQuery requires a window with a document”

徘徊边缘 提交于 2019-12-03 03:43:12
I'm using browserify to bundle my front-end javascript using CommonJS-style dependencies. For example, I have: $ = require('jquery/dist/jquery'); // v2.1.0-beta2 _ = require('underscore'); Backbone = require('backbone'); However, when browserify bundles the dependencies I run into the following console error: Error: jQuery requires a window with a document Looking at the jQuery code, I see it's trying to use this for the global window . (function( window, factory ) { .... }(this, function( window ) { Since browserify wraps all dependencies, this is an object , not the window . What's

Why do I have to use vinyl-source-stream with gulp?

我们两清 提交于 2019-12-03 03:27:25
问题 I am trying to use gulp and browserify to transform my .jsx files into .js files. var gulp = require('gulp'); var browserify = require('browserify'); var reactify = require('reactify'); gulp.task('js', function () { browserify('public/javascripts/src/app.jsx') .transform(reactify) .bundle() .pipe(gulp.dest('public/javascripts/dist')) }); ``` The above threw Arguments to path.resolve must be strings . I managed to get around it by using vinyl-source-stream var source = require('vinyl-source

Chain Gulp glob to browserify transform

匿名 (未验证) 提交于 2019-12-03 03:10:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a project with a few relatively disjoint pages, each including their own entry point script. These scripts require a number of others using commonjs syntax, and need to be transformed by 6to5 and bundled by browserify. I would like to set up a gulp task that captures all the files matching a pattern and passes them on to the bundler, but I'm not sure how to pass files from gulp.src to browserify(filename) . My gulpfile looks like: var gulp = require("gulp"); var browserify = require("browserify"); var to5browserify = require("6to5

AngularJS RequireJS Browserify and the Javascript module/global scope nightmare [closed]

匿名 (未验证) 提交于 2019-12-03 03:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have been digging a bit lately in all this CommonJS vs AMD battle and this is my findings... ( BTW I am not preaching here I am sharing my thoughts to get some constructive insights... ) The RequireJS brings to much complexity to my Angular modules, it feel wrong to me as it's a module wrap in a module... The Browserify way is cleaner but for it to work correctly with every thing, you need to have all your dependency and your dependency-dependencies implemented correctly and unfortunately we don't live in a perfect world... so

Browserify and bower. Canonical approach

試著忘記壹切 提交于 2019-12-03 02:54:22
问题 The way I'm using packages that not available out of the box in npm, right now is like that: package.json has: "napa": { "angular": "angular/bower-angular", "angular-animate": "angular/bower-angular-animate", "d3": "mbostock/d3", "ui-router":"angular-ui/ui-router", "bootstrap":"twbs/bootstrap" }, "scripts": { "install": "node node_modules/napa/bin/napa" and that installs files into node_modules directory, and I use them natively like this require('angular/angular') require('ui-router') ...

Use of browserify to pack React components

匿名 (未验证) 提交于 2019-12-03 02:33:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to learn browserify to manage my javascript. My first simple task is to create a react.js file which will be generated by gulp + browserify var browserify = require('gulp-browserify'); gulp.task('browserify-react', function () { return gulp.src('js/react/react.js') .pipe(browserify()) .pipe(rename('react-generated.js')) .pipe(gulp.dest('./dist')); }); In js/react/ I created a file react.js which is just two require commands: var React = require('react'); var ReactDOM = require('react-dom'); I expect that a new file react