=========================================
Documentation Theme1-bundle
=========================================

.. sectnum::

.. contents:: Table des contenus

Installer le bundle
~~~~~~~~~~~~~~~~~~~~~~~~~

.. code-block:: terminal

    $ composer require "cpcreation/theme1-bundle" "dev-master@dev"

Activer le Bundle
~~~~~~~~~~~~~~~~~~~~~~~~~

Ajouter dans :file:config/bundles.php

.. code-block:: php

	CpCreation\Theme1Bundle\CpCreationTheme1Bundle::class => ['all' => true],


Dépendances JS
~~~~~~~~~~~~~~~~~~~~~~~~~

Voici la liste des dépendances JS a ajouter au projet pour faire fonctionner correctement le theme1-bundle.

Polyfill (ie11)
"""""""""""""""""""""""""""""""""""
.. code-block:: json

    {
  "dependencies": {
    "custom-event-polyfill": "^1.0.7",
    "element-matches-polyfill": "^1.0.0",
    "intersection-observer": "^0.11.0",
    "tippy.js": "^6.2.6",
    "unorm": "^1.6.0",
    "regenerator-runtime": "^0.13.7",
  },

Le packages json complet pour le theme1-bundle

.. code-block:: json

	{
    "dependencies": {
      "@babel/core": "^7.7.0",
      "@babel/plugin-transform-runtime": "^7.11.5",
      "@babel/preset-env": "^7.7.0",
      "@fortawesome/fontawesome-free": "^5.11.2",
      "@symfony/webpack-encore": "^0.28.1",
      "animate.css": "^3.6.1",
      "babel-loader": "^8.0.5",
      "brotli-webpack-plugin": "^1.1.0",
      "core-js": "^3.4.1",
      "custom-event-polyfill": "^1.0.7",
      "default-passive-events": "^1.0.10",
      "dotenv": "^6.2.0",
      "element-matches-polyfill": "^1.0.0",
      "es6-promise": "^4.2.4",
      "file-loader": "^1.1.11",
      "foundation-sites": "^6.5.3",
      "intersection-observer": "^0.11.0",
      "isotope-layout": "^3.0.6",
      "jquery": "^3.3.1",
      "load-google-maps-api": "^1.3.3",
      "lozad": "^1.16.0",
      "moment": "^2.18.1",
      "node-sass": "^4.9.0",
      "normalize.css": "^8.0.1",
      "object-fit-images": "^3.2.4",
      "readmore-js": "^2.2.1",
      "regenerator-runtime": "^0.13.7",
      "sass-loader": "^7.0.1",
      "smooth-scroll": "^16.0.3",
      "sweetalert2": "^10.3.0",
      "swiper": "^4.2.6",
      "tippy.js": "^6.2.6",
      "toastr": "^2.1.4",
      "unorm": "^1.6.0"
  	},
    "scripts": {
      "dev-server": "encore dev-server --host 0.0.0.0 --https --http2 --cert docker/nginx/localhost.pem --key docker/nginx/localhost-key.pem",
      "dev": "encore dev",
      "watch": "encore dev --watch",
      "build": "encore production --progress"
    },
    "resolutions": {
      "upath": "1.1.1"
    }
  }

Si nécessaire, mettre à jour les packets en faisant un make reset.

Example de configuration webpack
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: javascript

      const Encore = require('@symfony/webpack-encore');
      const webpack = require('webpack');
      const dotenv = require('dotenv').config();
      const path = require('path');
      const BrotliPlugin = require('brotli-webpack-plugin');
      process.env = process.env || {};
      process.env.NODE_ENV = Encore.isProduction() ? 'production' : 'development';

      Encore
          .setOutputPath('public/build/')
          .setPublicPath('/build')
          .cleanupOutputBeforeBuild()
          .addEntry('app', './assets/')
          .enableSassLoader()
          .enableSingleRuntimeChunk()
          .autoProvidejQuery()
          .enableSourceMaps(!Encore.isProduction())
          .enableVersioning(Encore.isProduction())
      ;

      let config = Encore.getWebpackConfig();

      if (!Encore.isProduction()) {
          config.devServer.watchOptions.poll = 250;
      }

      config.plugins.push(
          new webpack.DefinePlugin({
              'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
              'process.env.APP_GOOGLEMAP': JSON.stringify(process.env.APP_GOOGLEMAP),
              'process.env.RECAPTCHA_V3_PUBLIC': JSON.stringify(process.env.RECAPTCHA_V3_PUBLIC)
          })
      );

      config.plugins.push(
          new webpack.ProvidePlugin({
              Promise: ['es6-promise'],
              $: 'jquery',
              Swiper: path.resolve('./node_modules/swiper/dist/js/swiper.js'),
              Routing: path.resolve('./vendor/friendsofsymfony/jsrouting-bundle/Resources/public/js/router.js'),
              routes: path.resolve('./public/js/fos_js_routes.json'),
          })
      );

      if (Encore.isProduction()) {
          config.plugins.push(new BrotliPlugin({
              asset: '[path].br[query]',
              test: /\.(js|css|html|svg)$/,
              threshold: 10240,
              minRatio: 0.8
          }));
          // Remove the old version first
          config.optimization = {minimize: true};
          config.module.rules.push(
              {test: /\.pem$/, loader: 'raw-loader', options: {esModule: false}},
              {
                  test: /\.(js|jsx)$/,
                  use: {
                      loader: 'babel-loader',
                      options: {
                          "presets": [
                              [
                                  "@babel/preset-env",
                                  {
                                      "targets": {
                                          "ie": "11"
                                      },
                                      "useBuiltIns": "entry",
                                      "corejs": 3,
                                      "debug": false,

                                  }
                              ]
                          ]
                      }
                  },
                  exclude: [/\bcore-js\b/,/\bnode_modules\b/]
              },
          );
      }

      module.exports = config;
