How Gulp + sourcemaps work for debugging - build

So I just got set up with Gulp yesterday and after a rocky start I'm well on my way to automating build processes, but I decided to try and do something a teensy bit trickier and suddenly hit another wall.
My desired output is to have a minified javascript file which I can serve to the browser and, upon inspecting in Chrome or Firefox, see the original source code. Pretty simple, right?
I currently have the following in my gulpfile:
gulp.task('minify', function() {
gulp.src('./sources/**/*.js')
.pipe(sourcemaps.init())
.pipe(minify({
ext:{
src:'.js',
min:'.min.js'
}
}))
.pipe(sourcemaps.write('maps'))
.pipe(gulp.dest('./www/js'));
});
This successfully generates the sourcemaps in ./www/js/maps/ and it puts the following at the bottom of the uncompressed files:
//# sourceMappingURL=maps/<whatever>.js.map
However it does not append such a comment to the bottom of the compressed files. As such when I open these files in a browser it's unable to show me the original source.
What am I doing wrong?

You can try this:
gulp.task('minify', function() {
gulp.src('./sources/**/*.js')
.pipe(sourcemaps.init())
.pipe(minify({
ext:{
src:'.js',
min:'.min.js'
}
}))
.pipe(sourcemaps.write('maps', {
addComment: true
}))
.pipe(gulp.dest('./www/js'));
});

Related

ember-electron application start (code hierarchy)

I'm trying to move a very old 2.x ember-electron application to new electron with ember-electron and got application window with blank screen and error in console:
(node:9061) electron: Failed to load URL: serve://dist/ with error: ERR_FILE_NOT_FOUND
The calling file ../new-ember-electron/electron-app/src/index.js has lines from old applications:
const emberAppLocation = 'serve://dist';
mainWindow.loadURL(emberAppLocation);
File ../new-ember-electron/app/router.js has:
this.route('index', { path: '/' }, function() {}
Files ../new-ember-electron/app/routes/index.js, ../new-ember-electron/app/controllers/index.js and ../new-ember-electron/app/templates/index.hbs also exist.
So, it's unclear what exactly is not found and how to find a more detailed error (application developer console doesn't have errors). But if to change the mentioned 2 lines in ../new-ember-electron/electron-app/src/index.js to:
const emberAppLocation = '../app/index.html';
mainWindow.loadFile(emberAppLocation);
then application shows content of the correct file, despite nothing working in it, even <LinkTo>...</LinkTo> is not treated as a link.
Would you please help me to understand how an ember-electron application should be structured and which way is called for the recent versions?
Used versions: node - 16.14.0, electron: 17.0.1, ember-cli: 3.28.5, ember-electron: 3.1.0, OS: darwin x64.
Thank you.
Thank you, jacobq, I've looked at your example and used emberAppUrl to start from ember-dist/index.html file. After few more changes related to require/requireNode (fixed with webPreferences options in mainWindow) the app rendered index.html file. But a problem with app location happens again right on {{ content-for "body" }} in index.html: "Uncaught Error: Cannot find module 'app-name/app'" where app-name is the application name set up as 'name' in /package.json and as 'modulePrefix' in config/environment.js. The error itself comes from /node-modules/ember-cli/lib/utilities/ember-app-utils.js, 'contentFor' function called with 'app-boot'. The ember-cli itself constructs the /app-name/app path. So, the question now is what exactly ember-cli expects to find during the boot with the new structure? Or maybe some config variable should be added to let know Ember about the /app-name/app location?
Edited:
jacobq, yes, the only difference in index.html is application name: "testapp". RootURL is set in ../testapp/config/environment.js:
podModulePrefix: 'testapp/pods',
environment,
modulePrefix: 'testapp',
rootURL: process.env.EMBER_CLI_ELECTRON ? '' : '/',
locationType: process.env.EMBER_CLI_ELECTRON ? 'hash' : 'auto',
The full error:
It happens when testapp.js file is called from index.html, on code included from ember-cli:
if (!runningTests) {
require("testapp/app")["default"].create({"LOG_TRANSITIONS":true,"LOG_TRANSITIONS_INTERNAL":true});
}
First thing I'd like to plug is joining the #topic-desktop channel on the Ember.js community Discord server: https://discord.com/channels/480462759797063690/488735754139336714
(it's often easier to work things out by chatting there as there's lower latency than typically found with forum post/reply platforms)
Secondly, there are lots of breaking (but good) changes between ember-electron 2.x and 3.x, so I'd encourage you to work through the upgrade guide here: https://ember-electron.js.org/docs/guides/upgrading
That said, I suspect that the problem you're seeing is related to the change from serve:// to file://. Have a look at the demo app I just spun up here:
https://github.com/jacobq/ember-electron-demo
You can see the new emberAppURL here:
https://github.com/jacobq/ember-electron-demo/blob/cf7c5dee2cd975f8c67ed1dfc61eb717461f5b7d/electron-app/src/index.js#L13
Basically, ember-electron v3.x puts the usual dist output from ember build into <project_root>/electron-app/ember-dist/ now.
FWIW, I'm actually stuck on 3.0.0-beta.2 in my application because I am using IndexedDB and don't have migration code to deal with origin-related issues of switching to file:// scheme. I don't recommend that you use that version, but you could try it if you wanted to see if that changes the error you're encountering (because that beta still uses electron-protocol-serve).

