Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sourcemaps in dev builds #25901

Merged
merged 2 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"eslint-plugin-import": "^2.27.5",
"failonlyreporter": "^1.0.0",
"jimp": "^0.22.7",
"magic-string": "^0.30.0",
"pixelmatch": "^5.3.0",
"puppeteer-core": "^19.8.1",
"qunit": "^2.19.4",
Expand Down
39 changes: 28 additions & 11 deletions utils/build/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import terser from '@rollup/plugin-terser';
import MagicString from 'magic-string';

function addons() {

Expand All @@ -8,11 +9,13 @@ function addons() {

if ( /\/examples\/jsm\//.test( id ) === false ) return;

code = code.replace( 'build/three.module.js', 'src/Three.js' );
code = new MagicString( code );

code.replace( 'build/three.module.js', 'src/Three.js' );

return {
code: code,
map: null
code: code.toString(),
map: code.generateMap().toString()
};

}
Expand All @@ -29,7 +32,9 @@ export function glsl() {

if ( /\.glsl.js$/.test( id ) === false ) return;

code = code.replace( /\/\* glsl \*\/\`(.*?)\`/sg, function ( match, p1 ) {
code = new MagicString( code );

code.replace( /\/\* glsl \*\/\`(.*?)\`/sg, function ( match, p1 ) {

return JSON.stringify(
p1
Expand All @@ -43,8 +48,8 @@ export function glsl() {
} );

return {
code: code,
map: null
code: code.toString(),
map: code.generateMap().toString()
};

}
Expand All @@ -59,12 +64,18 @@ function header() {

renderChunk( code ) {

return `/**
code = new MagicString( code );

code.prepend( `/**
* @license
* Copyright 2010-2023 Three.js Authors
* SPDX-License-Identifier: MIT
*/
${ code }`;
*/\n` );

return {
code: code.toString(),
map: code.generateMap().toString()
};

}

Expand All @@ -78,8 +89,14 @@ function deprecationWarning() {

renderChunk( code ) {

return `console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated with r150+, and will be removed with r160. Please use ES Modules or alternatives: https://threejs.org/docs/index.html#manual/en/introduction/Installation' );
${ code }`;
code = new MagicString( code );

code.prepend( `console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated with r150+, and will be removed with r160. Please use ES Modules or alternatives: https://threejs.org/docs/index.html#manual/en/introduction/Installation' );\n` );

return {
code: code.toString(),
map: code.generateMap().toString()
};

}

Expand Down