Simple browserify test only runs when built with --debug - browserify

I have a simple hello world script main.js:
window.addEventListener('load', function() {
"use strict";
document.getElementById('output').textContent = "Hello, browser.";
});
If I build bundle.js with:
browserify -r ./main.js > bundle.js
It doesn't run in the browser. No errors, just doesn't execute. If I use:
browserify -r --debug ./main.js > bundle.js
It runs fine. Why doesn't the non-debug one run?

-r means require. -> -r file.js means, that you will put it into a seperate scope to require it in an other bundle, but it don't will execute.
Your "solution" -r --debug (or short -r -d) works, because the require attribute has no parameter/file, so it will be ignored by browserify.
Just removing -r --debug should solve your problem.
This...
browserify -r --debug ./main.js -o ./bundle.js
...is the same as this:
browserify -d ./main.js -o ./bundle.js

Related

sass --watch : could not find option named "watch"

Simple one, but could not find the answer anywhere online! Installed sass globally (npm install -g sass) on my Mac.
This works as expected:
sass style.scss style.css
Then I try:
sass --watch style.scss:style.css
And get:
Could not find an option named "watch".
Usage: sass <input> [output]
--[no-]stdin Read the stylesheet from stdin.
--[no-]indented Use the indented syntax for input from stdin.
-I, --load-path=<PATH> A path to use when resolving imports.
May be passed multiple times.
-s, --style=<NAME> Output style.
[expanded (default), compressed]
-c, --[no-]color Whether to emit terminal colors.
-q, --[no-]quiet Don't print warnings.
--[no-]trace Print full Dart stack traces for exceptions.
-h, --help Print this usage information.
--version Print the version of Dart Sass.
What am I missing??
Thanks!!
First create the SASS's folder, and in there create your SASS's file. Example:
sass/styles.sass
In your project root folder, open the console and type the command:
sass --watch sass/styles.sass:css/styles.css
This command will create your CSS's folder and CSS's file. In addition to compiling your .sass content for your .css.
In the end, I gave up on sass as tried above, and went for a solution with webpack.
Another option I tried which worked was to use node-sass.
I solved running this command on your terminal
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
i hope that help

npm seems to be messing up my shell script which invokes uglifyjs

I have webpack use babel to transpile es6 files into es5. I want to compress these using uglifyjs. The method I used which worked till today was to have this script file be invoked with npm:
scripts/uglifyjs:
#!/usr/bin/env zsh
for file in ./public/assets/js/*.js
do
echo "uglifying `basename $file`"
uglifyjs --verbose --compress --source-map content=${file:2}.map,url=`basename $file`.map,filename=${file:2}.map,includeSources=true --output $file $file
done
And in my package.json:
"scripts": {
...
"uglifyjs": "scripts/uglifyjs",
Take the first file that gets invoked, links.js. If I manually type the command is works:
$ uglifyjs --verbose --compress --source-map content=public/assets/js/links.js.map,url=links.js.map,filename=public/assets/js/links.js.map,includeSources=true --output ./public/assets/js/links.js ./public/assets/js/links.js
INFO: Using input source map: public/assets/js/links.js.map
When running npm run uglifyjs I get the following error:
$ npm run uglifyjs
> jbuk-frontend#0.0.1 uglifyjs /home/jonny/git/jonnybarnes.uk
> scripts/uglifyjs
uglifying links.js
fs.js:651
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
^
Error: ENOENT: no such file or directory, open 'content=public/assets/js/links.js.map,url=links.js.map,filename=public/assets/js/links.js.map,includeSources=true'
at Object.fs.openSync (fs.js:651:18)
at Object.fs.writeFileSync (fs.js:1300:33)
at done (/home/jonny/git/jonnybarnes.uk/node_modules/uglify-js/bin/uglifyjs:516:20)
at cb (/home/jonny/git/jonnybarnes.uk/node_modules/uglify-js/bin/uglifyjs:324:39)
at /home/jonny/git/jonnybarnes.uk/node_modules/uglify-js/bin/uglifyjs:391:9
at tryToString (fs.js:512:3)
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:500:12)
I don’t know why I can run the command manually, but not via npm, it worked before. Is this a known change with npm v5?

Uglifyjs does not generate working map file when uglifying browserify output

I've run browserify like this:
browserify js/app.js -d | exorcist js/bundle.js.map > js/bundle.js
When I load this in Chrome, the sources map file is fine. When I uglify it like this:
uglifyjs js/bundle.js --in-source-map js/bundle.js.map --source-map-url bundle2.js.map --source-map js/bundle2.js.map -o js/bundle2.js -p 1
The sources map file does not work. It tries to load sources from /js/js, instead of just from /js. I have fiddled with the -p parameter, and every other parameter that is documented on the commandline here:
https://github.com/mishoo/UglifyJS2
The only way I could get this to work was to cd into the js directory and run the commands from there. Lame, but it works.
-p relative
fixed the issue for me

Browserify exclude does not seem to work

I am trying to exclude JQuery from my build file:
browserify --exclude jquery -g uglifyify -e src/main.js -t partialify -t uglifyify > dist/bundle.min.js
Only JQuery is still in the bundle.min.js? Am I doing something wrong?
https://github.com/substack/browserify-handbook#ignoring-and-excluding
Have you tried the following?
browserify src/main.js --exclude jquery -g uglifyify -t partialify -t uglifyify > dist/bundle.min.js
the usage is as follows, i.e. options come after entry files:
Usage: browserify [entry files] {OPTIONS}

bundle not found via ssh

If I ssh into my VPS as the deployment user and run bundle -v I get Bundler version 1.1.5 as expected.
If I run ssh deployment#123.123.123.123 bundle -v, then I see bash: bundle: command not found
Why isn't bundle being shown running commands via ssh?
More Info
$ cat ~/.bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
if [ -d "${RBENV_ROOT}" ]; then
export PATH="${RBENV_ROOT}/bin:${PATH}"
eval "$(rbenv init -)"
fi
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
When you run:
ssh deployment#123.123.123.123
You get a login shell on the remote host, which means that your shell will run (...for bash...) .bash_profile or .profile or equivalent AS WELL AS your per-shell initialization file.
When you run:
ssh deployment#123.123.123.123 some_command
This does not start a login shell, so it only runs the per-shell initialization file (e.g., .bashrc).
The problem you've described typically means that you need something in your .profile file (typically an environment variable setting) for everything to work.