Reputation: 11502
I'm toying with ES6 modules for the first time, trying to get basic bundling going with Webpack. I'd like to use use Babel 6 (currently the latest and greatest) for transpiling in the Webpack loader. I've read this and this and this.
package.json includes:
"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"
},
file structure:
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']);
};
I'm obviously missing something really basic with path handling. I can't even get started, and I've gone in circles for hours, trying lots of combinations. Error is:
Loading "Gruntfile.js" tasks...ERROR
>> ReferenceError: path is not defined
Any help very appreciated.
Upvotes: 0
Views: 1318
Reputation: 161457
You are doing
include: path.resolve(__dirname, "es6"),
and using the path
module, but you have not loaded it.
var path = require('path');
Upvotes: 6