Bläddra i källkod

添加正式环境打包压缩转化

bill-lai 3 år sedan
förälder
incheckning
71cec55ede
5 ändrade filer med 3843 tillägg och 3 borttagningar
  1. 5 0
      .balbelrc
  2. 15 0
      main.js
  3. 8 2
      package.json
  4. 19 1
      rollup.config.js
  5. 3796 0
      yarn.lock

+ 5 - 0
.balbelrc

@@ -0,0 +1,5 @@
+{
+  "presets": [
+    "@babel/preset-env"
+  ]
+}

+ 15 - 0
main.js

@@ -0,0 +1,15 @@
+const util = require('util');
+const child_process = require('child_process');
+const exec = util.promisify(child_process.exec);
+const fs = require('fs-extra')
+const path = require('path')
+
+const PATH = `./.laser-lib-path`
+const buildPaths = [
+	`build`,
+	...fs.existsSync(PATH) ? [fs.readFileSync(PATH).toString()] : []
+]
+
+buildPaths.forEach(d => fs.emptyDirSync(path.resolve(__dirname, d)))
+
+exec(`yarn build-c`);

+ 8 - 2
package.json

@@ -17,16 +17,22 @@
   ],
   "main": "./build/potree/potree.js",
   "scripts": {
-    "start": "gulp watch",
-    "build": "gulp build pack",
+    "start": "gulp watch -c development",
+    "build": "node main.js",
+    "build-c": "gulp build pack -c production",
     "postinstall": "npm run build"
   },
   "dependencies": {
+    "@babel/core": "^7.16.10",
+    "@babel/preset-env": "^7.16.10",
+    "fs-extra": "^10.0.0",
     "gulp": "^4.0.2",
     "gulp-concat": "^2.6.1",
     "gulp-connect": "^5.7.0",
     "json5": "^2.1.3",
     "rollup": "^1.31.1",
+    "rollup-plugin-babel": "^4.4.0",
+    "rollup-plugin-uglify": "^6.0.4",
     "through": "~2.3.4"
   },
   "author": "Markus Schütz",

+ 19 - 1
rollup.config.js

@@ -1,4 +1,8 @@
-const fs = require('fs')
+const fs = require('fs-extra')
+const path = require('path')
+const babel = require('rollup-plugin-babel');
+const { uglify } = require('rollup-plugin-uglify');
+
 const PATH = `./.laser-lib-path`
 const buildPaths = [
 	`build`,
@@ -48,4 +52,18 @@ for (const dir of buildPaths) {
 	)
 }
 
+if (process.env.npm_lifecycle_script.includes('production')) {
+	builds.forEach(item => {
+		item.output.sourcemap = false
+		item.plugins = [
+			babel({
+				exclude: "node_modules/**"
+			}),
+			// 压缩代码
+			uglify()
+		]
+	})
+}
+
+
 export default builds

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 3796 - 0
yarn.lock