Ionic 2 项目架构(图片)

Ionic 2 project architecture (images)

Ionic 2项目中,放置图片的正确位置是什么? 在一些博客中,人们说将所有图像放在 www\build\"images_folder" 中, 但问题是当你 build 项目或命令时:ionic serve 你的构建文件夹被完全删除并从头开始重建并且你丢失了所有图像。

当你 运行 ionic serve 所有 javascript 和样式文件都被编译并放在一起(在其他任务中)在你的 build 文件夹中,这就是为什么如果你在那里放了一些东西,被删除了。

为了避免这种情况,您应该将图像放在 www\images 中,然后通过执行以下操作在您的代码中引用它们:

<img src="images/myImage.png" />

======================

编辑:

您可以通过以下方式找到有关 运行 ionic serve(以及 emulatedeploybuild)时发生的事情的更多信息看看你的 gulpfile.js:

/**
 * Ionic hooks
 * Add ':before' or ':after' to any Ionic project command name to run the specified
 * tasks before or after the command.
 */
gulp.task('serve:before', ['watch']);
gulp.task('emulate:before', ['build']);
gulp.task('deploy:before', ['build']);
gulp.task('build:before', ['build']);

在 gulpfile.js 的最后几行代码中,您可以看到:

gulp.task('clean', function(){
  return del('www/build');
});

这就是导致构建文件夹被删除的原因。