Ember build and sourcemaps

My Ember app is actually a child engine. Recently, I observed that the source maps are not working properly in Chrome. So, I have to open the generated engine.js to debug…Instead I want to be able to open the individual source modules/files written in ES6 using Ctrl + P in Chrome Sources and add breakpoints to debug.
I tried both the ways in ember-cli-build.js;
babel: { sourceMaps: ‘inline’ }
sourcemaps: { enabled: true, extensions: [‘js’] }
My question is am I doing something wrong with the above? Does the parent/host app have any impact on the generated source map OR is the child engine configuration for sourcemap totally independent of the parent config ?

Ionic file opener

I am developing an app for android, ios and windows. One of the requirements is being able to download a pdf that is stored in the assets folder in the ionic app. I am using this plugin https://ionicframework.com/docs/native/file-opener/. I am executing this code as per the documentation.
this.fileOpener.open(‘assets/pdf-test.pdf’, ‘application/pdf’)
.then(() => console.log(‘File is opened’))
.catch(e => console.log(‘Error openening file’, e));
However I get the following error
“file not found”
Please help
assetsfolder only works in your app. What you are telling these others apps to do is to read help_doc.pdf out of their assets, and they do not have such a file.
try this code , but if not work , some time browser not support open pdf , then go must go with plugin fileOpener2
var location = cordova.file.applicationDirectory +"www/assets/MobiMedPrivacyPolicy.pdf";
window.resolveLocalFileSystemURL(location, function(fileEntry) {
window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory + '/Download/', function(dirEntry) {
fileEntry.copyTo(dirEntry, "MobiMedPrivacyPolicy.pdf", function(newFileEntry) {
window.open(newFileEntry.nativeURL, '_blank', 'location=no');
});
});
},function(error)
{
console.log(error)
});

Ionic 2 not seeing images

Im currently working with Ionic 2.0.0-beta.32. After some searching around, I found the following code to add images to my project then at build time have them auto import into the final build
I add a directory in app called img, and place all my images in there, then the code in the gulpfile is as follows
gulp.task('images', function() {
return gulp.src(['app/img/*'])
.pipe(gulp.dest('www/build/img'));
});
and also all the runSequences
runSequence(
['images', 'sass', 'html', 'fonts', 'scripts'],
This all works good and moves the images to the www at build time, but when i run
ionic serve --lab
none of the images show, I've tried using the following
../img/imgname
/img/imgname
img/imgname
build/img/imgname
None of the above shows my image.
Any help would be great, im pulling out my hair here
Do you want to use Gulp to modify your images (i.e., reduce their sizes) or something like that? If the answer is no, then you don't need to add that task to your gulp file
gulp.task('images', function() {
return gulp.src(['app/img/*'])
.pipe(gulp.dest('www/build/img'));
});
Why? Because if the image won't be changed, it doesn't make sense that each time that you run your tasks, the images gets copied again and again (without changes).
A simple way to work with images would be to put your images in a www\images folder, and then reference them in your code like this:
<img src="images/myImage.png" />
Since they're in the www folder, they're not going to be deleted (which happens if you place them in the build folder of your app).

CaptureError.CAPTURE_INTERNAL_ERR on Android trying to use capture.captureImage

I am trying to write a hybrid app for Android using VS 2013 update 3 and the multi-device hybrid app extension (Cordova v3.5.0). Everything is working well except the Media Capture plugin. I am calling navigator.device.capture.captureImage(MediaCaptureSuccess, MediaCaptureError, { limit: 3 }) which opens up the camera app. I can take a picture but when I click Ok on the device, my error callback is executed with CaptureError.CAPTURE_INTERNAL_ERR with no other information. I have tried switching to org.apache.cordova.media-capture#0.3.4 (currently using 0.3.1) but when I try to compile, I get a plugman error when it tries to retrieve it. I have searched the debug output for clues and the only thing that I found was the following line "Unknown permission android.permission.RECORD_VIDEO in package..." but that seems to be a valid user permission. When I look at capture.java generated by the build, I can see that this error is returned if there is an IOException occurs.
Does anyone have any suggestions on how to fix this or what to check next?
Try this plugin
Config:
<vs:feature>org.apache.cordova.camera#0.3.0</vs:feature>
JS:
navigator.camera.getPicture(onSuccess, onFail, {
quality: 30,
destinationType: Camera.DestinationType.FILE_URI,
saveToPhotoAlbum: true
});