Home > Web Front-end > JS Tutorial > body text

How to Import jQuery with ES6 Syntax in Babel and Semantic-UI?

Linda Hamilton
Release: 2024-10-26 07:21:30
Original
402 people have browsed it

How to Import jQuery with ES6 Syntax in Babel and Semantic-UI?

Importing jQuery using ES6 Syntax

When using ES6 syntax with Babel transpiler and semantic-ui, importing jQuery can be done as follows:

index.js

<code class="js">import { $, jQuery } from 'jquery';
// export for others scripts to use
window.$ = $;
window.jQuery = jQuery;</code>
Copy after login

Explanation:

  • Importing from node_modules: jQuery should be imported from the node_modules/ directory, not from the dist/ directory. The build:app script in package.json is responsible for copying jQuery to the dist/ folder.
  • Specific import: Instead of using the glob wildcard *, you can import specific named exports, such as $ and jQuery.
  • Exposing jQuery: To make jQuery available to other scripts, it's necessary to expose it to the global scope using window.$ = $.
  • Duplicate import removal: Browserify eliminates duplicate imports, so there's no overhead in importing both $ and jQuery.

The above is the detailed content of How to Import jQuery with ES6 Syntax in Babel and Semantic-UI?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!