diff --git a/package.json b/package.json index 0200dfd00f4..7ab1b86ba60 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tests/karma.conf.js b/tests/karma.conf.js index a3858227458..c3bcceb8caf 100644 --- a/tests/karma.conf.js +++ b/tests/karma.conf.js @@ -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 = [ @@ -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: '../', diff --git a/webpack.config.js b/webpack.common.cjs similarity index 59% rename from webpack.config.js rename to webpack.common.cjs index ac47f2f5cce..e7c3706168c 100644 --- a/webpack.config.js +++ b/webpack.common.cjs @@ -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( diff --git a/webpack.config.cjs b/webpack.config.cjs new file mode 100644 index 00000000000..d2557dbeeb3 --- /dev/null +++ b/webpack.config.cjs @@ -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' + } + } +}; diff --git a/webpack.module.config.cjs b/webpack.module.config.cjs new file mode 100644 index 00000000000..eeb68809a5c --- /dev/null +++ b/webpack.module.config.cjs @@ -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 + }) + ] + } +}; diff --git a/webpack.prod.config.js b/webpack.prod.config.cjs similarity index 94% rename from webpack.prod.config.js rename to webpack.prod.config.cjs index 982c21958e7..329113bc5e1 100644 --- a/webpack.prod.config.js +++ b/webpack.prod.config.cjs @@ -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',