o2team/elf

在webpack.base.js文件中增加了编译es6,但是报错了

Closed this issue · 15 comments

uaio commented
module: {
    loaders: [{
      test: zeptoPath,
      loader: 'exports?window.$!script'
    }, {
      test: /\.(mp3|mp4|webm|mov|ogg|ogv)(\?\S*)?$/,
      exclude: /node_modules/,
      loader: 'file-loader?' + JSON.stringify(config.audioLoaderQuery),
    }, {
      test: /\.html$/,
      exclude: /node_modules/,
      loader: 'html'
    },{
        test: /\.jsx?$/,
        exclude: /(node_modules|bower_components)/,
        loader: 'babel',
        query: {
            presets: ['es2015']
        }
       
    }]
  }

报什么错?

uaio commented

ERROR in ./src/js/main.js
Module build failed: Error: Couldn't find preset "es2015" relative to directory "D:\azq\elftest\demo\src\js"
at C:\Users\zhiqingan\AppData\Roaming\npm\node_modules\elf-cli\node_modules\babel-core\lib\transformation\file\options\option-manager.js:293:19
at Array.map (native)
at OptionManager.resolvePresets (C:\Users\zhiqingan\AppData\Roaming\npm\node_modules\elf-cli\node_modules\babel-core\lib\transformation\file\options\option-manager.js:275:20)
at OptionManager.mergePresets (C:\Users\zhiqingan\AppData\Roaming\npm\node_modules\elf-cli\node_modules\babel-core\lib\transformation\file\options\option-manager.js:264:10)
at OptionManager.mergeOptions (C:\Users\zhiqingan\AppData\Roaming\npm\node_modules\elf-cli\node_modules\babel-core\lib\transformation\file\options\option-manager.js:249:14)
at OptionManager.init (C:\Users\zhiqingan\AppData\Roaming\npm\node_modules\elf-cli\node_modules\babel-core\lib\transformation\file\options\option-manager.js:368:12)
at File.initOptions (C:\Users\zhiqingan\AppData\Roaming\npm\node_modules\elf-cli\node_modules\babel-core\lib\transformation\file\index.js:212:65)
at new File (C:\Users\zhiqingan\AppData\Roaming\npm\node_modules\elf-cli\node_modules\babel-core\lib\transformation\file\index.js:135:24)
at Pipeline.transform (C:\Users\zhiqingan\AppData\Roaming\npm\node_modules\elf-cli\node_modules\babel-core\lib\transformation\pipeline.js:46:16)
at transpile (C:\Users\zhiqingan\AppData\Roaming\npm\node_modules\elf-cli\node_modules\babel-loader\lib\index.js:46:20)
at Object.module.exports (C:\Users\zhiqingan\AppData\Roaming\npm\node_modules\elf-cli\node_modules\babel-loader\lib\index.js:163:20)
@ multi main

Module build failed: Error: Couldn't find preset "es2015" relative to directory "D:\azq\elftest\demo\src\js"

安装了 es2015 presets 吗?

uaio commented

我在 ele-cli里装的babel-core babel-loader babel-preset-es2015
这个三个依赖,我试试在项目里加试试

uaio commented

在项目里加了,可以了,每次加好麻烦啊

你把

        query: {
            presets: ['es2015']
        }

修改为

        query: {
            presets: ['es2015'].map(require.resolve)
        }

试试

uaio commented

module.js:471
throw err;
^

Error: Cannot find module 'es2015'
at Function.Module._resolveFilename (module.js:469:15)
at resolve (internal/module.js:27:19)
at Array.map (native)
at Object. (C:\Users\zhiqingan\AppData\Roaming\npm\node_modules\elf-cli\webpack\webpack.base.js:53:33)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object. (C:\Users\zhiqingan\AppData\Roaming\npm\node_modules\elf-cli\webpack\webpack.config.dev.js:7:27)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)

用包的全称 es2015 -> babel-preset-es2015

uaio commented

好了,3Q

你这是用在什么项目上?
这样修改了 webpack.base.js 往后就不好升级了

uaio commented

我们这项目一般用es6所以我就加上了,那放到webpack.build里,还是修改项目里的配置文件?技术水平还没达到自己写脚手架呢,请大神指点下;

目前自定义配置还不支持增加 loader,所以,只能像你现在这样修改 webpack 配置文件。

uaio commented

是啊,我看了自定义的配置了,还有,你们模板是放到了线上么,init的时候拉取?

是的,默认提供的模板在 https://github.com/elf-templates ,你也可以基于自己的模板初始化

uaio commented

好的谢谢