离子连接文件gulp-useref不会连接css和索引文件

时间:2016-01-04 12:39:16

标签: cordova ionic-framework gulp-concat gulp-uglify gulp-useref

我正在尝试让我的离子应用程序准备好进行生产,但是gulp-useref有一些错误

在我的索引文件

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Security-Policy">
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title></title>

    <link href="lib/ionic/css/ionic.css" rel="stylesheet">

    <!-- build:css dist_css/styles.css -->
    <link href="css/font-awesome.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">
    <link href="css/select.css" rel="stylesheet">
    <link href="css/ionic.app.css" rel="stylesheet">
    <link href="css/selectize.css" rel="stylesheet">
    <!-- endbuild -->

    <link href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css" rel="stylesheet"/>
    <link href='https://fonts.googleapis.com/css?family=RobotoDraft:400,500,700,400italic' rel='stylesheet' type='text/css'>
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <link href="lib/ionic-material/dist/ionic.material.min.css" rel="stylesheet">
    <link href="lib/ion-autocomplete/dist/ion-autocomplete.css" rel="stylesheet">
    <link href="lib/ionic-toast/src/style.css" rel="stylesheet">


    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
    <link href="css/ionic.app.css" rel="stylesheet">
    -->
    <script src="lib/ionic/js/ionic.bundle.js"></script>

    <script src="lib/angular-mocks/angular-mocks.js"></script>
    <script src="lib/angular-http-auth/src/http-auth-interceptor.js"></script>
    <script src="lib/angular-ui-router/release/angular-ui-router.js"></script>
    <script src="lib/ui-select/dist/select.js"></script>
    <script src="lib/ion-autocomplete/dist/ion-autocomplete.js"></script>
    <script src="lib/angular_ios9_patch/angular-ios9-uiwebview.patch.js"></script>
    <script src="lib/ionic-material/dist/ionic.material.min.js"></script>
    <script src="lib/angular-filters/dist/angular-filters.js"></script>
    <script src="lib/angular-messages/angular-messages.js"></script>
    <script src="lib/ng-file-upload/ng-file-upload.min.js"></script>
    <script src="lib/ionic-toast/dist/ionic-toast.bundle.min.js"></script>
    <script src="lib/ngstorage/ngStorage.min.js"></script>

    <!-- cordova script (this will be a 404 during development) -->
    <script src="lib/ngCordova/dist/ng-cordova.min.js"></script>
    <script src="cordova.js"></script>

    <!-- your app's js -->
    <!-- build:js dist_js/app.js -->
    <script src="dist/dist_js/app/app.js"></script>
    <script src="dist/dist_js/app/routes.js"></script>
    <script src="dist/dist_js/app/controllers/controllers.js"></script>
    <script src="dist/dist_js/app/services/services.js"></script>
    <script src="dist/dist_js/app/AppSettings.js"></script>
    <!-- endbuild -->

    <!-- build:js dist_js/templates.js -->
        <script src="dist/dist_js/app/templates.js"></script>
        <!-- endbuild -->
  </head>
  <body ng-app="app" ng-strict-di>
    <ion-nav-view nav-swipe="" nav-view-direction="none" nav-view-transition="ios" class="view-container"></ion-nav-view>
  </body>
</html>

和我的gulpfile.js

var useref = require('gulp-useref');
var paths = {
    useref: ['./www/*.html']
  };
gulp.task('default', ['sass', 'templatecache', 'ng_annotate', 'useref']);

gulp.task('watch', function() {
    gulp.watch(paths.sass, ['sass']);
    gulp.watch(paths.templatecache, ['templatecache']);
    gulp.watch(paths.ng_annotate, ['ng_annotate']);
    gulp.watch(paths.useref, ['useref']);
  });

gulp.task('useref', function (done) {
  gulp.src('./www/templates/**/*.html')
    .pipe(useref())
    .pipe(gulpif('*.css', minifyCss()))
    .pipe(gulp.dest('./www/dist'))
    .on('end', done);
});

我在after_prepare hook中有这个文件

var androidPlatformsDir_dist_css = path.resolve(__dirname, '../../platforms/android/assets/www/dist/dist_css');
var androidPlatformsDir_dist_js = path.resolve(__dirname, '../../platforms/android/assets/www/dist/dist_js');
var androidPlatformsDir_dist_index = path.resolve(__dirname, '../../platforms/android/assets/www/dist/index.html');
var androidPlatformsDir_www_css = path.resolve(__dirname, '../../platforms/android/assets/www/dist_css');
var androidPlatformsDir_www_js = path.resolve(__dirname, '../../platforms/android/assets/www/dist_js');
var androidPlatformsDir_www_index = path.resolve(__dirname, '../../platforms/android/assets/www/index.html');

console.log("Moving dist files to Android platform");
mv(androidPlatformsDir_dist_css, androidPlatformsDir_www_css, {mkdirp: true}, function(err) {
  if(typeof err != 'undefined')
  {
    console.log("err");
    console.log(err);
    console.log("ERROR when moving CSS folder to Android platform");
  }
  else
  {
    console.log("CSS folder moved OK to Android platform");
  }

});

mv(androidPlatformsDir_dist_js, androidPlatformsDir_www_js, {mkdirp: true}, function(err) {
  if(typeof err != 'undefined')
  {
    console.log("err");
    console.log(err);
    console.log("ERROR when moving JS folder to Android platform");
  }
  else
  {
    console.log("JS folder moved OK to Android platform");
  }
});

mv(androidPlatformsDir_dist_index, androidPlatformsDir_www_index, function(err) {
  if(typeof err != 'undefined')
  {
    console.log("err");
    console.log(err);
    console.log("ERROR when moving index.html file to Android platform");
  }
  else
  {
    console.log("index.html file moved OK to Android platform");
  }
});

我添加了&#34; useref&#34;在我的ionic.project文件中的gulpStartupTasks中,但每当我运行ionic build android时,我都会收到错误

{ [Error: ENOENT, rename '/home/k1ngsley/Projects/mobile_rea/platforms/android/assets/www/dist/index.html']
  errno: 34,
  code: 'ENOENT',
  path: '/home/k1ngsley/Projects/mobile_rea/platforms/android/assets/www/dist/index.html' }
ERROR when moving index.html file to Android platform
err
{ [Error: ENOENT, rename '/home/k1ngsley/Projects/mobile_rea/partners-mobile-app/platforms/android/assets/www/dist/dist_css']
  errno: 34,
  code: 'ENOENT',
  path: '/home/k1ngsley/Projects/mobile_rea/partners-mobile-app/platforms/android/assets/www/dist/dist_css' }
ERROR when moving CSS folder to Android platform

为什么它不使用新的index.html以及dist_css文件夹wt styles.css创建dist文件夹?

感谢任何帮助

0 个答案:

没有答案