我第一次使用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');
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句