var path = require('path')
var cssLoaders = require('./css-loaders')
var projectRoot = path.resolve(__dirname, '../')
const HappyPack = require('happypack')

module.exports = {
  entry: {
    app: './src/android.js'
  },
  output: {
    path: path.resolve(__dirname, '../dist-android/static'),
    publicPath: 'static/',
    filename: '[name].js'
  },
  resolve: {
    extensions: ['', '.js', '.vue'],
    fallback: [path.join(__dirname, '../node_modules')],
    alias: {
      'src': path.resolve(__dirname, '../src')
    }
  },
  resolveLoader: {
    fallback: [path.join(__dirname, '../node_modules')]
  },
  module: {
    loaders: [
      {
        test: /\.vue$/,
        // loader: 'vue'
        loader: 'happypack/loader?id=happyvue'
      },
      {
        test: /\.js$/,
        // loader: 'babel',
        include: [
          /src/,
          /build/,
          /examples/,
          /test/,
          /node_modules\/vue-client\/src/,
          /node_modules\/vue-strap\/src/,
          /node_modules\/system-clients\/src/,
          /node_modules\/ldap-clients\/src/,
          /node_modules\/sale-client\/src/,
          /node_modules\/manage-client\/src/,
          /node_modules\/address-client\/src/,
          /node_modules\/apply-clients\/src/,
          /node_modules\/telephone-clients\/src/,
          /node_modules\/safecheck-client\/src/,
          /node_modules\/webmeter-client\/src/,
          /node_modules\/material-client\/src/,
          /node_modules\/weixin-manage-client-wsd\/src/,
          /node_modules\/annunciator-client\/src/
        ],
        options: {
          presets: ['es2015']
        },

        loader: 'happypack/loader?id=happybabel'
      },
      {
        test: /\.json$/,
        // loader: 'json'
        loader: 'happypack/loader?id=happyjson'
      },
      {
        test: /\.html$/,
        // loader: 'vue-html'
        loader: 'happypack/loader?id=happyhtml'
      },
      {
        test: /\.less$/,
        // loader: 'style!css!less'
        loader: 'happypack/loader?id=happyless'
      },
      {
        test: /\.css$/,
        loader: 'style!css'
      },
      {
        test: /\.(png|jpg|gif|svg|woff2?|eot|ttf)(\?.*)?$/,
        loader: 'url',
        query: {
          limit: 10000,
          name: '[name].[ext]?[hash:7]'
        }
      }
    ]
  },
  vue: {
    loaders: cssLoaders({
      sourceMap: false,
      extract: false
    })
  },
  plugins: [
    new HappyPack({
      // 用唯一的标识符 id 来代表当前的HappyPack 是用来处理一类特定的文件
      id: 'happybabel',
      // 如何处理 .js 文件，用法和 Loader配置中一样
      loaders: ['babel']
    }),
    new HappyPack({
      id: 'happyvue',
      loaders: ['vue']
    }),
    new HappyPack({
      id: 'happyjson',
      loaders: ['json']
    }),
    new HappyPack({
      id: 'happyhtml',
      loaders: ['vue-html']
    }),
    new HappyPack({
      id: 'happyless',
      loaders: ['style!css!less']
    })
  ],
  eslint: {
    formatter: require('eslint-friendly-formatter')
  }
}
