Browse Source

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

Tristan VALCKE 8 years ago
parent
commit
e2b027637e
2 changed files with 56 additions and 51 deletions
  1. 56 11
      rollup.config.js
  2. 0 40
      rollup.unit.config.js

+ 56 - 11
rollup.config.js

@@ -24,21 +24,66 @@ function glsl() {
 }
 }
 
 
 export default {
 export default {
-	entry: 'src/Three.js',
+
+	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;
+
+		}
+
+	})(),
 	indent: '\t',
 	indent: '\t',
 	plugins: [
 	plugins: [
 		glsl()
 		glsl()
 	],
 	],
 	// sourceMap: true,
 	// sourceMap: true,
-	targets: [
-		{
-			format: 'umd',
-			moduleName: 'THREE',
-			dest: 'build/three.js'
-		},
-		{
-			format: 'es',
-			dest: 'build/three.module.js'
+	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;
+
 		}
 		}
-	]
+
+	})()
 };
 };

+ 0 - 40
rollup.unit.config.js

@@ -1,40 +0,0 @@
-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'
-		}
-	]
-};