Node.js   发布时间:2022-04-24  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Grunt / Yeoman用绝对路径连接javascript文件大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
javascript文件src路径以“/”开头时,我有使用Gruntfile.js的问题.

我按照这个用法http://briantford.com/blog/angular-yeoman.html

认情况下,JS文件包含在内

<!-- build:js scripts/scripts.js -->
        <script src="scripts/app.js"></script>
        <script src="scripts/controllers/main.js"></script>
        <!-- endbuild -->

$ls dist/scripts/
ab541b7e.app.js     afa864c8.scripts.js controllers         vendor
$cat dist/scripts/afa864c8.scripts.js 
"use Strict";var ...
....

App ENGIne应用程序配置require使用“/”前置.

<!-- build:js scripts/scripts.js -->
        <script src="/scripts/app.js"></script>
        <script src="/scripts/controllers/main.js"></script>
        <!-- endbuild -->

Build results in the concatenated file,$ls dist/scripts/
9eecb7db.scripts.js ab541b7e.app.js     controllers         vendor
$cat dist/scripts/9eecb7db.scripts.js

但是,然后连接的脚本文件为空.

完整的Gruntfile如下,未经修改.

@H_700_11@module.exports = function( grunt ) { 'use Strict'; // // Grunt configuration: // // https://github.com/cowboy/grunt/blob/master/docs/getTing_started.md // grunt.initConfig({ // Project configuration // --------------------- // specify an alternate install LOCATIOn for Bower bower: { dir: 'app/components' },// Coffee to JS compilation coffee: { compile: { files: { 'app/scripts/*.js': 'app/scripts/**/*.coffee','test/spec/*.js': 'test/spec/**/*.coffee' } } },// compile .scss/.sass to .css using Compass compass: { dist: { // http://compass-style.org/Help/tutorials/configuration-reference/#configuration-properties options: { css_dir: 'temp/styles',sass_dir: 'app/styles',images_dir: 'app/images',javascripts_dir: 'temp/scripts',force: true } } },// generate application cache manifest manifest:{ dest: '' },// default watch configuration watch: { coffee: { files: 'app/scripts/**/*.coffee',tasks: 'coffee reload' },compass: { files: [ 'app/styles/**/*.{scss,sass}' ],tasks: 'compass reload' },reload: { files: [ 'app/*.html','app/styles/**/*.css','app/scripts/**/*.js','app/views/**/*.html','app/images/**/*' ],tasks: 'reload' } },// default lint configuration,change this to match your setup: // https://github.com/cowboy/grunt/blob/master/docs/task_lint.md#lint-built-in-task lint: { files: [ 'Gruntfile.js','spec/**/*.js' ] },// specifying JSHint options and globals // https://github.com/cowboy/grunt/blob/master/docs/task_lint.md#specifying-jshint-options-and-globals jshint: { options: { curly: true,eqeqeq: true,immed: true,latedef: true,newcap: true,noarg: true,sub: true,undef: true,boss: true,eqnull: true,browser: true },globals: { angular: true } },// Build configuration // ------------------- // the staging directory used during the process staging: 'temp',// final build output output: 'dist',mkdirs: { staging: 'app/' },// Below,all paths are relative to the staging directory,which is a copy // of the app/ directory. Any .gitignore,.ignore and .buildignore file // that might appear in the app/ tree are used to ignore these values // during the copy process. // concat css/**/*.css files,inline @import,output a single minified css css: { 'styles/main.css': ['styles/**/*.css'] },// renames JS/CSS to prepend a hash of @R_450_8917@ contents for easier // versioning rev: { js: 'scripts/**/*.js',css: 'styles/**/*.css',img: 'images/**' },// usemin handler should point to the file containing // the usemin blocks to be parsed 'usemin-handler': { html: 'index.html' },// update references in HTML/CSS to revved files usemin: { html: ['**/*.html'],css: ['**/*.css'] },// HTML minification html: { files: ['**/*.html'] },// Optimizes JPGs and PNGs (with jpegtran & optipng) img: { dist: '<config:rev.img>' },// rjs configuration. You don't necessarily need to specify the typical // `path` configuration,the rjs task will parse these values from your // main module,using http://requirejs.org/docs/optimization.html#mainConfigFile // // name / out / mainConfig file should be used. You can let it blank if // you're using usemin-handler to parse rjs config from markup (default // setup) rjs: { // no minification,is done by the min task optimize: 'none',baseUrl: './scripts',wrap: true } }); // Alias the `test` task to run `testacular` instead grunt.registerTask('test','run the testacular test driver',function () { var done = this.async(); require('child_process').exec('testacular start --single-run',function (err,stdout) { grunt.log.write(stdout); done(err); }); }); };

编辑:

做一些研究导致下面的repo,由yeoman用来替换标记.
https://github.com/yeoman/grunt-usemin

仍然需要弄清楚,添加一个领先的“/”有什么问题

解决方法

实际上,应该支持您的用例.
但请注意:

>在当前0.9.6版的自耕农上,我不确定它是否有效>自耕农目前正在进行大量的返工,很快就会使用grunt-usemin.您的用例应该由grunt-usemin支持

大佬总结

以上是大佬教程为你收集整理的Grunt / Yeoman用绝对路径连接javascript文件全部内容,希望文章能够帮你解决Grunt / Yeoman用绝对路径连接javascript文件所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。