browserify

How to “require” text files with browserify?

亡梦爱人 提交于 2019-12-02 20:29:12
I am using browserify (using browserify-middleware) how can I require simple text files, something like: var myTmpl = require("myTmpl.txt"); I cheked stringify plugin for browserify but the code in the documentation is not working with browserify V2 require() is really best for just javascript code and json files to maintain parity with node and to improve readability of your code to outsiders who expect require() to work the way it does in node. Instead of using require() to load text files, consider using the brfs transform. With brfs, you maintain parity with node by calling fs.readFileSync

How to improve webpack performance?

旧城冷巷雨未停 提交于 2019-12-02 20:25:40
I recently switched from browserify to webpack and the build time jumped from 4s to 16s on (2014 MBP). I understand webpack does alot more than browserify but i shouldn't take that long. My build process is fairly simple. Are there any tips or options to improve my build time? var webpackOptions = { cache : true, output: { filename: '[name].js', }, module: { loaders: [ { test: /\.js$/, loader: 'jsx-loader' }, { test: /\.css$/, loader: "style!css" } ] }, }; gulp.task('buildJs', function(){ multipipe( gulp.src(jsSrcPath), named(), webpack(webpackOptions), uglify(), gulp.dest(jsDestPath) ).on(

Is there a way to render multiple React components in the React.render() function?

情到浓时终转凉″ 提交于 2019-12-02 20:04:20
For example could I do: import React from 'react'; import PanelA from './panelA.jsx'; import PanelB from './panelB.jsx'; React.render( <PanelA /> <PanelB />, document.body ); where React would render: body PanelA PanelB Currently I'm getting the error: Adjacent JSX elements must be wrapped in an enclosing tag while transpiling with browserify and babelify Since the React v16.0 release you can render an array of components without wrapping items in an extra element when you are inside a component: render() { return [ <li key="one">First item</li>, <li key="two">Second item</li>, <li key="three"

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

…衆ロ難τιáo~ 提交于 2019-12-02 17:55:18
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 mymodule = (function() { ... })(); if (isRequired()) { module.exports = mymodule; } else { window.mymodule

vuejs router - Require is not defined

跟風遠走 提交于 2019-12-02 17:23:25
问题 I am trying to get started with this: https://github.com/vuejs/vue-router I have cloned the package, and followed the instructions to build: npm install npm run build But I am receiving a "Require is not defined" error on: var Vue = require('vue') var VueRouter = require('../src') in /example/example.js I have installed node and browserify... Not sure what to do. 回答1: Have you done the following after you installed Browserify? 1) bundle all your .js files into one file (e.g. 'bundle.js')

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

丶灬走出姿态 提交于 2019-12-02 16:57:30
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-stream'); ... .bundle() .source('app.js') ... Why does this work? I am fairly new to nodejs and gulp.

Browserify and bower. Canonical approach

柔情痞子 提交于 2019-12-02 16:46:03
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') ... etc That works, but I was thinking if it's possible to use packages installed with bower (into bower

Vue JS 2.0 not rendering anything?

ε祈祈猫儿з 提交于 2019-12-02 15:23:54
Using Vue (^2.0.0-rc.6) + Browserify, entry point is index.js: import Vue from 'vue' import App from './containers/App.vue' new Vue({ // eslint-disable-line no-new el: '#root', render: (h) => h(App) }) App.vue: <template> <div id="root"> <hello></hello> </div> </template> <script> import Hello from '../components/Hello.vue' export default { components: { Hello } } </script> <style> body { font-family: Helvetica, sans-serif; } </style> Hello.vue: <template> <div class="hello"> <h1>\{{ msg }}</h1> </div> </template> <script> export default { data () { return { msg: 'Hello Vue!' } } } </script>

NodeJS with webpack jQuery.Deferred exception: o(…).select2 is not a function TypeError: o(…).select2 is not a function

一世执手 提交于 2019-12-02 14:34:21
问题 I'm modifying my application to use nodejs and browserify via gulp to produce one minified js. I've switched from loading dependencies manually and updating manually to installing them with npm. Everything went smooth, but when I wanted to install select2 it started throwing errors all over the place. When I moved my removed manual updated file for the npm required() file. jquery.js:3841 jQuery.Deferred exception: o(...).select2 is not a function TypeError: o(...).select2 is not a function at

How to uglify output with Browserify in Gulp?

孤街浪徒 提交于 2019-12-02 13:52:27
I tried to uglify output of Browserify in Gulp, but it doesn't work. gulpfile.js var browserify = require('browserify'); var gulp = require('gulp'); var uglify = require('gulp-uglify'); var source = require('vinyl-source-stream'); gulp.task('browserify', function() { return browserify('./source/scripts/app.js') .bundle() .pipe(source('bundle.js')) .pipe(uglify()) // ??? .pipe(gulp.dest('./build/scripts')); }); As I understand I cannot make it in steps as below. Do I need to make in one pipe to preserve the sequence? gulp.task('browserify', function() { return browserify('./source/scripts/app