browserify

Browserify import/require?

こ雲淡風輕ζ 提交于 2019-11-30 06:37:34
I'm trying to pick up browserify and have been through a number of examples. In one example I see the use of 'import': import 'jquery'; and importing local files with: import Header from './Header'; but in other examples I see people importing via: require('./Header'); What is the difference? require() is the Node module system (CommonJS) in ES5. import is ES6 module syntax. If you want to browserify modules written with ES6 module syntax you'll need to compile them using something like babelify (or babel by other means). 来源: https://stackoverflow.com/questions/33042867/browserify-import

Get browserify require paths to behave more like requirejs

我们两清 提交于 2019-11-30 06:26:21
I'm finding that it's a pain when moving files around and constantly having to rewrite the file include paths to be relative to their new folder. I want to avoid this in my browserify code: var View = require('../../../../base/view'); And do something more in line with requirejs where it knows my base path is js : var View = require('base/view'); eightyfive You should use the paths option. It is not documented in browserify but in node-browser-resolve (used under the hood): paths - require.paths array to use if nothing is found on the normal node_modules recursive walk A great option here is

How do I watch multiple files with gulp-browserify but process only one?

柔情痞子 提交于 2019-11-30 05:05:55
I'm trying to wire up gulp-browserify and gulp-watch to rebuild my bundle each time a source file changes. However, gulp-browserify requires a single entry point for the compilation (e.g. src/js/app.js ) and fetches every dependency itself: gulp.src('src/js/app.js') .pipe(browserify()) .pipe(gulp.dest('dist')) However, with gulp-watch this fails to rebuild on every change because only the entry point file is being watched. What I actually need is a possibility to watch multiple files and then process only the entry point file (look for replaceEverythingWithEntryPointFile ): gulp.src("src/**/*

How to expose 'require' to the browser when using browserify from within gulp?

99封情书 提交于 2019-11-30 04:00:53
When I have a file x.js that looks like this: x.js module.exports = function (n) { return n * 111 } and I run browserify from the command line like so: browserify -r ./x.js > bundle.js I get an output file that looks like this (roughly): require=(function e(t,n,r){function ...... ./App.jsx":[function(require,module,exports){ module.exports=require('0+DPR/'); },{}]},{},[]) Then in my browser code I can do this: <html> <head> <title>React server rendering example</title> <script src="static/bundle.js"></script> </head> <body> Welcome to the React server rendering example. Here is a server

Bests practice for Browserify in large web projects - Gulp

依然范特西╮ 提交于 2019-11-30 02:22:16
Here is the thing, I come from a world where you have several js files included to a web page. Some are always included in the page (your libs, menu etc...) and others are depending on the current page (js for login page, js for subscription etc...). Basically let's say that I have 1 different js file per page plus the libs. Now I want to start a new project with browserify and I am in front of a big problem : In all the examples I have seen, there is always a single entry point (like app.js). In my case I would have n entry points (1 per page). So my questions are : Is it against good

Require in browserify doesn't work variable name

情到浓时终转凉″ 提交于 2019-11-30 01:25:34
问题 I am trying to require a file with browserify using variables passed into a function: var playersOptions = { name: 'players', ajax: 'team-overview', route: { name: 'overview', path: 'playersOverview', url: 'playersoverview' } }; var BackboneView = require(playersOptions.route.path); //Error: Uncaught Error: Cannot find module 'playersOverview' var BackboneView = require('playersOverview'); //Requires the file without any problems. I am confused as to why this would fail? How can it not find

Browserify/Babelify React for production (NODE_ENV production)

大兔子大兔子 提交于 2019-11-29 22:59:18
问题 I run this command: browserify src.js -t [ babelify --presets [ react ] ] > build.js and I get a single file that can be used by it's own. Works fine, but it's NODE_ENV is set to development and I get a console.log about downloading React DevTools. How do I set it to production? I browsed around and didn't find anything that worked for me. I tried envify, but no luck (I'm very newb with JS builds). I tried putting --NODE_ENV production somewhere in the line above, but I'm very new to

Browserify with twitter bootstrap

独自空忆成欢 提交于 2019-11-29 19:46:28
There are many similar questions including answers here on stack overflow, but none of them have worked for me, so here I am asking you guys. I appreciate everyone's time. I recently started using gulp with browserify, and that works great. I then tried to use browserify for the front-end using: Backbone and Bootstrap3. things are appearing to work, until I try to require the js file that comes with Bootstrap. I get an error in my chrome tools stating: jQuery is undefined. I have attempted to shim it in, but I am very confused by the shim. I am using jQuery 2.1.1, so I should not need to shim

Task Runners (Gulp, Grunt, etc) and Bundlers (Webpack, Browserify). Why use together?

牧云@^-^@ 提交于 2019-11-29 19:01:58
I am a bit new to the task runner and bundler world and while going through things like Grunt, Gulp, Webpack, Browserify , I did not feel that there is much difference between them. In other words, I feel Webpack can do everything that a task runner does. But still I got a huge examples where gulp and webpack are used together. I couldn't figure out the reason why. Being new to this, I might be taking things in the wrong direction. It will be great if you could point out what I am missing. Any useful links are welcome. Thanks in advance. Grunt and Gulp are actually task runners, and they have

How do I use react.js without a bundler?

此生再无相见时 提交于 2019-11-29 17:44:07
问题 Recently I have been playing around with react.js and I like the speed that I can develop working UI components. I have now created quite a few components and I would like to distribute some of them among different .jsx files. Every thing I've read says that I should be using a bundler like browserify or webpacker whenever moving to production. However I am against this idea. Part of the reason I like developing in javascript is because its a scripted language and there is no compiler to muck