Skip to content

Commit

Permalink
chore: ice-scripts/release-2.1.7 (#33)
Browse files Browse the repository at this point in the history
ice-scripts/release-2.1.7
  • Loading branch information
imsobear authored Aug 8, 2019
2 parents 0935422 + 98841e5 commit 308354f
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 47 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 8 additions & 4 deletions packages/ice-plugin-css-assets-local/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# Changelog

## 0.1.1
## 0.1.2

- [fix] 兼容 options 为空的情况
- [feat] 支持 dev 命令下下载 css 资源

## 0.1.0
## 0.1.1

- [feat] 完成初始版本基础功能
- [fix] 兼容 options 为空的情况

## 0.1.0

- [feat] 完成初始版本基础功能
11 changes: 6 additions & 5 deletions packages/ice-plugin-css-assets-local/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '../',
}]);
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ice-plugin-css-assets-local/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions packages/ice-scripts/lib/config/jest/shim.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import 'core-js/stable';
import 'regenerator-runtime/runtime';
require('core-js/stable');
require('regenerator-runtime/runtime');
26 changes: 24 additions & 2 deletions packages/ice-scripts/lib/config/processEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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 });
};
18 changes: 4 additions & 14 deletions packages/ice-scripts/lib/core/Context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -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'));
}
});
};
2 changes: 1 addition & 1 deletion packages/ice-scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ice-scripts",
"version": "2.1.6",
"version": "2.1.7",
"description": "ICE SDK",
"main": "index.js",
"bin": {
Expand Down

0 comments on commit 308354f

Please sign in to comment.