jslim
jslim copied to clipboard
Minifying jquery with other plugins I get "$ is not defined"
I am running the following command with jslim
jslim --js ../minified_test/temp1.js --js_output_file ../minified_test/assets/linker/js/out.js --lib_js assets/linker/js/jquery-2.1.0.js --lib_js assets/linker/js/app.js --lib_js assets/linker/js/bbootstrap.js --lib_js assets/linker/js/bootstrap-formhelpers.js --lib_js assets/linker/js/jasny-bootstrap.js --lib_js assets/linker/js/jquery.cookie.js --lib_js assets/linker/js/jquery.form.js --lib_js assets/linker/js/jquery.validate.js --lib_js assets/linker/js/myhelpers.js --lib_js assets/linker/js/sails.io.js --lib_js assets/linker/js/socket.io.js --separate_files --skip_gzip --compilation_level SIMPLE_OPTIMIZATIONS
Removed 138 out of 662 named functions.
Then while accessing the webpage I get the following error in the console.
Uncaught TypeError: undefined is not a function out.js:37
Uncaught ReferenceError: $ is not defined product:138
Where in product script I have out.js
(product of jslim
) included.
What else can I provide to debug this error ?
Thanks for using JSlim. I would need to know more about this project. Where do you see the error? Are you using $ in your templ.js file? Depending on how you define this you may need to declare $ as an external reference.
@zgrossbart This is more or less my code :
$(function( ) {
var file, product_name;
$('input[type=file]').on('change', prepareUpload);
///..........
$("#submit_button").prop( "disabled", false);
$(".fileinput").fileinput('clear');
///..........
$("#form_new_product").validate({
///..........
});
var username = $.cookie("username");
if( username ){
$(".vertical-navbar-middle").html( ///..........);
}
});
It gives error on lines : with $(function() {
and does not go in the callback function (where there are more references to $
This is minified and compiled out.js
http://hastebin.com/coxeqohaca.rb (it gives Uncaught TypeError: undefined is not a function
on line 48)
I'm not really sure what's going on here. If you want to share your project somewhere I can take a look and try to figure out what's going on, but it might take a me a little while to get to it.
@zgrossbart Ok so I have shared it here https://github.com/pmalek/jslim_test
Just clone it, (you will need node and npm to run it http://nodejs.org) run npm install
, npm install -g sails
, then you can use jslim
jslim --js temp1.js --js_output_file assets/linker/js/out.js --lib_js old/ajquery-2.1.0.js --lib_js old/app.js --lib_js old/bbootstrap.js --lib_js old/bootstrap-formhelpers.js --lib_js old/jasny-bootstrap.js --lib_js old/jquery.cookie.js --lib_js old/jquery.form.js --lib_js old/jquery.validate.js --lib_js old/myhelpers.js --lib_js old/sails.io.js --lib_js old/socket.io.js --separate_files --skip_gzip --compilation_level NONE
and run the project from root directory: sails lift
After that you can access it at https://localhost
and see the error in the console.
EDIT
I forgot that there is also need to create private and public key for https :/ (put them in the ssl folder in root folder - I may put some exemplar keys later on used only for development purposes).
And there is also need to run redis
http://redis.io database on port 6379
. :/