How to insert image in ionic 2

后端 未结 9 1913
星月不相逢
星月不相逢 2020-12-28 08:10

I\'m new on ionic 2 and i\'m trying to insert an image, but i don\'t realize the real path. inside the file app/pages/getting-started/getting-started.html

&         


        
9条回答
  •  难免孤独
    2020-12-28 08:41

    Personally, I would add the images wherever it makes more sense for you, in your case in the app folder, and add a Gulp task to copy the images to the www/build folder.

    This is how my gulpfile.js lookslike: https://github.com/driftyco/ionic2-app-base/blob/master/gulpfile.js

    I have added this simple task to the gulpfile.js around line 66.

    gulp.task('images', function() {
        gulp.src('app/**/**/*.png')
        .pipe(gulp.dest('www/build'))
    });
    

    Make sure the task images is added to the list of tasks that run before the watch task (the tasks listed inside [..], 3rd line). Also, make sure to run gulpWatch whenever you add a new image for example (line 7)

    gulp.task('watch', ['clean'], function(done){
      runSequence(
        ['images','sass', 'html', 'fonts', 'scripts'],
        function(){
          gulpWatch('app/**/*.scss', function(){ gulp.start('sass'); });
          gulpWatch('app/**/*.html', function(){ gulp.start('html'); });
          gulpWatch('app/**/*.png', function(){ gulp.start('images'); });
          buildBrowserify({ watch: true }).on('end', done);
        }
      );
    });
    

    Alternatively, you can use this gulp plug-in https://www.npmjs.com/package/ionic-gulp-image-task and require it and use in your gulpfile.js similar to the other tasks such as copyHTML, copyFonts, copyScripts here https://github.com/driftyco/ionic2-app-base/blob/master/gulpfile.js

    I hope that makes sense.

提交回复
热议问题