Skip to content

Commit 3ce9c22

Browse files
Add webpack config to create a module bundle to be used with importmap (#5640)
* Add webpack config to create a module bundle to be used with importmap * Fix webpack config for tests, importing a config doesn't handle the extends * Rename webpack files to cjs
1 parent 99292e5 commit 3ce9c22

6 files changed

+80
-26
lines changed

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
"main": "dist/aframe-master.js",
77
"scripts": {
88
"dev": "cross-env INSPECTOR_VERSION=dev webpack serve --port 8080",
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",
9+
"dist": "node scripts/updateVersionLog.js && npm run dist:min && npm run dist:max && npm run dist:module",
10+
"dist:max": "webpack --config webpack.config.cjs",
11+
"dist:min": "webpack --config webpack.prod.config.cjs",
12+
"dist:module": "webpack --config webpack.module.config.cjs",
1213
"docs": "markserv --dir docs --port 9001",
1314
"preghpages": "node ./scripts/preghpages.js",
1415
"ghpages": "gh-pages -d gh-pages",

tests/karma.conf.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
var path = require('path');
33
var glob = require('glob');
44
var webpack = require('webpack');
5-
var webpackConfiguration = require('../webpack.config.js');
5+
var webpackConfiguration = require('../webpack.common.cjs');
66

77
// Define test files.
88
var FILES = [
@@ -38,7 +38,18 @@ webpackConfiguration.plugins.push(new webpack.ProvidePlugin({
3838
process: 'process/browser'
3939
}));
4040
// webpack will create a lot of files, use build directory instead of dist
41-
webpackConfiguration.output.path = path.resolve(__dirname, '../build');
41+
webpackConfiguration.output = {
42+
library: {
43+
name: 'AFRAME',
44+
type: 'var',
45+
export: 'default'
46+
},
47+
libraryTarget: 'umd',
48+
path: path.resolve(__dirname, '../build'),
49+
publicPath: '/dist/',
50+
filename: 'aframe-master.js'
51+
};
52+
webpackConfiguration.mode = 'development';
4253

4354
var karmaConf = {
4455
basePath: '../',

webpack.config.js renamed to webpack.common.cjs

-20
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,7 @@ var webpack = require('webpack');
33

44
module.exports = {
55
entry: './src/index.js',
6-
output: {
7-
library: {
8-
name: 'AFRAME',
9-
type: 'var',
10-
export: 'default'
11-
},
12-
libraryTarget: 'umd',
13-
path: path.resolve(__dirname, 'dist'),
14-
publicPath: '/dist/',
15-
filename: 'aframe-master.js'
16-
},
176
devtool: 'source-map',
18-
mode: 'development',
19-
devServer: {
20-
port: process.env.PORT || 9000,
21-
hot: false,
22-
liveReload: true,
23-
static: {
24-
directory: 'examples'
25-
}
26-
},
277
plugins: [
288
new webpack.DefinePlugin({
299
INSPECTOR_VERSION: JSON.stringify(

webpack.config.cjs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
var path = require('path');
2+
var webpack = require('webpack');
3+
4+
module.exports = {
5+
extends: ['webpack.common.cjs'],
6+
output: {
7+
library: {
8+
name: 'AFRAME',
9+
type: 'var',
10+
export: 'default'
11+
},
12+
libraryTarget: 'umd',
13+
path: path.resolve(__dirname, 'dist'),
14+
publicPath: '/dist/',
15+
filename: 'aframe-master.js'
16+
},
17+
mode: 'development',
18+
devServer: {
19+
port: process.env.PORT || 9000,
20+
hot: false,
21+
liveReload: true,
22+
static: {
23+
directory: 'examples'
24+
}
25+
}
26+
};

webpack.module.config.cjs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
var path = require('path');
2+
var TerserPlugin = require('terser-webpack-plugin');
3+
4+
module.exports = {
5+
extends: ['webpack.common.cjs'],
6+
output: {
7+
libraryTarget: 'module',
8+
path: path.resolve(__dirname, 'dist'),
9+
publicPath: '/dist/',
10+
filename: 'aframe-master.module.min.js'
11+
},
12+
experiments: {
13+
outputModule: true
14+
},
15+
externalsType: 'module',
16+
externals: {
17+
three: 'three'
18+
},
19+
mode: 'production',
20+
optimization: {
21+
minimize: true,
22+
minimizer: [
23+
new TerserPlugin({
24+
terserOptions: {
25+
compress: {
26+
passes: 2
27+
},
28+
format: {
29+
comments: false
30+
}
31+
},
32+
extractComments: false
33+
})
34+
]
35+
}
36+
};

webpack.prod.config.js renamed to webpack.prod.config.cjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var path = require('path');
22
var TerserPlugin = require('terser-webpack-plugin');
33

44
module.exports = {
5-
extends: ['webpack.config.js'],
5+
extends: ['webpack.common.cjs'],
66
output: {
77
library: {
88
name: 'AFRAME',

0 commit comments

Comments
 (0)