Преглед изворни кода

remove comments and unnecessary newlines from glsl files (#9389)

Rich Harris пре 9 година
родитељ
комит
ee0b32e80d
2 измењених фајлова са 16 додато и 5 уклоњено
  1. 0 1
      package.json
  2. 16 4
      rollup.config.js

+ 0 - 1
package.json

@@ -46,7 +46,6 @@
     "chokidar-cli": "1.2.0",
     "jscs": "^1.13.1",
     "rollup": "^0.33.1",
-    "rollup-plugin-string": "^2.0.2",
     "uglify-js": "^2.6.0"
   }
 }

+ 16 - 4
rollup.config.js

@@ -1,5 +1,4 @@
 import * as fs from 'fs';
-import string from 'rollup-plugin-string';
 
 var outro = `
 Object.defineProperty( exports, 'AudioContext', {
@@ -10,15 +9,28 @@ Object.defineProperty( exports, 'AudioContext', {
 
 var footer = fs.readFileSync( 'src/Three.Legacy.js', 'utf-8' );
 
+function glsl () {
+	return {
+		transform ( code, id ) {
+			if ( !/\.glsl$/.test( id ) ) return;
+
+			return 'export default ' + JSON.stringify(
+				code
+					.replace( /[ \t]*\/\/.*\n/g, '' )
+					.replace( /[ \t]*\/\*[\s\S]*?\*\//g, '' )
+					.replace( /\n{2,}/g, '\n' )
+			) + ';';
+		}
+	};
+}
+
 export default {
 	entry: 'src/Three.js',
 	dest: 'build/three.js',
 	moduleName: 'THREE',
 	format: 'umd',
 	plugins: [
-		string({
-			include: '**/*.glsl'
-		})
+		glsl()
 	],
 
 	outro: outro,