From 0ea168688c91a1fe6cc409ee4953f099843dbfdb Mon Sep 17 00:00:00 2001 From: iapyang Date: Fri, 3 Jul 2020 11:46:40 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20webpack=E6=89=93=E5=8C=85=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/postbuild/postbuild.js | 48 ++++++-------------------------------- webpack/attachments.js | 18 ++++++++++---- webpack/dirs.js | 7 ++++++ webpack/webpack.common.js | 46 +++++++++++++++++++++++++++++++++++- webpack/webpack.prod.js | 16 +++++++++---- 5 files changed, 83 insertions(+), 52 deletions(-) diff --git a/lib/postbuild/postbuild.js b/lib/postbuild/postbuild.js index 9deb38a63..47736bd6f 100644 --- a/lib/postbuild/postbuild.js +++ b/lib/postbuild/postbuild.js @@ -1,5 +1,5 @@ const { resolve } = require("path"); -const { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } = require("fs"); +const { existsSync, mkdirSync, readFileSync, writeFileSync } = require("fs"); const rimraf = require("rimraf"); const dest = resolve(__dirname, '../../dist'); @@ -11,49 +11,15 @@ if (!existsSync($dest)) { } const deleteList = [ - "bundle.ie.css", - "bundle_without_normalize.js", - "bundle_without_normalize.js.map", - "fineui.ie.css", + "fineui.ie.min.css", "fineui_without_jquery_polyfill.css", + "font.js", + "font.js.map", + "2.0/fineui.ie.min.css", + "2.0/fineui_without_normalize.js", + "2.0/fineui_without_normalize.js.map", ]; -const copyList = [{ - source: "bundle.min", - exts: ["css", "js", "js.map"], - targets: ["2.0/fineui", "2.0/fineui.min"], -}, { - source: "bundle_without_normalize", - exts: ["css"], - targets: ["2.0/fineui_without_normalize", "2.0/fineui_without_normalize.min"], -}, { - source: "fineui", - exts: ["css", "js", "js.map"], - targets: ["fineui.min"], -}, { - source: "utils", - exts: ["js", "js.map"], - targets: ["utils.min"], -}, { - source: "bundle.ie", - exts: ["js", "js.map"], - targets: ["2.0/fineui.ie", "2.0/fineui.ie.min"], -}]; - -copyList.forEach(conf => { - conf.exts.forEach(ext => { - const sourcefile = resolve(dest, `./${conf.source}.${ext}`); - - if (!existsSync(sourcefile)) { - console.log(`${sourcefile} does not exist!`); - } - - conf.targets.forEach(target => { - copyFileSync(sourcefile, resolve(dest, `./${target}.${ext}`)); - }); - }); -}); - deleteList.forEach(filename => { const sourcefile = resolve(dest, `./${filename}`); diff --git a/webpack/attachments.js b/webpack/attachments.js index ca5a3a20c..1f7cb20a8 100644 --- a/webpack/attachments.js +++ b/webpack/attachments.js @@ -8,6 +8,10 @@ function sync(patterns) { return uniq(grunt.file.expand({ filter: path => !new RegExp(/__test__/g).test(path) }, patterns)).map(name => `./${name}`); } +const fixJs = "./dist/fix/fix.js"; +const fixIEJs = "./dist/fix/fix.ie.js"; +const lodashJs = "src/core/lodash.js"; + const basicAttachmentMap = { polyfill: sync(["src/core/foundation.js", "src/polyfill/**/*.js"]).concat(["@babel/polyfill", "es6-promise/auto"]), polyfillIE: sync(["src/core/foundation.js", "src/polyfill/**/*.js"]).concat([ @@ -28,7 +32,7 @@ const basicAttachmentMap = { "src/less/core/**/*.less", "src/less/theme/**/*.less", "src/core/foundation.js", - "src/core/lodash.js", + lodashJs, // 'src/core/mvc/**/*.js', "src/core/base.js", "src/core/ob.js", @@ -87,7 +91,7 @@ const basicAttachmentMap = { config: sync(["demo/version.js", "i18n/i18n.cn.js"]), utils: sync([ "src/core/foundation.js", - "src/core/lodash.js", + lodashJs, "src/core/var.js", "src/core/func/array.js", "src/core/func/number.js", @@ -105,8 +109,8 @@ const basicAttachmentMap = { "src/data/data.js", "src/data/**/*.js", ]), - fix: ['./typescript/fix/fix.ts'], - fixIE: ['./typescript/fix/fix.ie.ts'], + fix: [fixJs], + fixIE: [fixIEJs], }; const bundle = [].concat( @@ -177,7 +181,7 @@ const fineuiIE = [].concat( const fineuiWithoutJqueryAndPolyfillJs = [].concat( sync([ "src/core/foundation.js", - "src/core/lodash.js", + lodashJs, // 'src/core/mvc/**/*.js', "src/core/base.js", "src/core/ob.js", @@ -232,6 +236,10 @@ const demo = [].concat( ); module.exports = { + fix: fixJs, + fixIE: fixIEJs, + lodash: lodashJs, + font: basicAttachmentMap.font, bundle: uniq(bundle), bundleIE: uniq(bundleIE), bundleWithoutNormalize: uniq(bundleWithoutNormalize), diff --git a/webpack/dirs.js b/webpack/dirs.js index b5956fa6c..8b08748dd 100644 --- a/webpack/dirs.js +++ b/webpack/dirs.js @@ -6,4 +6,11 @@ module.exports = { BABEL_CONFIG: path.resolve(__dirname, "../babel.config.js"), IE8_BABEL_CONFIG: path.resolve(__dirname, "../babel.config.ie8.js"), TYPESCRIPT: path.resolve(__dirname, "../typescript"), + SRC: path.resolve(__dirname, "../src"), + DEMO: path.resolve(__dirname, "../demo"), + PUBLIC: path.resolve(__dirname, "../public"), + I18N: path.resolve(__dirname, "../i18n"), + UI: path.resolve(__dirname, "../ui"), + MOBILE: path.resolve(__dirname, "../_mobile"), + FIX: path.resolve(__dirname, "../dist/fix"), }; diff --git a/webpack/webpack.common.js b/webpack/webpack.common.js index ae28c016e..c07421c1e 100644 --- a/webpack/webpack.common.js +++ b/webpack/webpack.common.js @@ -1,5 +1,6 @@ const MiniCssExtractPlugin = require("mini-css-extract-plugin"); const autoprefixer = require("autoprefixer"); +const path = require("path"); const dirs = require("./dirs"); @@ -22,7 +23,7 @@ module.exports = { { test: /\.(js|ts)$/, include: [dirs.NODE_MODULES, dirs.PRIVATE, dirs.TYPESCRIPT], - exclude: /(node_modules(\/|\\)core-js|\.\/demo|\.\/src|\.\/public|\.\/i18n|\.\/ui|\.\/_mobile|\.dist).+\.js$/, + exclude: /node_modules(\/|\\)core-js/, use: [{ loader: "babel-loader", options: { @@ -35,6 +36,49 @@ module.exports = { }, }], }, + { + test: /\.js$/, + include: [ + dirs.DEMO, + dirs.SRC, + dirs.PUBLIC, + dirs.MOBILE, + dirs.I18N, + dirs.UI, + dirs.FIX, + ], + use: [ + { + loader: "source-map-loader", + options: { + enforce: "pre", + }, + }, + ], + }, + { + test: /\.js$/, + include: [path.resolve(__dirname, '../', attachments.lodash)], + use: [ + { + loader: "script-loader", + }, + ], + }, + { + test: path.resolve(__dirname, '../', attachments.fix), + use: [{ + loader: 'expose-loader', + options: 'Fix', + }], + }, + { + test: path.resolve(__dirname, '../', attachments.fixIE), + use: [{ + loader: 'expose-loader', + options: 'Fix', + }], + }, { test: /\.(css|less)$/, use: [ diff --git a/webpack/webpack.prod.js b/webpack/webpack.prod.js index 7fe2f07c4..1ba7652e5 100644 --- a/webpack/webpack.prod.js +++ b/webpack/webpack.prod.js @@ -14,17 +14,23 @@ const attachments = require("./attachments"); module.exports = merge.smart(common, { mode: "production", entry: { - 'bundle.min': attachments.bundle, - 'bundle_without_normalize': attachments.bundleWithoutNormalize, + font: attachments.font, fineui: attachments.fineui, - 'fineui_without_jquery_polyfill': attachments.fineuiWithoutJqueryAndPolyfillJs, + "fineui.min": attachments.fineui, + "fineui.ie.min": attachments.fineuiIE, utils: attachments.utils, - 'bundle.ie': attachments.bundleIE, - 'fineui.ie': attachments.fineuiIE, + "utils.min": attachments.utils, + "bundle.min": attachments.bundle, + "fineui_without_jquery_polyfill": attachments.fineuiWithoutJqueryAndPolyfillJs, + "2.0/fineui.ie.min": attachments.bundleIE, + "2.0/fineui": attachments.bundle, + "2.0/fineui.min": attachments.bundle, + '2.0/fineui_without_normalize': attachments.bundleWithoutNormalize, }, optimization: { minimizer: [ new UglifyJsPlugin({ + include: /\.min/, parallel: true, sourceMap: true, uglifyOptions: {