{% extends '../../base.html.twig' %}

{% block body %}
  <div class="container-fluid">
    <div class="row flex-xl-nowrap">
      {% include '../../../documentation/navbar.html.twig' with {
        'route' : nodefony.route
      } %}
      <main class="col-12 col-md-9 col-xl-8 py-md-3 pl-md-5" style="top: 5rem;">
				<div class="page-header">
					<h1>WEBPACK </h1>
					<p>
						 Bundle Nodofony Generate a default webpack configuration  in Bundle config directory  <br>

						<h2 > You can see here :</h2>

						<p>
							<ul>
								<li><a href="#Location">Location</a></li>
								<li><a href="#configuration">Configuration</a></li>
							</ul>
						<p>

					<p>
				</div>

				<h2 name="Location">Location Webpack configurations in File System <span class="badge">Directory</span></h2>
				<div class="doc2">
				    </br>
				Location : <code>src/bundles/name-bundle/Resources/config/webpack</code>
				<pre><code class="hljs console" >
$ ls -l ./src/bundles/name-bundle/Resources/config
-rw-r--r--  1 cci  staff  1142 26 mar 17:08 config.js
-rw-r--r--  1 cci  staff   501 26 mar 17:08 routing.js
-rw-r--r--  1 cci  staff   896 26 mar 17:08 security.js
-rw-r--r--  1 cci  staff   122 26 mar 17:08 services.js
drwxr-xr-x  4 cci  staff   128 26 mar 17:08 webpack
-rw-r--r--  1 cci  staff  3047 26 mar 17:08 webpack.config.js

./src/bundles/name-bundle/Resources/config
├── config.js
├── routing.js
├── security.js
├── services.js
├── webpack
│   ├── webpack.dev.config.js
│   └── webpack.prod.config.js
└── webpack.config.js
				</code></pre>
				</div>
				</br>

				<h2 name="configuration">Webpack Nodefony configurations </h2>
				<div class="doc2">

				<div  class="card">
				    <div class="card-header"><strong>Nodefony WebPack Configurations</strong>  </div>
				    <div class="alert alert-warning" role="alert">
				        Nodefony  WebPack Configuration
				        </br>
				        <ul>
				            <li>
				                <strong>public</strong> : "src/bundles/name-bundle/Resources/public",
				            </li>
				            <li>
				                <strong>entry</strong> : "src/bundles/name-bundle/Resources/public/js/name.js",
				            </li>
				            <li>
				                <strong>output</strong>  : "src/bundles/name-bundle/Resources/public/assets",
				            </li>
				            <li>
				                <strong>publicPath</strong> : "/name-bundle",
				            </li>
				        </ul>
				    </div>
				    <div class="card-body" style='border-width:0.2em'>
				        <ul class="nav nav-pills"  role="tablist">
				            <li class="nav-item "><a class="nav-link active" href="#common" role="tab" aria-controls="common" data-toggle="pill" >webpack.config.js</a></li>
				            <li class="nav-item" ><a class="nav-link" href="#dev" role="tab" aria-controls="dev" data-toggle="pill">webpack.dev.config.js</a></li>
				            <li class="nav-item" ><a class="nav-link" href="#prod" role="tab" aria-controls="prod" data-toggle="pill">webpack.prod.config.js</a></li>
				            <li class="nav-item" ><a class="nav-link" href="#index" role="tab" aria-controls="index" data-toggle="pill">index.html.twig</a></li>
				            <li class="nav-item" ><a class="nav-link" href="#entryjs" role="tab" aria-controls="entryjs" data-toggle="pill">name.js</a></li>
				            <li class="nav-item" ><a class="nav-link" href="#entrycss" role="tab" aria-controls="entrycss" data-toggle="pill">name.css</a></li>
				        </ul>
				        <div class="tab-content ">
				            <div id="common" class="tab-pane active">
				                </br>
				                <p>Location : <code>src/bundles/name-bundle//Resources/config/webpack.config.js</code></p>
				                <pre><code class="hljs javascript" >const path = require("path");

const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const webpackMerge = require('webpack-merge');

// Default context <bundle base directory>
//const context = path.resolve(__dirname, "..", "Resources", "public");
const public = path.resolve(__dirname, "..", "public", "assets");
const bundleName = path.basename(path.resolve(__dirname, "..", ".."));
const publicPath = bundleName + "/assets/";

let config = null;
let dev = true;
if (kernel.environment === "dev") {
  config = require("./webpack/webpack.dev.config.js");
} else {
  config = require("./webpack/webpack.prod.config.js");
  dev = false;
}

