browserify

Using Node.js modules in HTML

天涯浪子 提交于 2019-12-01 03:06:13
问题 I have the following Node.js project (which is a Minimal Working Example of my problem): module1.js : module.exports = function() { return "this is module1!"; }; module2.js : var module1 = require('./module1'); module.exports = function() { return module1()+" and this is module2!"; }; server.js : var module2 = require('./module2'); console.log(module2()); // prints: "this is module1! and this is module2!" Now I want to create a client.html file that will also use module2.js. Here is what I

Including JQuery Mobile in a Node JS project with Browserify

巧了我就是萌 提交于 2019-12-01 02:19:42
问题 I'm writing a Node JS application where I need both jQuery UI and jQuery Mobile. I'm using Browserify to pack the modules in a single js file. I have the following code to include jQuery and jQuery UI in my project. var jQuery = require('jquery'); require('jquery-ui-browserify'); And it works. Problems arise when I try to add jQuery mobile, either with a require: require('./lib/jquery.mobile-1.4.0.min.js'); or with a script tag <script src="/lib/jquery.mobile-1.4.0.min.js" type="text

Node JS fs module inside browser

北战南征 提交于 2019-11-30 18:34:21
I have a scenario where I want to export data to CSV from the client-side. I will have a textbox/area or whatever where the user can input data and then ideally with one click, a local CSV file will be updated with that data. This is easily achievable with NodeJS with server interaction, and its core modules (specifically fs module), but apparently not so much from a browser. I found out that certain node modules (for example underscore ), support RequireJS's method of making a particular module work in the browser. So for underscore I did this: methods.js define(['underscore'],function(_) {

Require in browserify doesn't work variable name

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 18:21:48
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 the module when both are strings? Browserify has to be able to statically analyze all of the require

How do I use react.js without a bundler?

守給你的承諾、 提交于 2019-11-30 12:24:25
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 around with. If I wanted to mess around with build chains and the like I would probably just do my

Bests practice for Browserify in large web projects - Gulp

拜拜、爱过 提交于 2019-11-30 12:15:36
问题 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)

How do you use JSHint and Browserify together?

大城市里の小女人 提交于 2019-11-30 11:50:07
I'm attempting to build a project using Angular and Browserify. My controllers.js file looks like this... 'use strict'; module.exports.testController = function($scope){ $scope.message = 'Controller 1'; console.log( 'hello' ); }; As you may expect, that generates three linting errors. Use the function form of Strict 'module' is not defined 'console' is not defined I did find a bit of a solution here that enables JSHint to process Node.js files by putting jslint node: true at the top of the file like this /*jslint node: true */ 'use strict'; module.exports.testController = function($scope){

Require jsx files without specifying extension

戏子无情 提交于 2019-11-30 09:01:49
I am using browserify and watchify , and would like to require() files other than the default extensions .js and .json without specifying the extension, for instance: // Not ideal (tedious) var Carousel = require('./components/Carousel/Carousel.jsx') // Ideal var Carousel = require('./components/Carousel/Carousel') I have tried --extension=EXTENSION as specified in the browserify documentation: "scripts": { "build": "browserify ./src/App.js --transform [ reactify --es6 ] > dist/script.js -v -d --extension=jsx", "watch": "watchify ./src/App.js --transform [ reactify --es6 ] -o dist/script.js -v

一个后端er想进前端娱乐圈

☆樱花仙子☆ 提交于 2019-11-30 08:37:10
经过几天的折腾,总算是略微明白前端娱乐圈的一堆工具。 模块化 为什么要折腾这些? 因为我想用js的模块化,不想再jquery一把梭。 第一个想到的是typescript,过了一遍文档,把现有项目的部分功能用ts改写后没问题,学习内容包括: 了解Node.js,会用其运行脚本; 了解包管理工具npm,据~说yarn更好,遂采用后者,会用其安装、卸载包; 学习typescript语法,并改写现有项目的几个函数。 随后准备编译,合并进项目master,接下来问题来了,浏览器不能运行。 报错信息为: exports is not defined ,这个信息让我走上了瞎折腾的道路。 规范 得知现代浏览器不支持 exports 关键词,那 exports 又是什么?它是 CommonJs 中的一个语法,我想起ts配置文件中有个编译选项就是 "module": "commonjs" 。 这个 CommonJs 又是什么?它是一种规范,就是希望大家都能按这个标准来,同类规范还有: AMD (Asynchronous Module Definition) CMD (Common Module Definition) ES6 (ECMAScript 6) 这里引用 《前端模块化详解(完整版)》 中的一张图,关于模块化的发展进程和相关介绍,大家可以看看这篇文章,写的很好。 转换器

Disable chrome react DevTools for production

别说谁变了你拦得住时间么 提交于 2019-11-30 08:27:22
问题 I'm trying to browserify my react app for production using gulp and envify to setup NODE_ENV. So I can remove react warning, error reporting in the console, and even my code to disable some features like the require of react-addons-perf. And it's working great. When I search in my app.js for "production" to see if there are theses typical conditions : if("development" !== "production") { ... } There is nothing, so, as I said, it seems to work well. But, I still can see that chrome's react