Parcourir la source

Revert "Remove rollup.unit.config.js file and implement conditional environment in rollup.config.js (Available env are "production" and "test" for the moment)"

This reverts commit e2b027637e69dfb421bf2cffe7ddef10d9ebe17a.
Tristan Valcke il y a 8 ans
Parent
commit
793088705f
2 fichiers modifiés avec 51 ajouts et 56 suppressions
  1. 11 56
      rollup.config.js
  2. 40 0
      rollup.unit.config.js

+ 11 - 56
rollup.config.js

@@ -24,66 +24,21 @@ function glsl() {
 }
 
 export default {
-
-	entry: (function () {
-
-		var env = process.env.BUILD;
-
-		if( env === 'production' ) {
-
-			return 'src/Three.js';
-
-		} else if( env === 'test' ){
-
-			return 'test/Three.Unit.js';
-
-		} else {
-
-			console.error("Invalid BUILD environment variable: " + env);
-			return null;
-
-		}
-
-	})(),
+	entry: 'src/Three.js',
 	indent: '\t',
 	plugins: [
 		glsl()
 	],
 	// sourceMap: true,
-	targets: (function () {
-
-		var env = process.env.BUILD;
-
-		if( env === 'production' ) {
-
-			return [
-				{
-					format: 'umd',
-					moduleName: 'THREE',
-					dest: 'build/three.js'
-				},
-				{
-					format: 'es',
-					dest: 'build/three.module.js'
-				}
-			];
-
-		} else if( env === 'test' ){
-
-			return [
-				{
-					format: 'umd',
-					moduleName: 'THREE',
-					dest: 'test/unit/three.unit.js'
-				}
-			];
-
-		} else {
-
-			console.error("Invalid BUILD environment variable: " + env);
-			return null;
-
+	targets: [
+		{
+			format: 'umd',
+			moduleName: 'THREE',
+			dest: 'build/three.js'
+		},
+		{
+			format: 'es',
+			dest: 'build/three.module.js'
 		}
-
-	})()
+	]
 };

+ 40 - 0
rollup.unit.config.js

@@ -0,0 +1,40 @@
+function glsl() {
+
+	return {
+
+		transform( code, id ) {
+
+			if ( /\.glsl$/.test( id ) === false ) return;
+
+			var transformedCode = 'export default ' + JSON.stringify(
+				code
+					.replace( /[ \t]*\/\/.*\n/g, '' )
+					.replace( /[ \t]*\/\*[\s\S]*?\*\//g, '' )
+					.replace( /\n{2,}/g, '\n' )
+			) + ';';
+			return {
+				code: transformedCode,
+				map: { mappings: '' }
+			};
+
+		}
+
+	};
+
+}
+
+export default {
+	entry: 'test/Three.Unit.js',
+	indent: '\t',
+	plugins: [
+		glsl()
+	],
+	// sourceMap: true,
+	targets: [
+		{
+			format: 'umd',
+			moduleName: 'THREE',
+			dest: 'test/unit/three.unit.js'
+		}
+	]
+};