diff --git a/bench/rollup_config_benchmarks.ts b/bench/rollup_config_benchmarks.ts index 00bab50672..1a08970ec3 100644 --- a/bench/rollup_config_benchmarks.ts +++ b/bench/rollup_config_benchmarks.ts @@ -1,8 +1,7 @@ import fs from 'fs'; import sourcemaps from 'rollup-plugin-sourcemaps'; import replace from '@rollup/plugin-replace'; -import {plugins} from '../build/rollup_plugins'; -import resolve from '@rollup/plugin-node-resolve'; +import {plugins, nodeResolve} from '../build/rollup_plugins'; import commonjs from '@rollup/plugin-commonjs'; import typescript from '@rollup/plugin-typescript'; import {execSync} from 'child_process'; @@ -67,7 +66,7 @@ const viewConfig: RollupOptions = { sourcemap: false }, plugins: [ - resolve({browser: true, preferBuiltins: false}), + nodeResolve, watch ? typescript() : null, commonjs(), replace(replaceConfig) diff --git a/build/rollup_plugins.ts b/build/rollup_plugins.ts index fbe1e30986..83d31513f0 100644 --- a/build/rollup_plugins.ts +++ b/build/rollup_plugins.ts @@ -12,6 +12,12 @@ import {Plugin} from 'rollup'; // Common set of plugins/transformations shared across different rollup // builds (main maplibre bundle, style-spec package, benchmarks bundle) +export const nodeResolve = resolve({ + browser: true, + preferBuiltins: false, + extensions: ['.mjs', '.js', '.json', '.node', '.ts'] +}); + export const plugins = (minified: boolean, production: boolean, watch: boolean): Plugin[] => [ minifyStyleSpec(), json(), @@ -38,10 +44,7 @@ export const plugins = (minified: boolean, production: boolean, watch: boolean): production ? unassert({ include: ['**/*'], // by default, unassert only includes .js files }) : false, - resolve({ - browser: true, - preferBuiltins: false - }), + nodeResolve, watch ? typescript() : false, commonjs({ // global keyword handling causes Webpack compatibility issues, so we disabled it: diff --git a/build/web_worker_replacement.js b/build/web_worker_replacement.ts similarity index 57% rename from build/web_worker_replacement.js rename to build/web_worker_replacement.ts index cb58b1814d..c0d007047a 100644 --- a/build/web_worker_replacement.js +++ b/build/web_worker_replacement.ts @@ -1,5 +1,5 @@ -import maplibregl from '../rollup/build/tsc/src/index' +import maplibregl from '../src/index'; export default function () { return new Worker(maplibregl.workerUrl); -} \ No newline at end of file +} diff --git a/package.json b/package.json index 738ec34fc4..8f17c2d5fd 100644 --- a/package.json +++ b/package.json @@ -136,7 +136,7 @@ "typescript": "^4.5.5" }, "browser": { - "./rollup/build/tsc/src/util/web_worker.js": "./build/web_worker_replacement.js" + "./src/util/web_worker.ts": "./build/web_worker_replacement.ts" }, "scripts": { "generate-shaders": "node --loader ts-node/esm --experimental-specifier-resolution=node build/generate-shaders.ts", diff --git a/rollup.config.style-spec.ts b/rollup.config.style-spec.ts index 91529bb159..5805f9c222 100644 --- a/rollup.config.style-spec.ts +++ b/rollup.config.style-spec.ts @@ -1,11 +1,11 @@ import path, {dirname} from 'path'; import replace from '@rollup/plugin-replace'; -import resolve from '@rollup/plugin-node-resolve'; import commonjs from '@rollup/plugin-commonjs'; import unassert from 'rollup-plugin-unassert'; import json from '@rollup/plugin-json'; import {fileURLToPath, pathToFileURL} from 'url'; import {RollupOptions} from 'rollup'; +import {nodeResolve} from './build/rollup_plugins'; const esm = 'esm' in process.env; @@ -47,10 +47,7 @@ const config: RollupOptions[] = [{ }), json(), unassert(), - resolve({ - browser: true, - preferBuiltins: false - }), + nodeResolve, commonjs() ] }];