Skip to content

ES module type attribute

The ES module type attribute is a HTML attribute used to enable the execution of ECMAScript (ES6) modules directly within the browser environment.^[600-developer__frontend__vue__vue-module.md]

Implementation

To utilize this feature, the type="module" attribute must be added to the standard <script> tag in the HTML document^[600-developer__frontend__vue__vue-module.md].

Characteristics

Native Compilation

When this attribute is used, the browser assumes the script is a JavaScript module and compiles the ES6 code natively^[600-developer__frontend__vue__vue-module.md]. This allows developers to use modern JavaScript features and module syntax (such as import and export) directly in the browser without requiring a build step or transpilation tools like Babel^[600-developer__frontend__vue__vue-module.md].

Vue.js Integration

In the context of [[Vue.js]], this attribute enables the loading of single-file JavaScript components as modules^[600-developer__frontend__vue__vue-module.md]. For example, a main entry script (app.js) can import a component (e.g., SingleFileComponent.js) to instantiate a Vue application^[600-developer__frontend__vue__vue-module.md].

Sources

^[600-developer__frontend__vue__vue-module.md]