module.exports = webpackMerge(config, {
  //context: context,
  target: "web",
  entry: {
    name  : [ "./Resources/public/js/name.js" ]
  },
  output: {
    path: public,
    publicPath: publicPath,
    filename: "./js/[name].js",
    library: "[name]",
    libraryExport: "default"
  },
  externals: {},
  resolve: {},
  module: {
    rules: [{
        // BABEL TRANSCODE
        test: new RegExp("\.es6$|\.js$"),
        exclude: new RegExp("node_modules"),
        use: [{
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env']
          }
        }]
      },
      /*
       *	JQUERY EXPOSE BROWSER CONTEXT
       *
       */
      {
        test: require.resolve("jquery"),
        loader: "expose-loader?$!expose-loader?jQuery"
      }, {
        test: /jquery\..*\.js/,
        loader: "imports-loader?$=jquery,jQuery=jquery,this=>window"
      }, {
        test: /\.(sa|sc|c)ss$/,
        use: [
          //'css-hot-loader',
          MiniCssExtractPlugin.loader,
          {
            loader: "css-loader",
            options: {
              sourceMap: true
            }
          }, {
            loader: 'resolve-url-loader',
            options: {}
          }, {
            loader: 'postcss-loader', // Run post css actions
            options: {
              plugins: () => [require('precss'), require('autoprefixer')]
            }
          }, {
            loader: "sass-loader",
            options: {
              sourceMap: true
            }
          }
        ]
      }, {
        test: /.(ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
        use: [{
          loader: 'file-loader',
          options: {
            name: '[name].[ext]',
            outputPath: 'fonts/', // where the fonts will go
            publicPath: `/${bundleName}/assets/fonts/` // override the default path
          }
        }]
      }, {
        // IMAGES
        test: /\.(gif|png|jpe?g|svg)$/i,
        use: [{
          loader: "file-loader",
          options: {
            name: "[name].[ext]",
            publicPath: `/${bundleName}/assets/images/`,
            outputPath: "/images/"
          }
        }]
      }
    ]
  },
  plugins: [
    new MiniCssExtractPlugin({
      filename: "./css/[name].css",
      allChunks: true
    })
  ],
  devServer: {
    inline: true,
    hot: false
  }
});
				                </code></pre>
				            </div>
										<div id="dev" class="tab-pane">
										</br>
										<p>Location : <code>src/bundles/name-bundle/Resources/config/webpack/webpack.dev.config.js</code></p>
										<pre><code class="hljs javascript">// WEBPACK DEV CONFIGURATION
const CleanWebpackPlugin = require('clean-webpack-plugin');
//const public = path.resolve(__dirname, "..", "..", "public");

module.exports = {
  mode: "development",
  devtool: "source-map",
  resolve: {},
  plugins: [
    new CleanWebpackPlugin({
      verbose: kernel.debug
    })
    //new webpack.NamedModulesPlugin(),
    //new webpack.HotModuleReplacementPlugin()
  ]
};
										</code></pre>
										</div>
										<div id="prod" class="tab-pane">
				                </br>
				                <p>Location : <code>src/bundles/name-bundle/Resources/config/webpack/webpack.prod.config.js</code></p>
				                <pre><code class="hljs javascript">const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');

module.exports = {
  mode: "production",
  watch: false,
  externals: {},
  resolve: {},
  optimization: {
    minimizer: [
      new TerserPlugin({
        terserOptions: {
          warnings: true,
          compress: true
        },
        cache: true,
        parallel: true
      })
    ]
  },
  plugins: [
    new OptimizeCssAssetsPlugin({
      cssProcessorOptions: {
        discardComments: {
          removeAll: true
        }
      },
      canPrint: true
    })
  ]
};
				                </code></pre>
				            </div>
				            <div id="index" class="tab-pane">
				                </br>
				                <p>Location : <code>src/bundles/name-bundle/Resources/views/index.html.twig</code></p>
				                <pre><code class="hljs twig">
&#123;% extends '/app/Resources/views/base.html.twig' %&#125;

&#123;% block title %&#125;Welcome &#123;&#123;kernel.name&#125;&#125;! &#123;% endblock %&#125;

&#123;% block stylesheets %&#125;

	&#123;&#123; parent() &#125;&#125;

	&lt!-- WEBPACK BUNDLE --&gt
	&ltlink rel='stylesheet' href='&#123;&#123;CDN("stylesheet")&#125;&#125;/name-bundle/assets/css/name.css' /&gt

&#123;% endblock %&#125;

&#123;% block body %&#125;
	&ltdiv class='container'&gt
		&ltdiv class='row'&gt
			&ltimg class='displayed' src='&#123;&#123;CDN("image")&#125;&#125;/framework-bundle/images/nodefony-logo-white.png'&gt
		&lt/div&gt
	&lt/div&gt
	&ltdiv class='container'&gt
		&ltdiv class='row displayed'&gt
			&#123;&#123;readme&#125;&#125;
		&lt/div&gt
	&lt/div&gt
&#123;% endblock %&#125;

&#123;% block javascripts %&#125;

	&#123;&#123; parent() &#125;&#125;

	&lt!-- WEBPACK BUNDLE --&gt
	&ltscript src='&#123;&#123;CDN("javascript")&#125;&#125;/name-bundle/assets/js/name.js'&gt&lt/script&gt

&#123;% endblock %&#125;
				            </code></pre>
				            </div>

				            <div id="entryjs" class="tab-pane">
				                </br>
				                <p>Location : <code>src/bundles/name-bundle/Resources/public/js/name.js</code></p>
				                <pre><code class="hljs javascript" >/**
 *
 *	ENTRY POINT WEBPACK BUNLDE
 *
 *
 *  Add your assets here with require to an integration in webpack  bundle
 *
 *  import 'jquery';
 *  import'../css/mycss.css';
 *
 */
import "../css/name.css";

/**
 *	Class
 *
 *	Namespace name client side
 *
 **/
 class name {
	constructor() {}
}

export default new name();
				                </code></pre>
				            </div>
				            <div id="entrycss" class="tab-pane">
				                </br>
				                <p>Location : <code>src/bundles/name-bundle/Resources/public/css/name.css</code></p>
				                <pre><code class="hljs css" >
IMG.displayed {
    display: block;
    margin-left: auto;
    margin-right: auto
}
				                </code></pre>
				            </div>

				        </div>
				    </div>
				</div>


			</main>
		</div>
	</div>
{% endblock %}
