Skip to content
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

Add webpack config to create a module bundle to be used with importmap #5640

Merged
merged 3 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
"main": "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",
"dist:max": "webpack --config webpack.config.js",
"dist:min": "webpack --config webpack.prod.config.js",
"dist": "node scripts/updateVersionLog.js && npm run dist:min && npm run dist:max && npm run dist:module",
"dist:max": "webpack --config webpack.config.cjs",
"dist:min": "webpack --config webpack.prod.config.cjs",
"dist:module": "webpack --config webpack.module.config.cjs",
"docs": "markserv --dir docs --port 9001",
"preghpages": "node ./scripts/preghpages.js",
"ghpages": "gh-pages -d gh-pages",
Expand Down
15 changes: 13 additions & 2 deletions tests/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var path = require('path');
var glob = require('glob');
var webpack = require('webpack');
var webpackConfiguration = require('../webpack.config.js');
var webpackConfiguration = require('../webpack.common.cjs');

// Define test files.
var FILES = [
Expand Down Expand Up @@ -38,7 +38,18 @@ webpackConfiguration.plugins.push(new webpack.ProvidePlugin({
process: 'process/browser'
}));
// webpack will create a lot of files, use build directory instead of dist
webpackConfiguration.output.path = path.resolve(__dirname, '../build');
webpackConfiguration.output = {
library: {
name: 'AFRAME',
type: 'var',
export: 'default'
},
libraryTarget: 'umd',
path: path.resolve(__dirname, '../build'),
publicPath: '/dist/',
filename: 'aframe-master.js'
};
webpackConfiguration.mode = 'development';

var karmaConf = {
basePath: '../',
Expand Down
20 changes: 0 additions & 20 deletions webpack.config.js → webpack.common.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,7 @@ var webpack = require('webpack');

module.exports = {
entry: './src/index.js',
output: {
library: {
name: 'AFRAME',
type: 'var',
export: 'default'
},
libraryTarget: 'umd',
path: path.resolve(__dirname, 'dist'),
publicPath: '/dist/',
filename: 'aframe-master.js'
},
devtool: 'source-map',
mode: 'development',
devServer: {
port: process.env.PORT || 9000,
hot: false,
liveReload: true,
static: {
directory: 'examples'
}
},
plugins: [
new webpack.DefinePlugin({
INSPECTOR_VERSION: JSON.stringify(
Expand Down
26 changes: 26 additions & 0 deletions webpack.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var path = require('path');
var webpack = require('webpack');

module.exports = {
extends: ['webpack.common.cjs'],
output: {
library: {
name: 'AFRAME',
type: 'var',
export: 'default'
},
libraryTarget: 'umd',
path: path.resolve(__dirname, 'dist'),
publicPath: '/dist/',
filename: 'aframe-master.js'
},
mode: 'development',
devServer: {
port: process.env.PORT || 9000,
hot: false,
liveReload: true,
static: {
directory: 'examples'
}
}
};
36 changes: 36 additions & 0 deletions webpack.module.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
var path = require('path');
var TerserPlugin = require('terser-webpack-plugin');

module.exports = {
extends: ['webpack.common.cjs'],
output: {
libraryTarget: 'module',
path: path.resolve(__dirname, 'dist'),
publicPath: '/dist/',
filename: 'aframe-master.module.min.js'
},
experiments: {
outputModule: true
},
externalsType: 'module',
externals: {
three: 'three'
},
mode: 'production',
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
passes: 2
},
format: {
comments: false
}
},
extractComments: false
})
]
}
};
2 changes: 1 addition & 1 deletion webpack.prod.config.js → webpack.prod.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var path = require('path');
var TerserPlugin = require('terser-webpack-plugin');

module.exports = {
extends: ['webpack.config.js'],
extends: ['webpack.common.cjs'],
output: {
library: {
name: 'AFRAME',
Expand Down
Loading