Преглед на файлове

Examples: Convert jsm examples to use bare three import only before publish (#21654)

* Add prepublish script

* Add prepublish only script
Garrett Johnson преди 4 години
родител
ревизия
53e3b99dfe
променени са 2 файла, в които са добавени 14 реда и са изтрити 1 реда
  1. 2 1
      package.json
  2. 12 0
      utils/prepublish.js

+ 2 - 1
package.json

@@ -73,7 +73,8 @@
     "test-e2e": "node test/e2e/puppeteer.js",
     "test-e2e-cov": "node test/e2e/check-coverage.js",
     "test-treeshake": "rollup -c test/rollup.treeshake.config.js",
-    "make-screenshot": "node test/e2e/puppeteer.js --make"
+    "make-screenshot": "node test/e2e/puppeteer.js --make",
+    "prepublishOnly": "node utils/prepublish.js"
   },
   "keywords": [
     "three",

+ 12 - 0
utils/prepublish.js

@@ -0,0 +1,12 @@
+const fs = require( 'fs' );
+const path = require( 'path' );
+const glob = require( 'glob' );
+
+const paths = glob.sync( path.resolve( __dirname, '../examples/jsm/**/*.js' ) );
+paths.forEach( p => {
+
+	const content = fs.readFileSync( p, { encoding: 'utf8' } );
+	const bareContent = content.replace( /(\.\.\/){2,}build\/three.module.js/g, 'three' );
+	fs.writeFileSync( p, bareContent, { encoding: 'utf8' } );
+
+} );