-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Switch to webpack to support ESM #5116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,12 +5,10 @@ | |
| "homepage": "https://aframe.io/", | ||
| "main": "dist/aframe-master.js", | ||
| "scripts": { | ||
| "browserify": "browserify src/index.js -s 'AFRAME' -p browserify-derequire", | ||
| "build": "shx mkdir -p build/ && npm run browserify -- --debug -t [ envify --INSPECTOR_VERSION dev ] -o build/aframe.js", | ||
| "dev": "npm run build && cross-env INSPECTOR_VERSION=dev node ./scripts/budo -t envify", | ||
| "dist": "node scripts/updateVersionLog.js && npm run dist:min", | ||
| "dist:max": "npm run browserify -s -- --debug | exorcist dist/aframe-master.js.map > dist/aframe-master.js", | ||
| "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", | ||
| "dev": "cross-env INSPECTOR_VERSION=dev webpack serve", | ||
| "dist": "node scripts/updateVersionLog.js && npm run dist:min && npm run dist:max", | ||
| "dist:max": "webpack --config webpack.config.js", | ||
| "dist:min": "webpack --config webpack.prod.config.js", | ||
| "docs": "markserv --dir docs --port 9001", | ||
| "preghpages": "node ./scripts/preghpages.js", | ||
| "ghpages": "ghpages -p gh-pages/", | ||
|
|
@@ -20,7 +18,7 @@ | |
| "prepush": "node scripts/testOnlyCheck.js", | ||
| "prerelease": "node scripts/release.js 1.2.0 1.3.0", | ||
| "start": "npm run dev", | ||
| "start:https": "cross-env SSL=true npm run dev", | ||
| "start:https": "npm run dev -- --server-type https", | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I chose to use the parameter here but we could have used an environment variable and set it in the config https://webpack.js.org/configuration/dev-server/#devserverserver |
||
| "test": "karma start ./tests/karma.conf.js", | ||
| "test:docs": "node scripts/docsLint.js", | ||
| "test:firefox": "npm test -- --browsers Firefox", | ||
|
|
@@ -37,6 +35,7 @@ | |
| "vendor/**/*" | ||
| ], | ||
| "dependencies": { | ||
| "buffer": "^6.0.3", | ||
| "custom-event-polyfill": "^1.0.6", | ||
| "debug": "ngokevin/debug#noTimestamp", | ||
| "deep-assign": "^2.0.0", | ||
|
|
@@ -51,25 +50,20 @@ | |
| "webvr-polyfill": "^0.10.12" | ||
| }, | ||
| "devDependencies": { | ||
| "browserify": "^17.0.0", | ||
| "browserify-css": "^0.15.0", | ||
| "browserify-derequire": "^1.1.1", | ||
| "browserify-istanbul": "^3.0.1", | ||
| "budo": "^11.8.4", | ||
| "@babel/core": "^7.17.10", | ||
| "babel-loader": "^8.2.5", | ||
| "babel-plugin-istanbul": "^6.1.1", | ||
| "chai": "^4.3.6", | ||
| "chai-shallow-deep-equal": "^1.4.0", | ||
| "chalk": "^1.1.3", | ||
| "cross-env": "^7.0.3", | ||
| "envify": "^4.1.0", | ||
| "exorcist": "^2.0.0", | ||
| "css-loader": "^6.7.1", | ||
| "ghpages": "0.0.8", | ||
| "git-rev": "^0.2.1", | ||
| "glob": "^8.0.3", | ||
| "husky": "^0.11.7", | ||
| "istanbul": "^0.4.5", | ||
| "jsdom": "^20.0.0", | ||
| "karma": "^6.4.0", | ||
| "karma-browserify": "^8.1.0", | ||
| "karma-chai-shallow-deep-equal": "0.0.4", | ||
| "karma-chrome-launcher": "^3.1.1", | ||
| "karma-coverage": "^2.2.0", | ||
|
|
@@ -78,6 +72,7 @@ | |
| "karma-mocha": "^2.0.1", | ||
| "karma-mocha-reporter": "^2.2.5", | ||
| "karma-sinon-chai": "^2.0.2", | ||
| "karma-webpack": "^5.0.0", | ||
| "markserv": "github:sukima/markserv#feature/fix-broken-websoketio-link", | ||
| "mocha": "^10.0.0", | ||
| "replace-in-file": "^2.5.3", | ||
|
|
@@ -87,17 +82,15 @@ | |
| "sinon": "<12.0.0", | ||
| "sinon-chai": "^3.7.0", | ||
| "snazzy": "^5.0.0", | ||
| "terser": "^5.15.0", | ||
| "style-loader": "^3.3.1", | ||
| "too-wordy": "ngokevin/too-wordy", | ||
| "webpack": "^5.73.0", | ||
| "webpack-cli": "^4.10.0", | ||
| "webpack-dev-server": "^4.11.0", | ||
| "webpack-merge": "^5.8.0", | ||
| "write-good": "^1.0.8" | ||
| }, | ||
| "link": true, | ||
| "browserify": { | ||
| "transform": [ | ||
| "browserify-css", | ||
| "envify" | ||
| ] | ||
| }, | ||
| "semistandard": { | ||
| "ignore": [ | ||
| "build/**", | ||
|
|
@@ -120,9 +113,6 @@ | |
| "web-components", | ||
| "webvr" | ||
| ], | ||
| "browserify-css": { | ||
| "minify": true | ||
| }, | ||
| "engines": { | ||
| "node": ">= 4.6.0", | ||
| "npm": ">= 2.15.9" | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,7 +99,7 @@ module.exports = window.AFRAME = { | |
| AComponent: require('./core/component').Component, | ||
| AEntity: AEntity, | ||
| ANode: ANode, | ||
| ANIME: require('super-animejs'), | ||
| ANIME: require('super-animejs').default, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For you to understand webpack by default is importing the package from the field 'browser', 'module', 'main' in this order of priority by default if those fields are defined in |
||
| AScene: AScene, | ||
| components: components, | ||
| coreComponents: Object.keys(components), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import * as SUPER_THREE from 'super-three'; | ||
| import { DRACOLoader } from 'super-three/examples/jsm/loaders/DRACOLoader'; | ||
| import { GLTFLoader } from 'super-three/examples/jsm/loaders/GLTFLoader'; | ||
| import { KTX2Loader } from 'super-three/examples/jsm/loaders/KTX2Loader'; | ||
| import { OBJLoader } from 'super-three/examples/jsm/loaders/OBJLoader'; | ||
| import { MTLLoader } from 'super-three/examples/jsm/loaders/MTLLoader'; | ||
| import * as BufferGeometryUtils from 'super-three/examples/jsm/utils/BufferGeometryUtils'; | ||
| import { LightProbeGenerator } from 'super-three/examples/jsm/lights/LightProbeGenerator'; | ||
|
|
||
| var objectAssign = require('object-assign'); | ||
| var THREE = window.THREE = objectAssign({}, SUPER_THREE); | ||
|
|
||
| // TODO: Eventually include these only if they are needed by a component. | ||
| require('../../vendor/DeviceOrientationControls'); // THREE.DeviceOrientationControls | ||
| THREE.DRACOLoader = DRACOLoader; | ||
| THREE.GLTFLoader = GLTFLoader; | ||
| THREE.KTX2Loader = KTX2Loader; | ||
| THREE.OBJLoader = OBJLoader; | ||
| THREE.MTLLoader = MTLLoader; | ||
| THREE.BufferGeometryUtils = BufferGeometryUtils; | ||
| THREE.LightProbeGenerator = LightProbeGenerator; | ||
|
|
||
| export default THREE; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| /* global AFRAME, sinon, setup, teardown */ | ||
| /* global sinon, setup, teardown */ | ||
|
|
||
| /** | ||
| * __init.test.js is run before every test case. | ||
|
|
@@ -19,13 +19,14 @@ navigator.getVRDisplays = function () { | |
| return Promise.resolve([mockVRDisplay]); | ||
| }; | ||
|
|
||
| require('index'); | ||
| const AFRAME = require('index'); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the |
||
| var AScene = require('core/scene/a-scene').AScene; | ||
| // Make sure WebGL context is not created since Travix CT runs headless. | ||
| // Stubs below failed once in a while due to asynchronous tesst setup / teardown. | ||
| AScene.prototype.setupRenderer = function () {}; | ||
|
|
||
| setup(function () { | ||
| window.AFRAME = AFRAME; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one gave me a hard time. I'm not sure how this worked with browserify with karma before, I think karma-browserify injected the |
||
| this.sinon = sinon.createSandbox(); | ||
| // Stubs to not create a WebGL context since Travis CI runs headless. | ||
| this.sinon.stub(AScene.prototype, 'render'); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| // Karma configuration. | ||
| var path = require('path'); | ||
| var glob = require('glob'); | ||
| var webpackConfiguration = require("../webpack.config.js"); | ||
|
|
||
| // Define test files. | ||
| var FILES = [ | ||
|
|
@@ -14,15 +16,20 @@ if (process.env.TEST_FILE) { | |
| } | ||
| }); | ||
| } else { | ||
| FILES.push('tests/**/*.test.js'); | ||
| glob.sync('tests/**/*.test.js').forEach(function (filename) { | ||
| FILES.push(filename); | ||
| }); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't quite understand why the previous code didn't work anymore, it gave me 16 tests instead of 355 tests. Doing the glob myself like it's done when you use |
||
| } | ||
|
|
||
| // add 'src' to be able to resolve require('utils/tracked-controls') for | ||
| // example in the tests | ||
| webpackConfiguration.resolve.modules = ['src', 'node_modules']; | ||
| // webpack will create a lot of files, use build directory instead of dist | ||
| webpackConfiguration.output.path = path.resolve(__dirname, '../build'); | ||
|
|
||
| var karmaConf = { | ||
| basePath: '../', | ||
| browserify: { | ||
| debug: true, | ||
| paths: ['src'] | ||
| }, | ||
| webpack: webpackConfiguration, | ||
| browsers: ['Firefox', 'Chrome'], | ||
| customLaunchers: { | ||
| ChromeTravis: { | ||
|
|
@@ -38,28 +45,19 @@ var karmaConf = { | |
| 'TEST_ENV' | ||
| ], | ||
| files: FILES, | ||
| frameworks: ['mocha', 'sinon-chai', 'chai-shallow-deep-equal', 'browserify'], | ||
| frameworks: ['mocha', 'sinon-chai', 'chai-shallow-deep-equal', 'webpack'], | ||
| preprocessors: { | ||
| 'tests/**/*.js': ['browserify', 'env'] | ||
| 'tests/**/*.js': ['webpack', 'env'] | ||
| }, | ||
| reporters: ['mocha'] | ||
| }; | ||
|
|
||
| // Configuration for code coverage reporting. | ||
| if (process.env.TEST_ENV === 'ci') { | ||
| Object.assign(karmaConf.browserify, { | ||
| transform: [ | ||
| [ | ||
| 'browserify-istanbul', { | ||
| instrumenterConfig: { | ||
| embedSource: true | ||
| }, | ||
| defaultIgnore: true, | ||
| ignore: ['**/node_modules/**', '**/tests/**', '**/vendor/**', '**/*.css'] | ||
| } | ||
| ] | ||
| ] | ||
| }); | ||
| // modify the babel-loader rule | ||
| karmaConf.webpack.module.rules[0].use.options = { | ||
| plugins: [['istanbul', { 'exclude': ['**/node_modules/**', '**/tests/**', '**/vendor/**', '**/*.css'] }]] | ||
| }; | ||
| karmaConf.coverageReporter = { | ||
| dir: 'tests/coverage', | ||
| includeAllSources: true, | ||
|
|
@@ -69,7 +67,6 @@ if (process.env.TEST_ENV === 'ci') { | |
| ] | ||
| }; | ||
| karmaConf.reporters.push('coverage'); | ||
| karmaConf.preprocessors['src/**/*.js'] = ['coverage']; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing this line is on purpose, this is not an error, https://github.com/istanbuljs/babel-plugin-istanbul#karma is saying to not add the coverage preprocessor. |
||
| karmaConf.browsers = ['Firefox', 'ChromeTravis']; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The webpack command comes from the webpack-cli package. The
serveargument is available when you have the webpack-dev-server package.webpack serveuse thedevServerconfiguration inwebpack.config.js