Skip to content
Snippets Groups Projects
webpack.config.js 1.84 KiB
Newer Older
  • Learn to ignore specific revisions
  • Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    var path = require('path')
    const CopyPlugin = require('copy-webpack-plugin')
    const webpack = require('webpack')
    const fs = require('fs')
    const SvgoInstance = require('svgo')
    
    
    const index = require('./package.json').main
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    
    const readManifest = () =>
      JSON.parse(fs.readFileSync(path.join(__dirname, './manifest.konnector')))
    
    const svgo = new SvgoInstance({
      plugins: [
        {
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
          inlineStyles: { onlyMatchedOnce: false },
        },
      ],
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    })
    
    let iconName
    try {
      iconName = JSON.parse(fs.readFileSync('manifest.konnector', 'utf8')).icon
      // we run optimize only on SVG
      if (!iconName.match(/\.svg$/)) iconName = null
    } catch (e) {
      // console.error(`Unable to read the icon path from manifest: ${e}`)
    }
    const appIconRX = iconName && new RegExp(`[^/]*/${iconName}`)
    
    module.exports = {
    
      entry: {
        index,
        onDeleteAccount: './src/onDeleteAccount.js',
      },
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
      target: 'node',
      mode: 'none',
      output: {
        path: path.join(__dirname, 'build'),
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
      },
      plugins: [
        new CopyPlugin({
          patterns: [
            { from: 'manifest.konnector' },
            { from: 'package.json' },
            { from: 'README.md' },
            { from: 'assets', transform: optimizeSVGIcon },
            { from: '.travis.yml' },
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
            { from: 'LICENSE' },
          ],
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
        }),
        new webpack.DefinePlugin({
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
          __WEBPACK_PROVIDED_MANIFEST__: JSON.stringify(readManifest()),
        }),
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
      ],
      module: {
        // to ignore the warnings like :
        // WARNING in ../libs/node_modules/bindings/bindings.js 76:22-40
        // Critical dependency: the request of a dependency is an expression
        // Since we cannot change this dependency. I think it won't hide more important messages
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
        exprContextCritical: false,
      },
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    }
    
    function optimizeSVGIcon(buffer, path) {
      if (appIconRX && path.match(appIconRX)) {
        return svgo.optimize(buffer).then(resp => resp.data)
      } else {
        return buffer
      }
    }