browserify

How to import jquery using ES6 syntax?

人走茶凉 提交于 2019-11-26 14:13:58
I'm writing a new app using (JavaScript) ES6 syntax through babel transpiler and the preset-es2015 plugins, as well as semantic-ui for the style. index.js import * as stylesheet from '../assets/styles/app.scss'; import * as jquery2 from '../dist/scripts/jquery.min'; import * as jquery3 from '../node_modules/jquery/dist/jquery.min'; console.log($('my-app')); index.html <!DOCTYPE html> <html lang="fr"> <head> <body> <script src="dist/app.js"></script> </body> </html> Project structure . ├── app/ │ ├── index.js ├── assets/ ├── dist/ │ ├── scripts/ │ │ ├── jquery.min.js ├── index.html ├── node

Defining global variable for Browserify

蓝咒 提交于 2019-11-26 14:04:33
问题 I'm using SpineJS (which exports a commonjs module) and it needs to be available globally because I use it everywhere, but It seems like I have to do Spine = require('spine') on every file that uses Spine for things to work. Is there any way to define Spine once to make it globally available? PS: I'm using Spine as an example, but I'm in general wondering about how to do this with any other library. 回答1: Writing Spine = require('spine') in each file is the right way to do. Yet, there are

Modules vs. Namespaces: What is the correct way to organize a large typescript project?

筅森魡賤 提交于 2019-11-26 13:57:31
问题 I'm pretty new to typescript and I'm writing a small prototyping framework for WebGl. I'm currently refactoring my project and have run into some problems as how to organize my project, as both (modules and namespaces) approaches seem to have serious drawbacks. This post is not about HOW to use these patterns, but how to overcome the problems each of these brings. Status Quo: Using namespaces Coming from C# this seemed like the most natural way to go. Every class/module gets it's appropriate

How do I use Browserify with external dependencies?

末鹿安然 提交于 2019-11-26 12:04:17
问题 I am trying to slowly introduce Browserify into my site, but I don\'t want to rewrite all the js and I don\'t want duplicate instances of jquery and other libraries bundled with my Browserify build. If I build my module listing jquery as an external dependency, how do I then point it at my global jquery instance? Also the goal is to eliminate the mylibs global (example below), so I don\'t want to use it in my module. This is what I\'m trying to do (psudo-code). This would be in my site\'s

Is it okay to use babel-node in production

这一生的挚爱 提交于 2019-11-26 11:46:42
问题 I have been developing a site using babel-node and browserify with the babelify transform, to support ES6 syntax. I am just wondering, can I run this in production as babel-node server rather than node server What other options do I have to run ES6 in node? Here are the commands I am running for build and start in development // npm run build browserify -t [babelify] client.js > public/js/bundle.js\", // npm start babel-node server.js\" Here are my dev dependencies \"babel\": \"^4.0.1\", \

SyntaxError: &#39;import&#39; and &#39;export&#39; may appear only with &#39;sourceType: module&#39; - Wait what?

坚强是说给别人听的谎言 提交于 2019-11-26 11:24:33
问题 So consider the following two files: app.js import Game from \'./game/game\'; import React from \'react\'; import ReactDOM from \'react-dom\'; export default (absPath) => { let gameElement = document.getElementById(\"container\"); if (gameElement !== null) { ReactDOM.render( <Game mainPath={absPath} />, gameElement ); } } index.js import App from \'./src/app\'; The gulpfile.js var gulp = require(\'gulp\'); var source = require(\'vinyl-source-stream\'); var browserify = require(\'browserify\')

browserify error /usr/bin/env: node: No such file or directory

可紊 提交于 2019-11-26 10:13:51
问题 I installed node js and npm via apt-get install and all of the dependencies, then I installed browserify npm install browserify -g it goes through the process and it seems like it installed correctly, but when I try to do a simple bundle per this walkthrough I get the error: /usr/bin/env: node: No such file or directory 回答1: Some linux distributions install nodejs not as "node" executable but as "nodejs". In this case you have to manually link to "node" as many packages are programmed after

Browserify - How to call function bundled in a file generated through browserify in browser

岁酱吖の 提交于 2019-11-26 09:17:22
问题 I am new to nodejs and browserify. I started with this link . I have file main.js which contains this code var unique = require(\'uniq\'); var data = [1, 2, 2, 3, 4, 5, 5, 5, 6]; this.LogData =function(){ console.log(unique(data)); }; Now I Install the uniq module with npm: npm install uniq Then I bundle up all the required modules starting at main.js into a single file called bundle.js with the browserify command: browserify main.js -o bundle.js The generated file looks like this: (function

Browserify with require(&#39;fs&#39;)

末鹿安然 提交于 2019-11-26 07:43:18
问题 I was trying to use browserify on a file that uses the fs object. When I browserify it, the call to require(\'fs\') doesn\'t get transformed and require returns {} . Is there any workaround for this? I\'ve seen some suggestions on stackoverlow and elsewhere, but none seem to be fully realized. I actually hoped to create a google web packaged app using browserify for a class I teach. Thanks in advance. 回答1: Which filesystem should the browser use then? The HTML5 filesystem is not really

Browserify, Babel 6, Gulp - Unexpected token on spread operator

ぃ、小莉子 提交于 2019-11-26 05:58:25
问题 I\'m trying to get my Browserify/Babelify/Gulp working in my project, but it won\'t take the spread operator. I got this error from my gulpfile: [SyntaxError: /Users/mboutin2/Desktop/Todo-tutorial/src/reducers/grocery-list-reducers.js: Unexpected token (16:8) while parsing file: /Users/mboutin2/Desktop/Todo-tutorial/src/reducers/grocery-list-reducers.js] This is my gulpfile.js var gulp = require(\'gulp\'); var source = require(\'vinyl-source-stream\'); var browserify = require(\'browserify\')