From d2a858a31ecc43608dbc9da910c65ddb5db8f9a8 Mon Sep 17 00:00:00 2001 From: ashley zomo Date: Fri, 10 Dec 2021 14:49:06 -0600 Subject: [PATCH] init --- .gitignore | 3 +++ package.json | 42 ++++++++++++++++++++++++++++++++ src/index.scss | 3 +++ src/index.ts | 37 ++++++++++++++++++++++++++++ tsconfig.json | 12 +++++++++ webpack.config.js | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 159 insertions(+) create mode 100644 .gitignore create mode 100644 package.json create mode 100644 src/index.scss create mode 100644 src/index.ts create mode 100644 tsconfig.json create mode 100644 webpack.config.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..897cb9f --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules +package-lock.json +dist \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..ad60038 --- /dev/null +++ b/package.json @@ -0,0 +1,42 @@ +{ + "name": "webdj.frontend", + "version": "1.0.0", + "description": "", + "private": "true", + "scripts": { + "build": "webpack", + "serve": "serve dist -p 8080", + "watch": "npm-watch", + "dev": "concurrently \"npm:serve\" \"npm:watch\"" + }, + "watch": { + "build": { + "patterns": [ + "src" + ], + "extensions": "ts,scss", + "legacyWatch": true, + "delay": 2500 + } + }, + "author": "", + "license": "ISC", + "devDependencies": { + "@types/three": "^0.135.0", + "concurrently": "^6.4.0", + "css-loader": "^6.5.1", + "html-webpack-plugin": "^5.5.0", + "mini-css-extract-plugin": "^2.4.5", + "npm-watch": "^0.11.0", + "sass": "^1.44.0", + "sass-loader": "^12.4.0", + "serve": "^13.0.2", + "ts-loader": "^9.2.6", + "typescript": "^4.5.3", + "webpack": "^5.65.0", + "webpack-cli": "^4.9.1" + }, + "dependencies": { + "three": "^0.135.0" + } +} diff --git a/src/index.scss b/src/index.scss new file mode 100644 index 0000000..4e41b69 --- /dev/null +++ b/src/index.scss @@ -0,0 +1,3 @@ +body { + margin: 0; +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..2577f53 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,37 @@ +import * as THREE from 'three'; +import "./index.scss"; + +let camera: THREE.PerspectiveCamera, scene: THREE.Scene, renderer: THREE.WebGLRenderer; +let geometry: THREE.BoxGeometry, material: THREE.MeshNormalMaterial, mesh: THREE.Mesh +; + +init(); + +function init() { + + camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 10 ); + camera.position.z = 1; + + scene = new THREE.Scene(); + + geometry = new THREE.BoxGeometry( 0.2, 0.2, 0.2 ); + material = new THREE.MeshNormalMaterial(); + + mesh = new THREE.Mesh( geometry, material ); + scene.add( mesh ); + + renderer = new THREE.WebGLRenderer( { antialias: true } ); + renderer.setSize( window.innerWidth, window.innerHeight ); + renderer.setAnimationLoop( animation ); + document.body.appendChild( renderer.domElement ); + +} + +function animation( time: number ) { + + mesh.rotation.x = time / 2000; + mesh.rotation.y = time / 1000; + + renderer.render( scene, camera ); + +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..2abbe50 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "outDir": "./dist/", + "sourceMap": true, + "noImplicitAny": true, + "module": "es6", + "target": "es5", + "jsx": "react", + "allowJs": true, + "moduleResolution": "node" + } +} \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..7df6ce5 --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,62 @@ +const path = require('path'), + HtmlWebpackPlugin = require('html-webpack-plugin'), + MiniCssExtractPlugin = require('mini-css-extract-plugin'); + + +module.exports = { + entry: './src/index.ts', + devtool: 'inline-source-map', + mode: 'development', + module: { + rules: [ + { + test: /\.tsx?$/, + use: 'ts-loader', + exclude: /node_modules/, + }, + { + test: /\.s[ac]ss$/i, + use: [ + MiniCssExtractPlugin.loader, + "css-loader", + "sass-loader", + ], + } + ], + }, + resolve: { + extensions: ['.tsx', '.ts', '.js'], + }, + output: { + filename: '[name].[contenthash].js', + path: path.resolve(__dirname, 'dist'), + clean: true, + }, + optimization: { + runtimeChunk: 'single', + splitChunks: { + chunks: 'all', + maxInitialRequests: Infinity, + minSize: 0, + cacheGroups: { + vendor: { + test: /[\\/]node_modules[\\/]/, + name(module) { + // get the name. E.g. node_modules/packageName/not/this/part.js + // or node_modules/packageName + const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1]; + + // npm package names are URL-safe, but some servers don't like @ symbols + return `npm.${packageName.replace('@', '')}`; + }, + }, + }, + }, + }, + plugins: [ + new HtmlWebpackPlugin({ + title: 'webdj' + }), + new MiniCssExtractPlugin() + ], +}; \ No newline at end of file