the*_*hey 0 javascript node.js gruntjs grunt-babel
我是 Grunt 及其所有插件的新手,但我想学习和设置一些很棒的前端工具。话虽如此,我一直在通过Github关注Grunt 文档以及 Grunt 和 Babel 的一些类似问题,但我似乎不断收到以下回溯:
Running "babel:dist" (babel) task
Warning: Unable to write "dist" file (Error code: EISDIR). Use --force to continue.
Aborted due to warnings.
任何对这个新手更清晰的解释将不胜感激。我是 JS 编程和设置 DevOps 的新手,因此鼓励提供一些有用的提示和最佳实践。
设置:
js_practice/ (根项目) 
|----package.json
所有发行版和包
|---node_modules/
服务器端(节点)支持
|---es6/ 
| ------ test.js 
|---dist/
客户端(浏览器)支持
|----public/ 
|---es6/ (位于 public 文件夹内)
| ----- test2.js 
|---dist/ (这是在公共文件夹中)
这是我当前的代码:
Grunt 文件.js
module.exports = function(grunt) {
        // All of your Grunt code must be specified inside this function!
        // Setup configuration...
    // Load tasks...
    // Define tasks...
    grunt.initConfig({
            pkg: grunt.file.readJSON('package.json'),
            babel: {
                     options: {
                             sourceMap: true,
                             presets: ['babel-preset-es2015']
                     },
                     dist: {
                             files: [
                                 // Node source
                                 {
                                 src: ['es6/**/*.js'],
                                 dest: 'dist'},
                                 // Browser source
                                {
                                    src: ['public/es6/**/*.js'],
                                    dest: 'public/dist'},
                        ],
                    },
             },
            browserify: {
           dist: {
             options: {
               transform: [["babelify", { "stage": 0 }]]
             },
             files: {
               "build/bundle.js": "src/main.js"
             }
           }
             },
        jshint: {
            scripts: {
                src: ['scripts/**.js', 'lib/**.js']
            },
            tests: { // We can have more than one jshint task, this ones called `jshint:tests`
                src: 'tests/**.js'
            }
        },
                uglify: {
              options: {
                banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
              },
              build: {
                src: 'src/<%= pkg.name %>.js',
                dest: 'build/<%= pkg.name %>.min.js'
              },
            scripts: {
                expand: true,
                cwd: 'scripts/',
                src: '**.js',
                dest: 'build/',
                ext: '.min.js'
            }
        },
        watch: {
                    scripts: {
                    files: ['**/*.js'],
                    tasks: ['jshint'],
                        },
            styles: {
                files: 'styles/**.less',
                task: 'less:styles'
            }
        }
    });
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-less');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-browserify');
    grunt.loadNpmTasks('grunt-babel');
    grunt.registerTask('default', ['babel','browserify','jshint']);
    grunt.registerTask('build', ['jshint', 'uglify']);
};
只是扩展我在评论中所说的内容
任何对这个新手更清晰的解释将不胜感激。
Nodejs 正在尝试写入一个名为 的文件dist,但会产生错误,因为存在具有该名称的目录。
原因可以在babel任务中找到。
  files: [{
      src: ['es6/**/*.js'],
      dest: 'dist'
    },
    // Browser source
    {
      src: ['public/es6/**/*.js'],
      dest: 'public/dist'
    }]
你必须告诉 Babel 获取每个文件es6/,对其进行转换并将新文件放入dist/文件夹中。就目前而言,变压器尝试创建一个名为 dist.txt 的文件。将其重写为
  files: [{
      expand: true,
      cwd: 'es6/'
      src: ['**/*.js'],
      dest: 'dist/'
    },
    // Browser source
    {
      expand: true,
      cwd: 'public/es6/'
      src: ['**/*.js'],
      dest: 'public/dist/'
    }]
应该会产生更好的结果,但可以尝试一下。正如我提到的,我已经有一段时间没有使用 Grunt 了。查看有关构建文件对象的文档
正如我在评论中所说,使用 jshint 或其他此类工具(eslint 是所有炒作......)来保持您自己的代码整洁。不要浪费时间对您可能不想自行修复的 lib 文件运行 jshint 任务。并且始终在源文件上运行 jshint,而不是由 babel 或 browserify 转换的文件。它只是一个帮助您编写更好代码的工具,而不是某个生成器。
| 归档时间: | 
 | 
| 查看次数: | 1552 次 | 
| 最近记录: |