apache / incubator-weex-loader

Apache License 2.0
65 stars 32 forks source link

0.4.x版本因loadBabelModule打包错误 #56

Closed linkarys closed 7 years ago

linkarys commented 7 years ago

如题,loadBabelModule的实现在某些情况下会出现以下错误(出错环境: mac, node v8.0.0, npm v5.0.3),

img

const defaultLoaders = {
  none: '',
  main: path.resolve(loaderPath, 'loader.js'),
  extract: path.resolve(loaderPath, 'extract.js'),
  template: path.resolve(loaderPath, 'template.js'),
  style: path.resolve(loaderPath, 'style.js'),
  script: path.resolve(loaderPath, 'script.js'),
  json: path.resolve(loaderPath, 'json.js'),
  babel: loadBabelModule('babel-loader')
}

function loadBabelModule (moduleName) {
  try {
    const filePath = require.resolve(moduleName)
    return filePath.slice(0, filePath.lastIndexOf(moduleName) + moduleName.length)
  } catch (e) {
    return moduleName
  }
}

...

loaders.push({
  name: defaultLoaders.babel,
  query: {
    presets: [loadBabelModule('babel-preset-es2015')],
    plugins: [loadBabelModule('babel-plugin-transform-runtime')],
    comments: 'false'
  }
})

此处为什么特意写了一个loadBabelModule, 而不直接使用字符串? @exolution @terrykingcha

refer: https://github.com/weexteam/weex-loader/commit/76cf603b5102af74a8a934458b831829628cdbae

Hanks10100 commented 7 years ago

Fixed in #51 .