From 61cb60149cdb236c159c36474b01a636312e1adc Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Mon, 5 Aug 2019 19:46:13 +0800 Subject: [PATCH 1/5] fix: require shim modules --- packages/ice-scripts/lib/config/jest/shim.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ice-scripts/lib/config/jest/shim.js b/packages/ice-scripts/lib/config/jest/shim.js index 7629ad5..8914681 100644 --- a/packages/ice-scripts/lib/config/jest/shim.js +++ b/packages/ice-scripts/lib/config/jest/shim.js @@ -1,2 +1,2 @@ -import 'core-js/stable'; -import 'regenerator-runtime/runtime'; \ No newline at end of file +require('core-js/stable'); +require('regenerator-runtime/runtime'); \ No newline at end of file From 7ff96e9dd5bad742d9496db8e21c3fa860518e33 Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Tue, 6 Aug 2019 14:14:37 +0800 Subject: [PATCH 2/5] chore: version --- packages/ice-scripts/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ice-scripts/package.json b/packages/ice-scripts/package.json index 63d04e4..e9af724 100644 --- a/packages/ice-scripts/package.json +++ b/packages/ice-scripts/package.json @@ -1,6 +1,6 @@ { "name": "ice-scripts", - "version": "2.1.6", + "version": "2.1.7", "description": "ICE SDK", "main": "index.js", "bin": { From bbdc8879e4612f4f47340bb612614b20834b4bd1 Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Thu, 8 Aug 2019 14:33:41 +0800 Subject: [PATCH 3/5] fix: add polyfill after chainable webpack has been executed (#34) * fix: add polyfill after chainable webpack has been executed * fix: use break to stop loop --- .../ice-scripts/lib/config/processEntry.js | 26 +++++++++++++++++-- packages/ice-scripts/lib/core/Context.js | 18 +++---------- .../plugins/userConfig/configs/injectBabel.js | 19 +------------- .../userConfig => }/utils/polyfillLoader.js | 0 4 files changed, 29 insertions(+), 34 deletions(-) rename packages/ice-scripts/lib/{plugins/userConfig => }/utils/polyfillLoader.js (100%) diff --git a/packages/ice-scripts/lib/config/processEntry.js b/packages/ice-scripts/lib/config/processEntry.js index 04d4787..dafaa38 100644 --- a/packages/ice-scripts/lib/config/processEntry.js +++ b/packages/ice-scripts/lib/config/processEntry.js @@ -34,7 +34,8 @@ function enhanceEntries(entries, chunk) { return hotEntries; } -module.exports = (entry, options = {}) => { +module.exports = (config, options = {}) => { + const entry = config.toConfig().entry; // 需要区分项目类型,新版的项目直接返回 src/index.js let entries = {}; if (Array.isArray(entry) || typeof entry === 'string') { @@ -46,10 +47,31 @@ module.exports = (entry, options = {}) => { entries[key] = entryWithApp(entry[key]); }); } + if (options.polyfill) { + const rule = config.module.rule('polyfill').test(/\.jsx?|\.tsx?$/); + Object.keys(entries).forEach((key) => { + // only include entry path + for (let i = 0; i < entries[key].length; i += 1) { + // filter node_modules file add by plugin + if (!/node_modules/.test(entries[key][i])) { + rule.include.add(entries[key][i]); + break; + } + } + }); + rule.use('polyfill-loader').loader(require.resolve('../utils/polyfillLoader')).options({}); + + // add resolve modules for get core-js and regenerator-runtime + const modulePath = require.resolve('core-js'); + const pathArr = modulePath.split('node_modules'); + pathArr.pop(); // pop file path + config.resolve.modules.add(path.join(pathArr.join('node_modules'), 'node_modules')); + } if (options.hotDev) { entries = enhanceEntries(entries, hotDevClientPath); } - return entries; + config.entryPoints.clear(); + config.merge({ entry: entries }); }; diff --git a/packages/ice-scripts/lib/core/Context.js b/packages/ice-scripts/lib/core/Context.js index dca2b95..7f05f67 100644 --- a/packages/ice-scripts/lib/core/Context.js +++ b/packages/ice-scripts/lib/core/Context.js @@ -89,19 +89,6 @@ module.exports = class Context { } } - // process entry - processWepackEntry(config) { - const entry = config.toConfig().entry; - if (entry) { - // delete origin entry - config.entryPoints.clear(); - // merge new entry - config.merge({ entry: processEntry(entry, { - hotDev: this.command === 'dev' && !this.commandArgs.disabledReload, - }) }); - } - } - async applyHook(key, opts = {}) { const hooks = this.eventHooks[key] || []; const results = []; @@ -140,7 +127,10 @@ module.exports = class Context { } } // add polyfill/hotdev before origin entry - this.processWepackEntry(config); + processEntry(config, { + hotDev: this.command === 'dev' && !this.commandArgs.disabledReload, + polyfill: this.userConfig.injectBabel === 'polyfill', + }); return config.toConfig(); } diff --git a/packages/ice-scripts/lib/plugins/userConfig/configs/injectBabel.js b/packages/ice-scripts/lib/plugins/userConfig/configs/injectBabel.js index 8e88521..e0dae4b 100644 --- a/packages/ice-scripts/lib/plugins/userConfig/configs/injectBabel.js +++ b/packages/ice-scripts/lib/plugins/userConfig/configs/injectBabel.js @@ -1,6 +1,4 @@ -const path = require('path'); - -module.exports = ({ chainWebpack, context }, injectBabel) => { +module.exports = ({ chainWebpack }, injectBabel) => { chainWebpack((config) => { if (injectBabel === 'runtime') { ['jsx', 'tsx'].forEach((rule) => { @@ -26,21 +24,6 @@ module.exports = ({ chainWebpack, context }, injectBabel) => { return Object.assign(options, { plugins }); }); }); - } else if (injectBabel === 'polyfill') { - const { rootDir } = context; - const entries = config.toConfig().entry; - const rule = config.module.rule('polyfill').test(/\.jsx?|\.tsx?$/); - Object.keys(entries).forEach((key) => { - // only include entry path - rule.include.add(path.resolve(rootDir, entries[key][0])); - }); - rule.use('polyfill-loader').loader(require.resolve('../utils/polyfillLoader')).options({}); - - // add resolve modules for get core-js and regenerator-runtime - const modulePath = require.resolve('core-js'); - const pathArr = modulePath.split('node_modules'); - pathArr.pop(); // pop file path - config.resolve.modules.add(path.join(pathArr.join('node_modules'), 'node_modules')); } }); }; diff --git a/packages/ice-scripts/lib/plugins/userConfig/utils/polyfillLoader.js b/packages/ice-scripts/lib/utils/polyfillLoader.js similarity index 100% rename from packages/ice-scripts/lib/plugins/userConfig/utils/polyfillLoader.js rename to packages/ice-scripts/lib/utils/polyfillLoader.js From f8007a7b8a33c339622b61163b4ab4660f139c99 Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Thu, 8 Aug 2019 14:34:27 +0800 Subject: [PATCH 4/5] feat: support css localize in dev mode (#38) * feat: support css localize in dev mode * chore: version --- packages/ice-plugin-css-assets-local/CHANGELOG.md | 12 ++++++++---- packages/ice-plugin-css-assets-local/index.js | 11 ++++++----- packages/ice-plugin-css-assets-local/package.json | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/ice-plugin-css-assets-local/CHANGELOG.md b/packages/ice-plugin-css-assets-local/CHANGELOG.md index 3fd0c43..316efe8 100644 --- a/packages/ice-plugin-css-assets-local/CHANGELOG.md +++ b/packages/ice-plugin-css-assets-local/CHANGELOG.md @@ -1,9 +1,13 @@ # Changelog - ## 0.1.1 +## 0.1.2 - - [fix] 兼容 options 为空的情况 +- [feat] 支持 dev 命令下下载 css 资源 - ## 0.1.0 +## 0.1.1 - - [feat] 完成初始版本基础功能 \ No newline at end of file +- [fix] 兼容 options 为空的情况 + +## 0.1.0 + +- [feat] 完成初始版本基础功能 \ No newline at end of file diff --git a/packages/ice-plugin-css-assets-local/index.js b/packages/ice-plugin-css-assets-local/index.js index 966f06c..1ebd580 100644 --- a/packages/ice-plugin-css-assets-local/index.js +++ b/packages/ice-plugin-css-assets-local/index.js @@ -2,17 +2,18 @@ const ExtractCssAssetsWebpackPlugin = require('extract-css-assets-webpack-plugin module.exports = ({ context, log, chainWebpack }, options = {}) => { const { command } = context; - - // it is increase dev build time - if (command === 'build') { + const { outputPath, relativeCssPath, activeInDev } = options; + // it is increase dev build time by set default activeCommands ['build'] + const activeCommands = activeInDev ? ['dev', 'build'] : ['build']; + if (activeCommands.indexOf(command) > -1) { log.info('离线化构建项目,自动下载网络资源,请耐心等待'); chainWebpack((config) => { // TODO: set publicPath config.plugin('ExtractCssAssetsWebpackPlugin') .use(ExtractCssAssetsWebpackPlugin, [{ - outputPath: options.outputPath || 'assets', - relativeCssPath: options.relativeCssPath || '../', + outputPath: outputPath || 'assets', + relativeCssPath: relativeCssPath || '../', }]); }); } diff --git a/packages/ice-plugin-css-assets-local/package.json b/packages/ice-plugin-css-assets-local/package.json index bd4fd73..5ce492c 100644 --- a/packages/ice-plugin-css-assets-local/package.json +++ b/packages/ice-plugin-css-assets-local/package.json @@ -1,6 +1,6 @@ { "name": "ice-plugin-css-assets-local", - "version": "0.1.1", + "version": "0.1.2", "description": "ice-scripts plugin for localize CSS assets", "main": "index.js", "scripts": { From 98841e5b75455af54c721bc0c314670fc16d27c3 Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Thu, 8 Aug 2019 16:10:06 +0800 Subject: [PATCH 5/5] chore: changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 993f544..5cba634 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 2.1.7 + +- [fix] add polyfill when entry modified by plugin +- [fix] require modules in shim file +- [feat] support css localize in dev mode + ## 2.1.6 - [fix] remove check latest version of ice-scripts alibaba/ice#2517