From 778929e633ed7ec80767a3d863adeae483952558 Mon Sep 17 00:00:00 2001 From: iapyang Date: Mon, 21 Oct 2019 18:18:31 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=89=93=E5=8C=85=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gruntfile.js | 9 +++++---- lib/postbuild/postbuild.js | 36 ++++++++++++++++++++++++++++++++++++ package.json | 2 ++ yarn.lock | 6 ++++++ 4 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 lib/postbuild/postbuild.js diff --git a/Gruntfile.js b/Gruntfile.js index 577578c54..5154dbf59 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -106,7 +106,7 @@ module.exports = function (grunt) { }, bundleJs: { - src: ["dist/core.js", "dist/fix/fix.js", "dist/base.js", "dist/case.js", "dist/widget.js", "dist/fix/fix.compact.js", "dist/router.js", "public/js/**/*.js", "public/js/index.js", "i18n/i18n.cn.js", "dist/fineui.typescript.js"], + src: ["dist/core.js", "dist/fix/fix.js", "dist/base.js", "dist/case.js", "dist/widget.js", "dist/fix/fix.compact.js", "dist/router.js", "public/js/**/*.js", "public/js/index.js", "i18n/i18n.cn.js"], dest: "dist/bundle.js", }, @@ -116,7 +116,7 @@ module.exports = function (grunt) { }, bundleIEJs: { - src: ["dist/core.js", "dist/fix/fix.ie.js", "dist/base.js", "dist/case.js", "dist/widget.js", "dist/fix/fix.compact.ie.js", "dist/router.js", "public/js/**/*.js", "public/js/index.js", "i18n/i18n.cn.js", "dist/fineui.typescript.ie8.js"], + src: ["dist/core.js", "dist/fix/fix.ie.js", "dist/base.js", "dist/case.js", "dist/widget.js", "dist/fix/fix.compact.ie.js", "dist/router.js", "public/js/**/*.js", "public/js/index.js", "i18n/i18n.cn.js"], dest: "dist/bundle.ie.js" }, @@ -137,13 +137,13 @@ module.exports = function (grunt) { fineuiJs: { src: ["dist/polyfill.js", "dist/core.js", "dist/fix/fix.js", "dist/base.js", - "dist/case.js", "dist/widget.js", "dist/router.js", "dist/fix/fix.compact.js", "ui/js/**/*.js", "dist/fineui.typescript.js"], + "dist/case.js", "dist/widget.js", "dist/router.js", "dist/fix/fix.compact.js", "ui/js/**/*.js"], dest: "dist/fineui.js" }, fineuiIEJs: { src: ["dist/polyfill.js", "dist/core.js", "dist/fix/fix.ie.js", "dist/base.js", - "dist/case.js", "dist/widget.js", "dist/router.js", "dist/fix/fix.compact.ie.js", "ui/js/**/*.js", "dist/fineui.typescript.ie.js"], + "dist/case.js", "dist/widget.js", "dist/router.js", "dist/fix/fix.compact.ie.js", "ui/js/**/*.js"], dest: "dist/fineui.ie.js" }, @@ -274,6 +274,7 @@ module.exports = function (grunt) { banner: "/*! <%= pkg.name %> <%= grunt.template.today(\"yyyy-mm-dd HH:MM:ss\") %> */\n", mangle: false, sourceMap: true, + sourceMapIncludeSources: true, compress: { unused: false, }, diff --git a/lib/postbuild/postbuild.js b/lib/postbuild/postbuild.js new file mode 100644 index 000000000..98dcad2d7 --- /dev/null +++ b/lib/postbuild/postbuild.js @@ -0,0 +1,36 @@ +const Concat = require("concat-with-sourcemaps"); +const { resolve } = require("path"); +const fs = require("fs"); + +function unionJs(filenames) { + const filename = filenames[0]; + + var concat = new Concat(true, filename, "\n"); + + filenames.forEach(filename => { + concat.add( + filename, + fs.readFileSync(resolve(__dirname, `../../dist/${filename}`)), + fs.readFileSync(resolve(__dirname, `../../dist/${filename}.map`)).toString() + ); + }); + + concat.add(null, `//# sourceMappingURL=${filename}.map`); + + var concatenatedContent = concat.content; + var sourceMapForContent = concat.sourceMap; + + fs.writeFileSync(resolve(__dirname, "../../dist", filename), concatenatedContent, { + encoding: "utf8", + }); + + fs.writeFileSync(resolve(__dirname, "../../dist", `${filename}.map`), sourceMapForContent, { + encoding: "utf8", + }); +} + +unionJs(["bundle.min.js", "fineui.typescript.js"]); +unionJs(["bundle.ie.min.js", "fineui.typescript.ie.js"]); +unionJs(["fineui.min.js", "fineui.typescript.js"]); +unionJs(["fineui.ie.min.js", "fineui.typescript.ie.js"]); +// unionJs(["bundle.min.js", "fineui.typescript.js"]); diff --git a/package.json b/package.json index 4436fc2ec..cdb813eb8 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "autoprefixer": "9.6.1", "babel-loader": "8.0.6", "chai": "4.2.0", + "concat-with-sourcemaps": "1.1.0", "core-js": "3.3.2", "cross-env": "6.0.0", "css-loader": "3.0.0", @@ -68,6 +69,7 @@ "webpack:prod:ie8": "cross-env BROWSER_VERSION=ie8 webpack -p --progress --config=webpack/webpack.prod.js --mode production", "start": "node server.js", "build": "npm run webpack:prod && npm run webpack:prod:ie8 && grunt build", + "postbuild": "node ./lib/postbuild/postbuild.js", "compile": "grunt compile", "fake": "grunt fake-build", "test": "karma start", diff --git a/yarn.lock b/yarn.lock index ae0bf0ee8..e4ba0ee6a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1852,6 +1852,12 @@ concat-stream@^1.4.1, concat-stream@^1.5.0: readable-stream "^2.2.2" typedarray "^0.0.6" +concat-with-sourcemaps@1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/concat-with-sourcemaps/-/concat-with-sourcemaps-1.1.0.tgz#d4ea93f05ae25790951b99e7b3b09e3908a4082e" + dependencies: + source-map "^0.6.1" + connect-history-api-fallback@^1.6.0: version "1.6.0" resolved "https://registry.yarnpkg.com/connect-history-api-fallback/-/connect-history-api-fallback-1.6.0.tgz#8b32089359308d111115d81cad3fceab888f97bc"