我正在尝试让我的 ionic 应用程序为生产做好准备,但 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 钩子中有这个文件
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");
}
});
我在我的 ionic.project 文件的 gulpStartupTasks 中添加了“useref”,但是每当我运行时,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 文件夹以及 dist_css 文件夹 wt styles.css?
任何帮助表示赞赏