reconcile new three modules, create a bundle
This commit is contained in:
parent
e26e57e193
commit
9adfe33cfb
19 changed files with 82 additions and 60 deletions
|
|
@ -1,31 +1,7 @@
|
|||
const os = require('os');
|
||||
const fs = require('fs-extra');
|
||||
const fetchr = import('node-fetch');
|
||||
const path = require('path');
|
||||
|
||||
async function download(url, filePath) {
|
||||
const fetch = (await fetchr).default;
|
||||
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch ${url}: ${response.statusText}`);
|
||||
}
|
||||
|
||||
fs.ensureDir(path.dirname(filePath));
|
||||
const fileStream = fs.createWriteStream(filePath);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
response.body.pipe(fileStream);
|
||||
response.body.on('error', reject);
|
||||
fileStream.on('error', error => {
|
||||
console.log({ error });
|
||||
});
|
||||
fileStream.on('finish', () => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log('npm pre running');
|
||||
|
||||
|
|
|
|||
5
bin/webpack-three-bundle.js
Normal file
5
bin/webpack-three-bundle.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import * as THREE from "../node_modules/three/build/three.module.js";
|
||||
import * as SVGLoader from "../node_modules/three/examples/jsm/loaders/SVGLoader.js";
|
||||
import * as BufferGeometryUtils from "../node_modules/three/examples/jsm/utils/BufferGeometryUtils.js";
|
||||
|
||||
export { THREE, SVGLoader, BufferGeometryUtils };
|
||||
45
bin/webpack-three.js
Normal file
45
bin/webpack-three.js
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
const TerserPlugin = require("terser-webpack-plugin");
|
||||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
mode: 'production',
|
||||
entry: "./bin/webpack-three-bundle.js",
|
||||
output: {
|
||||
path: path.resolve('src/ext'),
|
||||
filename: 'three.js',
|
||||
library: 'ThreeBundle',
|
||||
libraryTarget: 'umd',
|
||||
globalObject: 'this'
|
||||
},
|
||||
resolve: {
|
||||
extensions: ['.mjs', '.js'],
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.m?js$/,
|
||||
resolve: {
|
||||
fullySpecified: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
optimization: {
|
||||
minimize: false,
|
||||
minimizer: [
|
||||
new TerserPlugin({
|
||||
extractComments: false,
|
||||
terserOptions: {
|
||||
format: {
|
||||
comments: false,
|
||||
},
|
||||
},
|
||||
}),
|
||||
],
|
||||
},
|
||||
performance: {
|
||||
hints: false,
|
||||
maxAssetSize: 2 * 1024 * 1024,
|
||||
maxEntrypointSize: 2 * 1024 * 1024,
|
||||
},
|
||||
};
|
||||
Loading…
Reference in a new issue