text: const fs                = require('fs');
  const path              = require('path');
  const webpack           = require('webpack');
  const VueLoaderPlugin   = require('vue-loader/lib/plugin');
  const pkg               = require('../package.json');
  
  let cssLoader = '@hippy/vue-css-loader';
  const hippyVueCssLoaderPath = path.resolve(__dirname, '../../../packages/hippy-vue-css-loader/dist/index.js');
  if (fs.existsSync(hippyVueCssLoaderPath)) {
    /* eslint-disable-next-line no-console */
    console.warn(`* Using the @hippy/vue-css-loader in ${hippyVueCssLoaderPath}`);
    cssLoader = hippyVueCssLoaderPath;
  } else {
    /* eslint-disable-next-line no-console */
    console.warn('* Using the @hippy/vue-css-loader defined in package.json');
  }
  
  module.exports = {
    mode: 'development',
    devtool: 'eval-source-map',
    watch: true,
    watchOptions: {
      aggregateTimeout: 1500,
    },
    entry: {
      index: path.resolve(pkg.nativeMain),
    },
    output: {
      filename: 'index.bundle',
      strictModuleExceptionHandling: true,
      path: path.resolve('./dist/dev/'),
    },
    plugins: [
      new VueLoaderPlugin(),
      new webpack.DefinePlugin({
        'process.env': {
          NODE_ENV: JSON.stringify('development'),
          HOST: JSON.stringify(process.env.DEV_HOST || '127.0.0.1'),
          PORT: JSON.stringify(process.env.DEV_PORT || 38989),
        },
        __PLATFORM__: null,
      }),
    ],
    module: {
      rules: [
        {
          test: /\.vue$/,
          use: [
            'vue-loader',
            'scope-loader',
            'unicode-loader',
          ],
        },
        {
          test: /\.js$/,
          use: [
            {
              loader: 'babel-loader',
              options: {
                presets: [[
                  '@babel/preset-env',
                  {
                    targets: {
                      chrome: 57,
                      ios: 9,
                    },
                  },
                ]],
                plugins: [
                  '@babel/plugin-proposal-class-properties',
                ],
              },
            },
            'unicode-loader',
          ],
        },
        {
          test: /\.css$/,
          use: [
            cssLoader,
          ],
        },
        {
          test: /\.less$/,
          use: [
            cssLoader,
            'less-loader',
          ],
        },
        {
          test: /\.(png|jpg|gif)$/,
          use: [{
            loader: 'file-loader',
            options: {
              name: '[name].[ext]',
              outputPath: 'assets/',
            },
          }],
        },
        {
          test: /\.json$/,
          loader: 'json-loader',
        },
      ],
    },
    resolve: {
      extensions: ['.js', '.vue', '.json'],
      modules: [path.resolve(__dirname, '../node_modules')],
      alias: (() => {
        const aliases = {
          vue: '@hippy/vue',
          '@': path.resolve('./src'),
          'vue-router': '@hippy/vue-router',
        };
  
        // If hippy-vue was built exist then make a alias
        // Remove the section if you don't use it
        const hippyVuePath = path.resolve(__dirname, '../../../packages/hippy-vue');
        if (fs.existsSync(path.resolve(hippyVuePath, 'dist/index.js'))) {
          /* eslint-disable-next-line no-console */
          console.warn(`* Using the @hippy/vue in ${hippyVuePath} as vue alias`);
          aliases.vue = hippyVuePath;
        } else {
          /* eslint-disable-next-line no-console */
          console.warn('* Using the @hippy/vue defined in package.json');
        }
  
        // If hippy-vue-router was built exist then make a alias
        // Remove the section if you don't use it
        const hippyVueRouterPath = path.resolve(__dirname, '../../../packages/hippy-vue-router');
        if (fs.existsSync(path.resolve(hippyVueRouterPath, 'dist/index.js'))) {
          /* eslint-disable-next-line no-console */
          console.warn(`* Using the @hippy/vue-router in ${hippyVueRouterPath} as vue-router alias`);
          aliases['vue-router'] = hippyVueRouterPath;
        } else {
          /* eslint-disable-next-line no-console */
          console.warn('* Using the @hippy/vue-router defined in package.json');
        }
  
        // If hippy-vue-router was built exist then make a alias
        // Remove the section if you don't use it
        const hippyVueNativeComponentsPath = path.resolve(__dirname, '../../../packages/hippy-vue-native-components');
        if (fs.existsSync(path.resolve(hippyVueNativeComponentsPath, 'dist/index.js'))) {
          /* eslint-disable-next-line no-console */
          console.warn(`* Using the @hippy/vue-native-components in ${hippyVueNativeComponentsPath}`);
          aliases['@hippy/vue-native-components'] = hippyVueNativeComponentsPath;
        } else {
          /* eslint-disable-next-line no-console */
          console.warn('* Using the @hippy/vue-native-components defined in package.json');
        }
  
        return aliases;
      })(),
    },
  };
  