Skip to content

Commit 24cb1b9

Browse files
committed
feat: migrate from commonjs to module
1 parent 5617355 commit 24cb1b9

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "openscad-playground",
33
"version": "0.1.0",
44
"private": true,
5+
"type": "module",
56
"homepage": "https://ochafik.com/openscad2/",
67
"dependencies": {
78
"@gltf-transform/core": "^4.1.1",
@@ -63,7 +64,7 @@
6364
"@types/react-dom": "^18.3.5",
6465
"@types/uzip": "^0.20201231.2",
6566
"@types/web": "^0.0.140",
66-
"copy-webpack-plugin": "^11.0.0",
67+
"copy-webpack-plugin": "^12.0.2",
6768
"css-loader": "^7.1.2",
6869
"jest": "^29.7.0",
6970
"jest-puppeteer": "^11.0.0",

webpack.config.js

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1-
const webpack = require('webpack');
2-
const CopyPlugin = require("copy-webpack-plugin");
3-
const WorkboxPlugin = require('workbox-webpack-plugin');
4-
const path = require('path');
5-
const packageConfig = require('./package.json');
1+
import CopyPlugin from 'copy-webpack-plugin';
2+
import WorkboxPlugin from 'workbox-webpack-plugin';
3+
import webpack from 'webpack';
4+
import packageConfig from './package.json' with {type: 'json'};
5+
6+
import path, {dirname} from 'path';
7+
import {fileURLToPath} from 'url';
8+
9+
const __filename = fileURLToPath(import.meta.url);
10+
const __dirname = dirname(__filename);
611

712
const LOCAL_URL = process.env.LOCAL_URL ?? 'http://localhost:4000/';
813
const PUBLIC_URL = process.env.PUBLIC_URL ?? packageConfig.homepage;
914
const isDev = process.env.NODE_ENV !== 'production';
1015

11-
module.exports = [
16+
17+
/**
18+
* @type {import('webpack').Configuration[]}
19+
*/
20+
const config = [
1221
{
1322
entry: './src/index.tsx',
1423
devtool: isDev ? 'source-map' : 'nosources-source-map',
@@ -38,7 +47,7 @@ module.exports = [
3847
{
3948
test: /\.css$/i,
4049
use: [
41-
"style-loader",
50+
'style-loader',
4251
{
4352
loader: 'css-loader',
4453
options:{url: false},
@@ -47,7 +56,7 @@ module.exports = [
4756
},
4857
// {
4958
// test: /\.(png|gif|woff|woff2|eot|ttf|svg)$/,
50-
// loader: "url-loader?limit=100000"
59+
// loader: 'url-loader?limit=100000'
5160
// },
5261
],
5362
},
@@ -59,7 +68,7 @@ module.exports = [
5968
path: path.resolve(__dirname, 'dist'),
6069
},
6170
devServer: {
62-
static: path.join(__dirname, "dist"),
71+
static: path.join(__dirname, 'dist'),
6372
compress: true,
6473
port: 4000,
6574
},
@@ -74,9 +83,9 @@ module.exports = [
7483
/\.map$/,
7584
/^manifest.*\.js$/,
7685
],
77-
// these options encourage the ServiceWorkers to get in there fast
78-
// and not allow any straggling "old" SWs to hang around
79-
swDest: path.join(__dirname, "dist", 'sw.js'),
86+
// these options encourage the ServiceWorkers to get in there fast
87+
// and not allow any straggling 'old' SWs to hang around
88+
swDest: path.join(__dirname, 'dist', 'sw.js'),
8089
maximumFileSizeToCacheInBytes: 200 * 1024 * 1024,
8190
clientsClaim: true,
8291
skipWaiting: true,
@@ -95,16 +104,16 @@ module.exports = [
95104
] : []),
96105
new CopyPlugin({
97106
patterns: [
98-
{
107+
{
99108
from: path.resolve(__dirname, 'public'),
100109
toType: 'dir',
101110
},
102-
{
111+
{
103112
from: path.resolve(__dirname, 'node_modules/primeicons/fonts'),
104113
to: path.resolve(__dirname, 'dist/fonts'),
105114
toType: 'dir',
106115
},
107-
{
116+
{
108117
from: path.resolve(__dirname, 'src/wasm/openscad.js'),
109118
from: path.resolve(__dirname, 'src/wasm/openscad.wasm'),
110119
},
@@ -177,3 +186,5 @@ module.exports = [
177186
],
178187
},
179188
];
189+
190+
export default config;

0 commit comments

Comments
 (0)