Skip to content

Commit 2f38f5a

Browse files
Switch to webpack to support ESM (#5116)
* remove budo script * switch build tool to webpack to support ESM modules * there is no 'npm run build' anymore * const nit Co-authored-by: Diego Marcos Segura <[email protected]>
1 parent efb5c3a commit 2f38f5a

File tree

12 files changed

+135
-120
lines changed

12 files changed

+135
-120
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,9 @@ jobs:
4545
with:
4646
run: npm run test:chrome -- --single-run
4747

48-
# - name: Test node
49-
# run: npm run test:node
50-
5148
- name: Check Lint
5249
run: npm run lint
5350

54-
- name: Check Build
55-
run: npm run build
56-
5751
- name: Check Build Minified
5852
run: npm run dist
5953

package.json

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
"homepage": "https://aframe.io/",
66
"main": "dist/aframe-master.js",
77
"scripts": {
8-
"browserify": "browserify src/index.js -s 'AFRAME' -p browserify-derequire",
9-
"build": "shx mkdir -p build/ && npm run browserify -- --debug -t [ envify --INSPECTOR_VERSION dev ] -o build/aframe.js",
10-
"dev": "npm run build && cross-env INSPECTOR_VERSION=dev node ./scripts/budo -t envify",
11-
"dist": "node scripts/updateVersionLog.js && npm run dist:min",
12-
"dist:max": "npm run browserify -s -- --debug | exorcist dist/aframe-master.js.map > dist/aframe-master.js",
13-
"dist:min": "npm run dist:max && terser dist/aframe-master.js -c --source-map 'content=dist/aframe-master.js.map,url=aframe-master.min.js.map' -o dist/aframe-master.min.js",
8+
"dev": "cross-env INSPECTOR_VERSION=dev webpack serve",
9+
"dist": "node scripts/updateVersionLog.js && npm run dist:min && npm run dist:max",
10+
"dist:max": "webpack --config webpack.config.js",
11+
"dist:min": "webpack --config webpack.prod.config.js",
1412
"docs": "markserv --dir docs --port 9001",
1513
"preghpages": "node ./scripts/preghpages.js",
1614
"ghpages": "ghpages -p gh-pages/",
@@ -20,7 +18,7 @@
2018
"prepush": "node scripts/testOnlyCheck.js",
2119
"prerelease": "node scripts/release.js 1.2.0 1.3.0",
2220
"start": "npm run dev",
23-
"start:https": "cross-env SSL=true npm run dev",
21+
"start:https": "npm run dev -- --server-type https",
2422
"test": "karma start ./tests/karma.conf.js",
2523
"test:docs": "node scripts/docsLint.js",
2624
"test:firefox": "npm test -- --browsers Firefox",
@@ -37,6 +35,7 @@
3735
"vendor/**/*"
3836
],
3937
"dependencies": {
38+
"buffer": "^6.0.3",
4039
"custom-event-polyfill": "^1.0.6",
4140
"debug": "ngokevin/debug#noTimestamp",
4241
"deep-assign": "^2.0.0",
@@ -51,25 +50,20 @@
5150
"webvr-polyfill": "^0.10.12"
5251
},
5352
"devDependencies": {
54-
"browserify": "^17.0.0",
55-
"browserify-css": "^0.15.0",
56-
"browserify-derequire": "^1.1.1",
57-
"browserify-istanbul": "^3.0.1",
58-
"budo": "^11.8.4",
53+
"@babel/core": "^7.17.10",
54+
"babel-loader": "^8.2.5",
55+
"babel-plugin-istanbul": "^6.1.1",
5956
"chai": "^4.3.6",
6057
"chai-shallow-deep-equal": "^1.4.0",
6158
"chalk": "^1.1.3",
6259
"cross-env": "^7.0.3",
63-
"envify": "^4.1.0",
64-
"exorcist": "^2.0.0",
60+
"css-loader": "^6.7.1",
6561
"ghpages": "0.0.8",
6662
"git-rev": "^0.2.1",
6763
"glob": "^8.0.3",
6864
"husky": "^0.11.7",
69-
"istanbul": "^0.4.5",
7065
"jsdom": "^20.0.0",
7166
"karma": "^6.4.0",
72-
"karma-browserify": "^8.1.0",
7367
"karma-chai-shallow-deep-equal": "0.0.4",
7468
"karma-chrome-launcher": "^3.1.1",
7569
"karma-coverage": "^2.2.0",
@@ -78,6 +72,7 @@
7872
"karma-mocha": "^2.0.1",
7973
"karma-mocha-reporter": "^2.2.5",
8074
"karma-sinon-chai": "^2.0.2",
75+
"karma-webpack": "^5.0.0",
8176
"markserv": "github:sukima/markserv#feature/fix-broken-websoketio-link",
8277
"mocha": "^10.0.0",
8378
"replace-in-file": "^2.5.3",
@@ -87,17 +82,15 @@
8782
"sinon": "<12.0.0",
8883
"sinon-chai": "^3.7.0",
8984
"snazzy": "^5.0.0",
90-
"terser": "^5.15.0",
85+
"style-loader": "^3.3.1",
9186
"too-wordy": "ngokevin/too-wordy",
87+
"webpack": "^5.73.0",
88+
"webpack-cli": "^4.10.0",
89+
"webpack-dev-server": "^4.11.0",
90+
"webpack-merge": "^5.8.0",
9291
"write-good": "^1.0.8"
9392
},
9493
"link": true,
95-
"browserify": {
96-
"transform": [
97-
"browserify-css",
98-
"envify"
99-
]
100-
},
10194
"semistandard": {
10295
"ignore": [
10396
"build/**",
@@ -120,9 +113,6 @@
120113
"web-components",
121114
"webvr"
122115
],
123-
"browserify-css": {
124-
"minify": true
125-
},
126116
"engines": {
127117
"node": ">= 4.6.0",
128118
"npm": ">= 2.15.9"

scripts/budo.js

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/components/animation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var anime = require('super-animejs');
1+
var anime = require('super-animejs').default;
22
var components = require('../core/component').components;
33
var registerComponent = require('../core/component').registerComponent;
44
var THREE = require('../lib/three');

src/core/component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ var Component = module.exports.Component = function (el, attrValue, id) {
4848
this.el.components[this.attrName] = this;
4949
this.objectPool = objectPools[this.name];
5050

51-
const events = this.events;
51+
var events = this.events;
5252
this.events = {};
5353
eventsBind(this, events);
5454

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ module.exports = window.AFRAME = {
9999
AComponent: require('./core/component').Component,
100100
AEntity: AEntity,
101101
ANode: ANode,
102-
ANIME: require('super-animejs'),
102+
ANIME: require('super-animejs').default,
103103
AScene: AScene,
104104
components: components,
105105
coreComponents: Object.keys(components),

src/lib/three.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var THREE = global.THREE = require('super-three');
1+
var THREE = require('./three.module.js').default;
22

33
// Allow cross-origin images to be loaded.
44

@@ -18,17 +18,6 @@ if (THREE.Cache) {
1818
THREE.Cache.enabled = true;
1919
}
2020

21-
// TODO: Eventually include these only if they are needed by a component.
22-
require('../../vendor/DeviceOrientationControls'); // THREE.DeviceOrientationControls
23-
require('super-three/examples/js/loaders/DRACOLoader'); // THREE.DRACOLoader
24-
require('super-three/examples/js/loaders/GLTFLoader'); // THREE.GLTFLoader
25-
require('super-three/examples/js/loaders/KTX2Loader'); // THREE.KTX2Loader
26-
require('super-three/examples/js/loaders/OBJLoader'); // THREE.OBJLoader
27-
require('super-three/examples/js/loaders/MTLLoader'); // THREE.MTLLoader
28-
require('super-three/examples/js/utils/BufferGeometryUtils'); // THREE.BufferGeometryUtils
29-
require('super-three/examples/js/lights/LightProbeGenerator'); // THREE.LightProbeGenerator
30-
require('super-three/examples/js/utils/WorkerPool'); // WorkerPool used by KTX2Loader
31-
3221
THREE.DRACOLoader.prototype.crossOrigin = 'anonymous';
3322
THREE.GLTFLoader.prototype.crossOrigin = 'anonymous';
3423
THREE.KTX2Loader.prototype.crossOrigin = 'anonymous';

src/lib/three.module.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as SUPER_THREE from 'super-three';
2+
import { DRACOLoader } from 'super-three/examples/jsm/loaders/DRACOLoader';
3+
import { GLTFLoader } from 'super-three/examples/jsm/loaders/GLTFLoader';
4+
import { KTX2Loader } from 'super-three/examples/jsm/loaders/KTX2Loader';
5+
import { OBJLoader } from 'super-three/examples/jsm/loaders/OBJLoader';
6+
import { MTLLoader } from 'super-three/examples/jsm/loaders/MTLLoader';
7+
import * as BufferGeometryUtils from 'super-three/examples/jsm/utils/BufferGeometryUtils';
8+
import { LightProbeGenerator } from 'super-three/examples/jsm/lights/LightProbeGenerator';
9+
10+
var objectAssign = require('object-assign');
11+
var THREE = window.THREE = objectAssign({}, SUPER_THREE);
12+
13+
// TODO: Eventually include these only if they are needed by a component.
14+
require('../../vendor/DeviceOrientationControls'); // THREE.DeviceOrientationControls
15+
THREE.DRACOLoader = DRACOLoader;
16+
THREE.GLTFLoader = GLTFLoader;
17+
THREE.KTX2Loader = KTX2Loader;
18+
THREE.OBJLoader = OBJLoader;
19+
THREE.MTLLoader = MTLLoader;
20+
THREE.BufferGeometryUtils = BufferGeometryUtils;
21+
THREE.LightProbeGenerator = LightProbeGenerator;
22+
23+
export default THREE;

tests/__init.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* global AFRAME, sinon, setup, teardown */
1+
/* global sinon, setup, teardown */
22

33
/**
44
* __init.test.js is run before every test case.
@@ -19,13 +19,14 @@ navigator.getVRDisplays = function () {
1919
return Promise.resolve([mockVRDisplay]);
2020
};
2121

22-
require('index');
22+
const AFRAME = require('index');
2323
var AScene = require('core/scene/a-scene').AScene;
2424
// Make sure WebGL context is not created since Travix CT runs headless.
2525
// Stubs below failed once in a while due to asynchronous tesst setup / teardown.
2626
AScene.prototype.setupRenderer = function () {};
2727

2828
setup(function () {
29+
window.AFRAME = AFRAME;
2930
this.sinon = sinon.createSandbox();
3031
// Stubs to not create a WebGL context since Travis CI runs headless.
3132
this.sinon.stub(AScene.prototype, 'render');

tests/karma.conf.js

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Karma configuration.
2+
var path = require('path');
23
var glob = require('glob');
4+
var webpackConfiguration = require("../webpack.config.js");
35

46
// Define test files.
57
var FILES = [
@@ -14,15 +16,20 @@ if (process.env.TEST_FILE) {
1416
}
1517
});
1618
} else {
17-
FILES.push('tests/**/*.test.js');
19+
glob.sync('tests/**/*.test.js').forEach(function (filename) {
20+
FILES.push(filename);
21+
});
1822
}
1923

24+
// add 'src' to be able to resolve require('utils/tracked-controls') for
25+
// example in the tests
26+
webpackConfiguration.resolve.modules = ['src', 'node_modules'];
27+
// webpack will create a lot of files, use build directory instead of dist
28+
webpackConfiguration.output.path = path.resolve(__dirname, '../build');
29+
2030
var karmaConf = {
2131
basePath: '../',
22-
browserify: {
23-
debug: true,
24-
paths: ['src']
25-
},
32+
webpack: webpackConfiguration,
2633
browsers: ['Firefox', 'Chrome'],
2734
customLaunchers: {
2835
ChromeTravis: {
@@ -38,28 +45,19 @@ var karmaConf = {
3845
'TEST_ENV'
3946
],
4047
files: FILES,
41-
frameworks: ['mocha', 'sinon-chai', 'chai-shallow-deep-equal', 'browserify'],
48+
frameworks: ['mocha', 'sinon-chai', 'chai-shallow-deep-equal', 'webpack'],
4249
preprocessors: {
43-
'tests/**/*.js': ['browserify', 'env']
50+
'tests/**/*.js': ['webpack', 'env']
4451
},
4552
reporters: ['mocha']
4653
};
4754

4855
// Configuration for code coverage reporting.
4956
if (process.env.TEST_ENV === 'ci') {
50-
Object.assign(karmaConf.browserify, {
51-
transform: [
52-
[
53-
'browserify-istanbul', {
54-
instrumenterConfig: {
55-
embedSource: true
56-
},
57-
defaultIgnore: true,
58-
ignore: ['**/node_modules/**', '**/tests/**', '**/vendor/**', '**/*.css']
59-
}
60-
]
61-
]
62-
});
57+
// modify the babel-loader rule
58+
karmaConf.webpack.module.rules[0].use.options = {
59+
plugins: [['istanbul', { 'exclude': ['**/node_modules/**', '**/tests/**', '**/vendor/**', '**/*.css'] }]]
60+
};
6361
karmaConf.coverageReporter = {
6462
dir: 'tests/coverage',
6563
includeAllSources: true,
@@ -69,7 +67,6 @@ if (process.env.TEST_ENV === 'ci') {
6967
]
7068
};
7169
karmaConf.reporters.push('coverage');
72-
karmaConf.preprocessors['src/**/*.js'] = ['coverage'];
7370
karmaConf.browsers = ['Firefox', 'ChromeTravis'];
7471
}
7572

0 commit comments

Comments
 (0)