openscad-playground/webpack.config.js

189 lines
4.8 KiB
JavaScript
Raw Normal View History

2025-01-02 00:25:46 +01:00
import CopyPlugin from 'copy-webpack-plugin';
import webpack from 'webpack';
2025-08-16 08:29:59 +02:00
import WorkboxPlugin from 'workbox-webpack-plugin';
2025-01-02 00:25:46 +01:00
2025-08-16 08:29:59 +02:00
import path, { dirname } from 'path';
import { fileURLToPath } from 'url';
2025-01-02 00:25:46 +01:00
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
2023-03-25 19:30:34 +00:00
const isDev = process.env.NODE_ENV !== 'production';
2025-01-02 00:25:46 +01:00
/** @type {import('webpack').Configuration[]} */
const config = [
{
entry: './src/index.tsx',
devtool: isDev ? 'source-map' : 'nosources-source-map',
mode: isDev ? 'development' : 'production',
target: 'web',
// devtool: 'inline-source-map',
module: {
rules: [
{
test: /\.tsx?$/,
use: {
loader: 'ts-loader',
🌈 Colorful Playground (#37) * glb (color-assimp2 branch) + model-viewer * color support + customizable output format * cleanup * disable monaco on iOS * reinstate STL viewer when output is stl * default to stl * fix iOS editor * script to build openscad-wasm from a branch / local repo * update fork link + build instructions * Update build-openscad-wasm.sh * Update initial-state.ts * update openscad3 refs * update wasm build script * Update Dockerfile.wasm * add jszip dep * multimaterial: color conversion + 3MF face painting * ignore ts error about compression apis * Update tsconfig.json * multimaterial support w/ extruder colors input component * fix wasm build script * symlinks for openscad.{js,wasm} under src * fix error line shift for bundled files * remove obsolete build script * set OPENSCADPATH env var * render-colors feature renamed * Customizer + prepare Multi-asset support * hide customizer button if unselected, hide it if no params, * Create build-openscad-wasm.sh * update build script * complete sound * fetchSource util * wider rotation allowance * use CSG-modules.scad as default * Update CustomizerPanel.tsx * Update index.html * capture save, allow Ctrl+Shift+Save to save project * customizer: fieldsets are better than accordion * expand customizer tabs by default * tooltip for reset buttons * pretty c++ exceptions * Delete inline-openscad-worker.ts * shuffle ux * use uzip instead of jszip for 3mf materialization * handle legacy links * update links to fork * use render-modifiers feature from color-assimp2 in preview mode * include NopSCADlib's STL files in archive * bind global f5 / f6 * update homepage back to openscad2 * styling fixes (editor alpha, customizer margins) * Add help link for customizer * fix customizer sliders (also need to show value input) * fix vector customizer component * style fallback editor * shorter logs button * customizer: rm reset button tooltip * customizer: allow dnd on viewer below, tweak background * add lights to modelviewer using an env image (gltf lights hard to plug across assimp for now) * update customizer styles * Update .gitignore * add license for UZIP.js (MIT) * Update skybox-lights.jpg * Update actions.ts * include NopSCADlib's STLs * Update LICENSE.md * include YAPP_Box examples * limit customizer height * Update skybox-lights.jpg * Update skybox-lights.jpg * Update openscad-worker.ts * build-openscad-wasm.sh fix: docker won't mount files outside home directory * Use Google CDN instead of unpkg for modelviewer * tmp updates before merge * Add ccache support to build-openscad-wasm.sh * Fix makefile * Update README.md * Fix ts imports * Delete build-openscad-wasm.sh * Crude off -> glb converter * Remove assimp related code * gltf diffs * Build using head openscad * readme: Update build prerequisites * make: attempt to build wasm binary in parallel first * Remove 3mf extruder color mapping & fix render / export flows (render all 3d to off) * off2glb: triangulate faces + add default color * Add simple e2e puppeteer test * ci: update pinned build to master output artefact * Update Makefile * Update test.yml * Update test.yml * Update test.yml * Update test.yml * ci: use relative node version names * Update test.yml * state: Remove renderFormat, introduce is2D * disable service worker in devel mode * remove dead code * build: fix NODE_ENV define * ci: simplify env vars * cleanups * Update README.md
2024-12-22 22:41:35 +00:00
options: {
transpileOnly: true,
compilerOptions: {
module: 'esnext',
moduleResolution: 'node',
target: 'ES2022',
lib: ['WebWorker', 'ES2022'],
sourceMap: isDev,
inlineSources: isDev
}
}
},
exclude: /node_modules/,
2023-03-25 19:30:34 +00:00
},
{
test: /\.css$/i,
use: [
2025-01-02 00:25:46 +01:00
'style-loader',
{
loader: 'css-loader',
2025-08-16 08:29:59 +02:00
options: { url: false },
}
]
2023-03-25 19:30:34 +00:00
},
// {
// test: /\.(png|gif|woff|woff2|eot|ttf|svg)$/,
2025-01-02 00:25:46 +01:00
// loader: 'url-loader?limit=100000'
// },
2023-03-25 19:30:34 +00:00
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
filename: 'index.js',
path: path.resolve(__dirname, 'dist'),
},
devServer: {
2025-01-02 00:25:46 +01:00
static: path.join(__dirname, 'dist'),
compress: true,
port: 4000,
},
plugins: [
new webpack.EnvironmentPlugin({
'process.env.NODE_ENV': 'development',
}),
...(process.env.NODE_ENV === 'production' ? [
new WorkboxPlugin.GenerateSW({
2025-08-16 08:29:59 +02:00
exclude: [
/(^|\/)\./,
/\.map$/,
/^manifest.*\.js$/,
],
// these options encourage the ServiceWorkers to get in there fast
// and not allow any straggling 'old' SWs to hang around
swDest: path.join(__dirname, 'dist', 'sw.js'),
maximumFileSizeToCacheInBytes: 200 * 1024 * 1024,
clientsClaim: true,
skipWaiting: true,
runtimeCaching: [{
urlPattern: ({ request, url }) => true,
handler: 'StaleWhileRevalidate',
options: {
cacheName: 'all',
expiration: {
maxEntries: 1000,
purgeOnQuotaError: true,
},
2025-08-16 08:29:59 +02:00
},
}],
}),
] : []),
new CopyPlugin({
patterns: [
2025-01-02 00:25:46 +01:00
{
from: path.resolve(__dirname, 'public'),
toType: 'dir',
},
2025-01-02 00:25:46 +01:00
{
from: path.resolve(__dirname, 'node_modules/primeicons/fonts'),
to: path.resolve(__dirname, 'dist/fonts'),
toType: 'dir',
},
2025-01-02 00:25:46 +01:00
{
from: path.resolve(__dirname, 'src/wasm/openscad.js'),
2025-08-16 08:29:59 +02:00
to: path.resolve(__dirname, 'dist'),
},
{
from: path.resolve(__dirname, 'src/wasm/openscad.wasm'),
2025-08-16 08:29:59 +02:00
to: path.resolve(__dirname, 'dist'),
},
],
}),
2024-10-23 17:38:03 +01:00
],
},
{
entry: './src/runner/openscad-worker.ts',
output: {
filename: 'openscad-worker.js',
path: path.resolve(__dirname, 'dist'),
globalObject: 'self',
// library: {
// type: 'module'
// }
},
devtool: isDev ? 'source-map' : 'nosources-source-map',
mode: 'production',
// mode: isDev ? 'development' : 'production',
target: 'webworker',
// experiments: {
// outputModule: true,
// },
module: {
rules: [
{
test: /\.tsx?$/,
use: {
loader: 'ts-loader',
options: {
transpileOnly: true,
compilerOptions: {
module: 'esnext',
moduleResolution: 'node',
target: 'ES2022',
lib: ['WebWorker', 'ES2022'],
sourceMap: isDev,
inlineSources: isDev
}
}
},
exclude: /node_modules/,
},
{
test: /\.wasm$/,
type: 'asset/resource'
}
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js', '.mjs', '.wasm'],
modules: [
path.resolve(__dirname, 'src'),
'node_modules'
],
fallback: {
fs: false,
path: false,
module: false
}
},
externals: {
'browserfs': 'BrowserFS'
},
plugins: [
new webpack.EnvironmentPlugin({
'process.env.NODE_ENV': 'development',
}),
],
2024-10-23 17:38:03 +01:00
},
];
2025-01-02 00:25:46 +01:00
export default config;