Browse Source

chore: 打包优化

es6
iapyang 5 years ago
parent
commit
778929e633
  1. 9
      Gruntfile.js
  2. 36
      lib/postbuild/postbuild.js
  3. 2
      package.json
  4. 6
      yarn.lock

9
Gruntfile.js

@ -106,7 +106,7 @@ module.exports = function (grunt) {
}, },
bundleJs: { 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", dest: "dist/bundle.js",
}, },
@ -116,7 +116,7 @@ module.exports = function (grunt) {
}, },
bundleIEJs: { 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" dest: "dist/bundle.ie.js"
}, },
@ -137,13 +137,13 @@ module.exports = function (grunt) {
fineuiJs: { fineuiJs: {
src: ["dist/polyfill.js", "dist/core.js", "dist/fix/fix.js", "dist/base.js", 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" dest: "dist/fineui.js"
}, },
fineuiIEJs: { fineuiIEJs: {
src: ["dist/polyfill.js", "dist/core.js", "dist/fix/fix.ie.js", "dist/base.js", 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" 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", banner: "/*! <%= pkg.name %> <%= grunt.template.today(\"yyyy-mm-dd HH:MM:ss\") %> */\n",
mangle: false, mangle: false,
sourceMap: true, sourceMap: true,
sourceMapIncludeSources: true,
compress: { compress: {
unused: false, unused: false,
}, },

36
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"]);

2
package.json

@ -20,6 +20,7 @@
"autoprefixer": "9.6.1", "autoprefixer": "9.6.1",
"babel-loader": "8.0.6", "babel-loader": "8.0.6",
"chai": "4.2.0", "chai": "4.2.0",
"concat-with-sourcemaps": "1.1.0",
"core-js": "3.3.2", "core-js": "3.3.2",
"cross-env": "6.0.0", "cross-env": "6.0.0",
"css-loader": "3.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", "webpack:prod:ie8": "cross-env BROWSER_VERSION=ie8 webpack -p --progress --config=webpack/webpack.prod.js --mode production",
"start": "node server.js", "start": "node server.js",
"build": "npm run webpack:prod && npm run webpack:prod:ie8 && grunt build", "build": "npm run webpack:prod && npm run webpack:prod:ie8 && grunt build",
"postbuild": "node ./lib/postbuild/postbuild.js",
"compile": "grunt compile", "compile": "grunt compile",
"fake": "grunt fake-build", "fake": "grunt fake-build",
"test": "karma start", "test": "karma start",

6
yarn.lock

@ -1852,6 +1852,12 @@ concat-stream@^1.4.1, concat-stream@^1.5.0:
readable-stream "^2.2.2" readable-stream "^2.2.2"
typedarray "^0.0.6" 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: connect-history-api-fallback@^1.6.0:
version "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" resolved "https://registry.yarnpkg.com/connect-history-api-fallback/-/connect-history-api-fallback-1.6.0.tgz#8b32089359308d111115d81cad3fceab888f97bc"

Loading…
Cancel
Save