Skip to content
Snippets Groups Projects
app.config.environment.dev.js 2.13 KiB
'use strict'

const webpack = require('webpack')
const merge = require('webpack-merge')
const { useHotReload, devtool } = require('cozy-scripts/config/webpack.vars')

let plugins = [
  new webpack.DefinePlugin({
    __DEVELOPMENT__: true,
  }),
]

// In development, the bar and cozy-client-js are provided automatically. We use the ProvidePlugin
// since it allows us to use in production the cozy.bar and cozy.client declared by the <script />
// line injected by the stack, while in developement to have it "served" from
// our node_modules
const stackProvidedLibsConfig = {
  plugins: [
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': JSON.stringify('development'),
      __IS_ALPHA__: true,
      __DEVELOPMENT__: true,
      __STACK_ASSETS__: true,
      __PIWIK_TRACKER_URL__: JSON.stringify('https://statweb.grandlyon.com/'),
      __PIWIK_SITEID__: 117,
      __SAU_LINK__: JSON.stringify(
        'https://portail-citoyen-sau.guichet-recette.grandlyon.com/ecolyo/'
      ),
      __SAU_IDEA_DIRECT_LINK__: JSON.stringify(
        'https://demarches-sau.guichet-recette.grandlyon.com/retour-ecolyo/ecolyo-une-idee/'
      ),
      __SAU_ISSUE_DIRECT_LINK__: JSON.stringify(
        'https://demarches-sau.guichet-recette.grandlyon.com/retour-ecolyo/ecolyo-un-probleme/'
      ),
      __SENTRY_DSN__: JSON.stringify(
        'https://c868f6010f3f431d95be8f70d7f37666@grandlyon.errors.cozycloud.cc/6'
      ),
    }),
  ],
  module: {
    rules: [
      {
        test: /cozy-bar(\/|\\)dist(\/|\\)cozy-bar\.min\.js$/,
        // Automatically import the CSS if the JS is imported.
        // imports-loader@0.8.0 works but imports-loader@1.0.0 does not
        loader: 'imports-loader?css=./cozy-bar.min.css',
      },
    ],
  },
}

const output = {}
if (useHotReload) {
  plugins = plugins.concat([new webpack.HotModuleReplacementPlugin()])
  output.globalObject = 'this'
}

module.exports = merge(
  {
    devtool: devtool || 'cheap-module-eval-source-map',
    mode: 'development',
    externals: ['cozy'],
    plugins,
    output,
    optimization: {
      removeAvailableModules: false,
      removeEmptyChunks: false,
    },
  },
  stackProvidedLibsConfig
)