繁体   English   中英

Grunt / Webpack / Babel中的路径错误

[英]Path error in Grunt/Webpack/Babel

我第一次使用ES6模块,试图使Webpack进行基本捆绑。 我想在Webpack加载程序中使用Babel 6(当前是最新的和最大的)进行转译。 我已经读过这个这个这个

package.json包括:

 "devDependencies": {
    "babel": "~6.0.12",
    "babel-core": "~6.0.12",
    "babel-loader": "~6.0.0",
    "babel-preset-es2015": "^6.0.14",
    "grunt": "~0.4.5",
    "grunt-webpack": "^1.0.11",
    "webpack": "^1.12.2",
    "webpack-dev-server": "^1.12.1"
  },

文件结构:

myproject
├── js
│   ├── es6
│   │   ├── app.js
│   │   ├── lib
│   │   │   ├── lib1.js
│   │   │   ├── lib2.js
│   │   └── modules
│   │       └── _myModule.js
├── node_modules
├── index.html
├── gruntfile.js

gruntfile.js

module.exports = function(grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

        webpack: {
            options: {
                entry: "./js/es6/app.js",
                output: {
                    path: __dirname,
                    filename: "webpacked.js",
                },
                module : {
                    loaders: [
                        {

       // grunt --verbose says the problem is with the next line
                            include: path.resolve(__dirname, "es6"),
                            loader: 'babel',    
                            query: {
                                presets: ['es2015']
                            }
                        }
                    ]
                },
                failOnError: true,
                resolve: {
                    root: [ "js", "node_modules" ],
                }       
            },
            build : {
                devtool: "sourcemap",
                debug: true
            }
        },

    });

    grunt.loadNpmTasks('babel');
    grunt.loadNpmTasks('babel-core');
    grunt.loadNpmTasks('babel-loader');
    grunt.loadNpmTasks('babel-preset-es2015');
    grunt.loadNpmTasks('grunt-minify-html');
    grunt.loadNpmTasks('grunt-webpack');    
    grunt.loadNpmTasks('grunt-sass');
    grunt.loadNpmTasks('grunt-contrib-watch');

    grunt.registerTask('default', ['webpack']);
};

我显然在路径处理中缺少一些非常基本的东西。 我什至无法开始,而且我已经兜圈子了几个小时,尝试了很多组合。 错误是:

Loading "Gruntfile.js" tasks...ERROR
>> ReferenceError: path is not defined

任何帮助非常感谢。

你在做

include: path.resolve(__dirname, "es6"),

并使用path模块,但尚未加载它。

var path = require('path');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM