Skip to content

Commit

Permalink
Expose ES module, remove browserify mention and use import syntax in …
Browse files Browse the repository at this point in the history
…documentation (#5654)

* Expose ES module, remove browserify mention and use ES syntax in documentation

* simply use require('aframe') to require the cjs build

* add missing quote
  • Loading branch information
vincentfretin authored Feb 3, 2025
1 parent e133ea9 commit 1791c1b
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ npm install --save aframe
```

```js
require('aframe') // e.g., with Browserify or Webpack.
import AFRAME from 'aframe'; // e.g., with Webpack or Vite.
```

## Local Development
Expand Down
4 changes: 0 additions & 4 deletions docs/components/look-controls.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ controls how we want (e.g., limit the pitch on touch, reverse one axis). If we
were to include every possible configuration into the core component, we would
be left maintaining a wide array of flags.

The component lives within a Browserify/Webpack context so you'll need to
replace the `require` statements with A-Frame globals (e.g.,
`AFRAME.registerComponent`, `window.THREE`), and get rid of the `module.exports`.

## Caveats

If you want to create your own component for look controls, you will have to
Expand Down
5 changes: 2 additions & 3 deletions docs/core/globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ source_code: src/index.js
---

A-Frame exposes its public interface through the `window.AFRAME` browser
global. This same interface is also exposed if requiring with CommonJS
(`require('aframe')`).
global. This same interface is also exposed when you import aframe (`import AFRAME from 'aframe'`).

## `AFRAME` Properties

Expand Down Expand Up @@ -56,7 +55,7 @@ It is possible to run A-Frame in [Node.js](https://nodejs.org/en/about) to get a
```js
const cleanup = require('jsdom-global')();
global.customElements = { define: function () {} };
var aframe = require('aframe/src');
const aframe = require('aframe');
console.log(aframe.version);
cleanup();
```
Expand Down
6 changes: 3 additions & 3 deletions docs/introduction/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ We can also install A-Frame through npm:
$ npm install aframe
```

Then we can bundle A-Frame into our application. For example, with Browserify
or Webpack:
Then we can bundle A-Frame into our application. For example, with Webpack or
Vite:

```js
require('aframe');
import AFRAME from 'aframe';
```

[angle]: https://www.npmjs.com/package/angle
Expand Down
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
"version": "1.6.0",
"description": "A web framework for building virtual reality experiences.",
"homepage": "https://aframe.io/",
"main": "dist/aframe-master.js",
"main": "./dist/aframe-master.js",
"module": "./dist/aframe-master.module.min.js",
"exports": {
".": {
"import": "./dist/aframe-master.module.min.js",
"require": "./dist/aframe-master.js"
}
},
"scripts": {
"dev": "cross-env INSPECTOR_VERSION=dev webpack serve --port 8080",
"dist": "node scripts/updateVersionLog.js && npm run dist:min && npm run dist:max && npm run dist:module",
Expand Down
5 changes: 2 additions & 3 deletions tests/node/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-env mocha */
'use strict';

const path = require('path');
const assert = require('assert');

suite('node acceptance tests', function () {
Expand All @@ -16,7 +15,7 @@ suite('node acceptance tests', function () {
});

test('can run in node', function () {
const aframe = require(path.join(process.cwd(), 'src'));
const aframe = require('aframe');

assert.ok(aframe.version);
});
Expand All @@ -25,7 +24,7 @@ suite('node acceptance tests', function () {
let aframe;

setup(function () {
aframe = require(path.join(process.cwd(), 'src'));
aframe = require('aframe');
});

test('isNodeEnvironment is true for node', function () {
Expand Down

0 comments on commit 1791c1b

Please sign in to comment.