I wanted to try using webpack with r168 or, more precisely, use webpack for the first time since three.webgpu.js came out. In my importmap I clearly reference three.webgpu.js
<script type="importmap"> {
"imports": {
"three": "./node_modules/three/build/three.webgpu.js",
"three/tsl": "./node_modules/three/build/three.webgpu.js",
"three/addons/": "./node_modules/three/examples/jsm/"
}
}
</script>
And this is what my webpack config looks like
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
module.exports = {
//mode: 'development',
//devtool: "none",
mode: 'production',
devtool: 'source-map',
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'build'),
filename: 'bundle.js'
},
devServer: {
port: 8889
},
experiments: {
topLevelAwait: true
},
resolve: {
alias: {
'three': 'three',
},
},
optimization: {
minimize: true,
minimizer: [new TerserPlugin({
terserOptions: {
mangle: false,
output: {
comments: false,
},
compress: {
warnings: false,
drop_console: true,
drop_debugger: true,
pure_funcs: ['console.log'],
unused: true,
},
output: {
comments: false,
},
},
})],
},
plugins: [
//new BundleAnalyzerPlugin()
]
};
Interestingly, webpack still uses three.module.js for bundling. Of course, this can’t work well because three.module.js doesn’t contain the webgpu components and that’s why the bundling fails.
If I remove three.module.js, the unbundled app still runs without any problems, which is logical since I clearly refer to three.webgpu.js with the import map. But webpack then fails completely because it obviously expects three.module.js for three.js.
Does anyone have an idea of ​​where webpack references three.module.js?
P.S. I wish I had thought about it for a few minutes longer before writing here
The reason is because three.js references three.modules.js in its node_modules/three/package.json. If you change that everywhere in the package.json to three.webgpu.js it works