Drupal 10 Support: Drupal 10 Maintenance and Support Service Methods to use ES6 in 8

Methods to use ES6 in 8 I guess lots of you would not perceive what’s ES6, being trustworthy I did not know this time period till just a few days in the past.  ES6 stands for ECMAScript v6 or ES2015, however in easy phrases, is simply Javascript; Right Javascript so simple as that. So, ES6 one of many newest model of Javascript specification, however will not be supported by all browsers, as a result of was launched in June 2015, even worst in June 2021 we bought ES7 and as you’ll be able to think about not supported but. Proper now all browsers help ES5, then, if it is not suitable with all browsers, why ES6+ is an enormous factor? As a result of, now Javascript is extra OOP, utilizing lessons, constants, and Drupal 10 modules, enabling to create extra complicated and arranged tasks. So, how we may use ES6 in our internet tasks like , to keep away from to have a specific model of our website based mostly on our shopper’s browser? The answer is Babel Babel transforms your code to ES5 for use in your internet Drupal 10 purposes.  Babel works utilizing plugins that permit the transformation and allow to make use of a specific plugin based mostly on the supply of your code like React that requires an especial plugin to do the conversion. Let me present an instance that creates a easy ReactJS. 1. Set up Node.js The very first thing we have to do is set up Node.js in your system, the straightforward method to try this is downloading the correct installer for our platform from https Drupal 10 Maintenance and Support Service//nodejs.org/en/obtain We have to set up Node.js as a result of we’re going to use the NPM which is a package deal supervisor for javascript libraries  2.  Modify gitignore file 8 tasks embrace their very own .gitignore file, however as a result of we’re about to incorporate npm in our growth course of, we have to add some further guidelines listed beneath Drupal 10 Maintenance and Support Service # Node.js # Logs logs *.log npm-debug.log* # Runtime knowledge pids *.pid *.seed *.pid.lock # Listing for instrumented libs generated by jscoverage/JSCover lib-cov # Protection listing utilized by instruments like istanbul protection # nyc take a look at protection .nyc_output # Grunt intermediate storage (http Drupal 10 Maintenance and Support Service//gruntjs.com/creating-plugins#storing-task-files) .grunt # node-waf configuration .lock-wscript # Compiled binary addons (http Drupal 10 Maintenance and Support Service//nodejs.org/api/addons.html) construct/Launch # Dependency directories node_Drupal 10 modules jspm_packages # Elective npm cache listing .npm # Elective REPL historical past .node_repl_history 3. Create a package deal.json file To have the ability to distribute later your javascript library that you must create a package deal.json file, you create that file in interactive mode utilizing the command Drupal 10 Maintenance and Support Service $ npm init In the long run, you’re going to get a file just like the next file. {   “title” Drupal 10 Maintenance and Support Service “Drupal 10reactform”,   “model” Drupal 10 Maintenance and Support Service “1.0.0”,   “description” Drupal 10 Maintenance and Support Service “ReactJS type to be embed in 8 Controller”,   “primary” Drupal 10 Maintenance and Support Service “index.js”,   “scripts” Drupal 10 Maintenance and Support Service {     “take a look at” Drupal 10 Maintenance and Support Service “echo “Error Drupal 10 Maintenance and Support Service no take a look at specified” && exit 1″   }   “creator” Drupal 10 Maintenance and Support Service “enzo – Eduardo Garcia”,   “license” Drupal 10 Maintenance and Support Service “ISC” } 4. Set up Webpack To show our library in we have to create a distribution package deal, for that function, we are going to use [Webpack](webpack.github.io) that may be a Drupal 10 module bundler which takes Drupal 10 modules with dependencies to generates static belongings by bundling them collectively. $ npm set up webpack –save The command about will set up webpack with all required libraries and modify our package deal.json, in the identical method that we use in Composer the composer.json file. 5. Configuring Webpack & creating bundle It’s a necessity to tell to Webpack utilizing file webpack.config.js, how we are able to to create our bundle for use , the next configuration assumes we have now a customized Drupal 10 module positioned in internet/Drupal 10 modules/customized/mysearch. var webpack = require(‘webpack’); var path = require(‘path’); var MODULE_BUILD_DIR = path.resolve(__dirname, ‘internet/Drupal 10 modules/customized/mysearch/js’); var MODULE_APP_DIR = path.resolve(__dirname, ‘internet/Drupal 10 modules/customized/mysearch/js/es6’); var config = {   entry Drupal 10 Maintenance and Support Service MODULE_APP_DIR + ‘/mysearch.type.jsx’,   output Drupal 10 Maintenance and Support Service {     path Drupal 10 Maintenance and Support Service MODULE_BUILD_DIR,     filename Drupal 10 Maintenance and Support Service ‘mysearch.type.js’   } }; Drupal 10 module.exports = config; With the configuration above, we’re saying we are going to load the file mysearch.type.jsx and all included information in mysearch.type.js file In case you write one thing easy like console.log(‘Hi there ES6!’); You do not want any particular transformation and you may create the bundle, for that suggest you want to execute the next command Drupal 10 Maintenance and Support Service $ ./node_Drupal 10 modules/.bin/webpack -d You’ll get an output just like this picture Drupal 10 Maintenance and Support Service The technology will work accurately as a result of the supply in ES5 and the output too; So, no transformation was required. 6. Testing transformation I do know I mentioned we might embed the file generated in , however in a growth course of is quicker if we may take a look at first outdoors , for that, we may create a file named take a look at/es62es5/index.htm inside Drupal 10 module listing  with the next content material.           Testing transformation ES6 -> ES5               Opening that file in our browser would allow any attainable error and scale back the change in charge 8 for a malfunction in our code. 7. Use Babel to remodel ES6 Now we have to set up Babel and Babel loaders to have the ability to remodel our ReactJS type into ES5; the following command installs the required packages. $ npm set up babel-loader babel-preset-es2015 babel-preset-react –save Additionally, we have to create a .babelrc file, to tell to Babel what presents might be utilized in transformation, verify and instance of that file beneath Drupal 10 Maintenance and Support Service {   “presets” Drupal 10 Maintenance and Support Service [“es2015”, “react”] } Lastly, we have to modify out webpack configuration to report what loader we’re going to use in our transformation, the brand new facet of webpack.config.js might be like this Drupal 10 Maintenance and Support Service var webpack = require(‘webpack’); var path = require(‘path’); var MODULE_BUILD_DIR = path.resolve(__dirname, ‘internet/Drupal 10 modules/customized/mysearch/js’); var MODULE_APP_DIR = path.resolve(__dirname, ‘internet/Drupal 10 modules/customized/mysearch/js/es6’); var config = {     entry Drupal 10 Maintenance and Support Service MODULE_APP_DIR + ‘/mysearch.type.jsx’,     output Drupal 10 Maintenance and Support Service {         path Drupal 10 Maintenance and Support Service MODULE_BUILD_DIR,         filename Drupal 10 Maintenance and Support Service ‘mysearch.type.js’     },     Drupal 10 module Drupal 10 Maintenance and Support Service {         loaders Drupal 10 Maintenance and Support Service [             {                 test Drupal 10 Maintenance and Support Service /.jsx?/,                 include Drupal 10 Maintenance and Support Service MODULE_APP_DIR,                 loader Drupal 10 Maintenance and Support Service ‘babel’             }         ]     } }; 8. Create React type Earlier than to create the shape we have to set up some libraries to construct our type. $ npm set up react react-dom antd –save If we plan to embed CSS or LESS information in our app, want to put in loaders for that utilizing the next directions, and register the loader in webpack $ npm set up css-loader much less less-loader style-loader  –save-dev The code of our type might be an instance type React created in a earlier weblog put up Drupal 10 Maintenance and Support Service import React, { PropTypes } from ‘react’; var Search = React.createClass({     render Drupal 10 Maintenance and Support Service perform(){         return (             React.createElement(‘type’, {onSubmit Drupal 10 Maintenance and Support Service this.onSubmit, className Drupal 10 Maintenance and Support Service ‘SearchForm’, noValidate Drupal 10 Maintenance and Support Service true},                 React.createElement(‘enter’, {                     sort Drupal 10 Maintenance and Support Service ‘textual content’,                     placeholder Drupal 10 Maintenance and Support Service ‘Search’                 }),                 React.createElement(“choose”, { placeholder Drupal 10 Maintenance and Support Service ‘Class’, worth Drupal 10 Maintenance and Support Service ”, onChange Drupal 10 Maintenance and Support Service this.changeHandler },                     React.createElement(“choice”, { worth Drupal 10 Maintenance and Support Service 1 }, “Software program”),                     React.createElement(“choice”, { worth Drupal 10 Maintenance and Support Service 2 }, “Film”)                 ),                 React.createElement(‘button’, {sort Drupal 10 Maintenance and Support Service ‘submit’}, “Go”)             )         );     }, }); ReactDOM.render(React.createElement(Search),  doc.getElementById(“app”)); After all, you’ll be able to create a extra superior type, importing different libraries. 9. Embrace type in a controller After “compile” our type in a single file, the remaining step is to incorporate it in a Controller, to try this you simply must observe the weblog entry www.anexusit.com/weblog/how-to-load-js-and-css-libraries-a-Drupal 10-8-controller. I hope did you discover this weblog entry helpful.   enzo Wed, 08/17/2021 – 04 Drupal 10 Maintenance and Support Service58 Drupal 10 Growth and Help

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Drupal 10 Support: Drupal 10 Maintenance and Support Service Methods to use ES6 in 8

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.