feat: migrate from commonjs to module

This commit is contained in:
Rotzbua 2025-01-02 00:25:46 +01:00
commit c8268c262e
No known key found for this signature in database
GPG key ID: C69022D529C17845
5 changed files with 35 additions and 19 deletions

View file

@ -7,7 +7,7 @@ on:
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-22.04
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:

View file

@ -1,4 +1,5 @@
module.exports = { /** @type {import('jest-environment-puppeteer').JestPuppeteerConfig} */
const config = {
launch: { launch: {
headless: process.env.CI === "true", headless: process.env.CI === "true",
}, },
@ -8,3 +9,5 @@ module.exports = {
launchTimeout: 180000, launchTimeout: 180000,
}, },
}; };
export default config;

View file

@ -1,6 +1,9 @@
module.exports = { /** @type {import('jest').Config} */
const config = {
preset: "jest-puppeteer", preset: "jest-puppeteer",
testMatch: [ testMatch: [
"**/tests/**/*.js", "**/tests/**/*.js",
], ],
}; };
export default config;

View file

@ -2,6 +2,7 @@
"name": "openscad-playground", "name": "openscad-playground",
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"type": "module",
"homepage": "https://ochafik.com/openscad2/", "homepage": "https://ochafik.com/openscad2/",
"dependencies": { "dependencies": {
"@gltf-transform/core": "^4.1.1", "@gltf-transform/core": "^4.1.1",
@ -63,7 +64,7 @@
"@types/react-dom": "^18.3.5", "@types/react-dom": "^18.3.5",
"@types/uzip": "^0.20201231.2", "@types/uzip": "^0.20201231.2",
"@types/web": "^0.0.140", "@types/web": "^0.0.140",
"copy-webpack-plugin": "^11.0.0", "copy-webpack-plugin": "^12.0.2",
"css-loader": "^7.1.2", "css-loader": "^7.1.2",
"jest": "^29.7.0", "jest": "^29.7.0",
"jest-puppeteer": "^11.0.0", "jest-puppeteer": "^11.0.0",

View file

@ -1,14 +1,21 @@
const webpack = require('webpack'); import CopyPlugin from 'copy-webpack-plugin';
const CopyPlugin = require("copy-webpack-plugin"); import WorkboxPlugin from 'workbox-webpack-plugin';
const WorkboxPlugin = require('workbox-webpack-plugin'); import webpack from 'webpack';
const path = require('path'); import packageConfig from './package.json' with {type: 'json'};
const packageConfig = require('./package.json');
import path, {dirname} from 'path';
import {fileURLToPath} from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const LOCAL_URL = process.env.LOCAL_URL ?? 'http://localhost:4000/'; const LOCAL_URL = process.env.LOCAL_URL ?? 'http://localhost:4000/';
const PUBLIC_URL = process.env.PUBLIC_URL ?? packageConfig.homepage; const PUBLIC_URL = process.env.PUBLIC_URL ?? packageConfig.homepage;
const isDev = process.env.NODE_ENV !== 'production'; const isDev = process.env.NODE_ENV !== 'production';
module.exports = [
/** @type {import('webpack').Configuration[]} */
const config = [
{ {
entry: './src/index.tsx', entry: './src/index.tsx',
devtool: isDev ? 'source-map' : 'nosources-source-map', devtool: isDev ? 'source-map' : 'nosources-source-map',
@ -38,7 +45,7 @@ module.exports = [
{ {
test: /\.css$/i, test: /\.css$/i,
use: [ use: [
"style-loader", 'style-loader',
{ {
loader: 'css-loader', loader: 'css-loader',
options:{url: false}, options:{url: false},
@ -47,7 +54,7 @@ module.exports = [
}, },
// { // {
// test: /\.(png|gif|woff|woff2|eot|ttf|svg)$/, // test: /\.(png|gif|woff|woff2|eot|ttf|svg)$/,
// loader: "url-loader?limit=100000" // loader: 'url-loader?limit=100000'
// }, // },
], ],
}, },
@ -59,7 +66,7 @@ module.exports = [
path: path.resolve(__dirname, 'dist'), path: path.resolve(__dirname, 'dist'),
}, },
devServer: { devServer: {
static: path.join(__dirname, "dist"), static: path.join(__dirname, 'dist'),
compress: true, compress: true,
port: 4000, port: 4000,
}, },
@ -75,8 +82,8 @@ module.exports = [
/^manifest.*\.js$/, /^manifest.*\.js$/,
], ],
// these options encourage the ServiceWorkers to get in there fast // these options encourage the ServiceWorkers to get in there fast
// and not allow any straggling "old" SWs to hang around // and not allow any straggling 'old' SWs to hang around
swDest: path.join(__dirname, "dist", 'sw.js'), swDest: path.join(__dirname, 'dist', 'sw.js'),
maximumFileSizeToCacheInBytes: 200 * 1024 * 1024, maximumFileSizeToCacheInBytes: 200 * 1024 * 1024,
clientsClaim: true, clientsClaim: true,
skipWaiting: true, skipWaiting: true,
@ -177,3 +184,5 @@ module.exports = [
], ],
}, },
]; ];
export default config;