未验证 提交 e806c8f0 编写于 作者: B beatles-chameleon 提交者: GitHub

Revert "1.0.6 merge"

上级 77c945ec
...@@ -67,6 +67,7 @@ typings/ ...@@ -67,6 +67,7 @@ typings/
# dotenv environment variables file # dotenv environment variables file
.env .env
package-lock.json
coverage coverage
.nyc_output .nyc_output
# /////////////////////////// # ///////////////////////////
......
## [1.0.6]
* web端动态加载支持自定义chunk名称
* 修复小程序端原生tabbar图标配置在windows上的Bug
## [1.0.6-alpha.6]
* web端 dev模式下如何支持跨域
* 构建过程警告信息支持配置是否输出,可以排查重复npm包的安装
* 压缩构建过程删除console
* windows下 subProject 配置npmName的路径适配修复
* 修复项目内安装cli通过npm脚本构建全局变量校验问题
## [1.0.6-alpha.5]
* 增加运行环境获取命令 cml info
* 提供构建进程和面板,优化开发体验
* 更新初始化项目依赖版本
* 支持weex多bundle构建自定义name
## [1.0.6-alpha.3]
* 初始化项目paltform默认值['web','weex','wx']三端
* 支持weex多bundle构建
## [1.0.6-alpha.2]
* 支付宝小程序编译组件包裹层id上移
* web、weex端router.config.json的编译方式增加name字段进行区分
## [1.0.6-alpha.1]
* 升级less编译器
* 支持原生组件样式引入对应平台样式文件不带后缀
* 支持路由多平台配置
## [1.0.5] ## [1.0.5]
* 发布支持头条和小程序增强相关能力的正式版本 发布支持头条和小程序增强相关能力的正式版本
* 预览页面改版,支持预览页面搜索能力 预览页面改版,支持预览页面搜索能力
## [1.0.5-alpha.2] ## [1.0.5-alpha.2]
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"packages": [ "packages": [
"packages/*" "packages/*"
], ],
"version": "1.0.6", "version": "1.0.5",
"command": { "command": {
"publish": { "publish": {
"allowBranch": "master", "allowBranch": "master",
......
此差异已折叠。
{ {
"name": "babel-plugin-chameleon-import", "name": "babel-plugin-chameleon-import",
"version": "1.0.6", "version": "1.0.5",
"description": "Component modular import plugin for babel.", "description": "Component modular import plugin for babel.",
"repository": { "repository": {
"type": "git", "type": "git",
......
{ {
"name": "chameleon-css-loader", "name": "chameleon-css-loader",
"version": "1.0.6", "version": "1.0.5",
"description": "chameleon样式处理", "description": "chameleon样式处理",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
}, },
"devDependencies": { "devDependencies": {
"chai": "^4.2.0", "chai": "^4.2.0",
"chameleon-tool-utils": "1.0.6", "chameleon-tool-utils": "1.0.5",
"coveralls": "^2.11.9", "coveralls": "^2.11.9",
"eslint": "^5.9.0", "eslint": "^5.9.0",
"gulp": "^3.9.1", "gulp": "^3.9.1",
......
{ {
"name": "chameleon-dev-proxy", "name": "chameleon-dev-proxy",
"version": "1.0.6", "version": "1.0.5",
"description": "cml开发环境代理服务模块", "description": "cml开发环境代理服务模块",
"main": "index.js", "main": "index.js",
"author": "Chameleon-Team", "author": "Chameleon-Team",
......
{ {
"version": "1.0.6", "version": "1.0.5",
"name": "chameleon-errors-webpack-plugin", "name": "chameleon-errors-webpack-plugin",
"main": "index.js", "main": "index.js",
"author": "Chameleon-Team", "author": "Chameleon-Team",
......
此差异已折叠。
{ {
"name": "chameleon-linter", "name": "chameleon-linter",
"version": "1.0.6", "version": "1.0.5",
"description": "cml规范校验工具", "description": "cml规范校验工具",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
...@@ -24,10 +24,10 @@ ...@@ -24,10 +24,10 @@
"@babel/traverse": "^7.1.4", "@babel/traverse": "^7.1.4",
"bulk-require": "^1.0.1", "bulk-require": "^1.0.1",
"chalk": "^2.4.1", "chalk": "^2.4.1",
"chameleon-tool-utils": "1.0.6", "chameleon-tool-utils": "1.0.5",
"cml-component-parser": "1.0.6", "cml-component-parser": "1.0.5",
"cml-htmllint": "1.0.6", "cml-htmllint": "1.0.5",
"cml-js-parser": "1.0.6", "cml-js-parser": "1.0.5",
"commander": "^2.19.0", "commander": "^2.19.0",
"glob": "^7.1.3", "glob": "^7.1.3",
"json-lint": "^0.1.0", "json-lint": "^0.1.0",
......
此差异已折叠。
{ {
"name": "chameleon-loader", "name": "chameleon-loader",
"version": "1.0.6", "version": "1.0.5",
"description": "chameleon cml文件处理loader", "description": "chameleon cml文件处理loader",
"main": "src/index.js", "main": "src/index.js",
"directories": { "directories": {
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
"@babel/types": "^7.3.4", "@babel/types": "^7.3.4",
"babel-generator": "6.26.1", "babel-generator": "6.26.1",
"babel-traverse": "6.26.0", "babel-traverse": "6.26.0",
"chameleon-template-parse": "1.0.6", "chameleon-template-parse": "1.0.5",
"chameleon-tool-utils": "1.0.6", "chameleon-tool-utils": "1.0.5",
"consolidate": "0.14.0", "consolidate": "0.14.0",
"de-indent": "1.0.2", "de-indent": "1.0.2",
"fs-extra": "^7.0.1", "fs-extra": "^7.0.1",
...@@ -27,9 +27,9 @@ ...@@ -27,9 +27,9 @@
"he": "1.1.0", "he": "1.1.0",
"loader-utils": "1.1.0", "loader-utils": "1.1.0",
"lru-cache": "4.1.1", "lru-cache": "4.1.1",
"mvvm-interface-parser": "1.0.6", "mvvm-interface-parser": "1.0.5",
"resolve": "1.4.0", "resolve": "1.4.0",
"runtime-check": "1.0.6", "runtime-check": "1.0.5",
"source-map": "0.6.1", "source-map": "0.6.1",
"vue-style-loader": "4.0.1" "vue-style-loader": "4.0.1"
}, },
......
const postcss = require('postcss');
// 原生组件引用的样式 @import './xxx' 不带平台样式后缀,less会默认添加less导致无法识别需要人工处理
const handleCssSuffix = postcss.plugin('handleCssSuffix', function(options) {
let {ext} = options;
return function(css, result) {
css.walkAtRules('import', function (rule) {
let params = rule.params;// ./xxx 引用的样式文件路径
// 注意这里取到的值是带引号的,比如 "./xxx" './xxx' `./xxx`
params = params.replace(/"|'|`/g, '');
if (!params.endsWith(ext)) {
rule.params = `"${params}${ext}"`
}
});
};
})
module.exports = function(source, options = {}) {
return postcss([handleCssSuffix(options)]).process(source).css;
}
...@@ -4,7 +4,6 @@ const loaderUtils = require('loader-utils'); ...@@ -4,7 +4,6 @@ const loaderUtils = require('loader-utils');
const fs = require('fs'); const fs = require('fs');
const cmlUtils = require('chameleon-tool-utils'); const cmlUtils = require('chameleon-tool-utils');
const path = require('path'); const path = require('path');
const handlePlatformCss = require('./handle-platform-css.js');
module.exports = function(content) { module.exports = function(content) {
const self = this;// eslint-disable-line const self = this;// eslint-disable-line
...@@ -39,9 +38,7 @@ module.exports = function(content) { ...@@ -39,9 +38,7 @@ module.exports = function(content) {
module.exports = function(){\n module.exports = function(){\n
}` }`
} }
if (output) {
output = handlePlatformCss(output, {filePath: this.resourcePath, ext: styles})
}
return output; return output;
} }
...@@ -38,8 +38,6 @@ _.getTabbarIconPaths = function(tabbar, type) { ...@@ -38,8 +38,6 @@ _.getTabbarIconPaths = function(tabbar, type) {
iconInfo.finalPath = item.iconPath; iconInfo.finalPath = item.iconPath;
iconPaths.push(iconInfo); iconPaths.push(iconInfo);
// 生成的app.json中的路径要适配windows
item.iconPath = cmlUtils.handleWinPath(item.iconPath);
} }
if (item.selectedIconPath) { if (item.selectedIconPath) {
let iconInfo = {}; let iconInfo = {};
...@@ -48,8 +46,6 @@ _.getTabbarIconPaths = function(tabbar, type) { ...@@ -48,8 +46,6 @@ _.getTabbarIconPaths = function(tabbar, type) {
iconInfo.finalPath = item.selectedIconPath; iconInfo.finalPath = item.selectedIconPath;
iconPaths.push(iconInfo); iconPaths.push(iconInfo);
// 生成的app.json中的路径要适配windows
item.selectedIconPath = cmlUtils.handleWinPath(item.selectedIconPath);
} }
}) })
} }
...@@ -62,9 +58,6 @@ _.getTabbarIconPaths = function(tabbar, type) { ...@@ -62,9 +58,6 @@ _.getTabbarIconPaths = function(tabbar, type) {
iconInfo.finalPath = item.icon; iconInfo.finalPath = item.icon;
iconPaths.push(iconInfo); iconPaths.push(iconInfo);
// 生成的app.json中的路径要适配windows
item.icon = cmlUtils.handleWinPath(item.icon);
} }
if (item.activeIcon) { if (item.activeIcon) {
let iconInfo = {}; let iconInfo = {};
...@@ -73,9 +66,6 @@ _.getTabbarIconPaths = function(tabbar, type) { ...@@ -73,9 +66,6 @@ _.getTabbarIconPaths = function(tabbar, type) {
iconInfo.finalPath = item.activeIcon; iconInfo.finalPath = item.activeIcon;
iconPaths.push(iconInfo); iconPaths.push(iconInfo);
// 生成的app.json中的路径要适配windows
item.activeIcon = cmlUtils.handleWinPath(item.activeIcon);
} }
}) })
} }
......
{ {
"name": "chameleon-miniapp-target", "name": "chameleon-miniapp-target",
"version": "1.0.6", "version": "1.0.5",
"description": "chameleon 小程序webpack的target", "description": "chameleon 小程序webpack的target",
"main": "src/index.js", "main": "src/index.js",
"scripts": { "scripts": {
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
"webpack": "^3.12.0" "webpack": "^3.12.0"
}, },
"dependencies": { "dependencies": {
"chameleon-tool-utils": "1.0.6" "chameleon-tool-utils": "1.0.5"
}, },
"mail": "ChameleonCore@didiglobal.com", "mail": "ChameleonCore@didiglobal.com",
"gitHead": "5ddcde4330774710f7646559446e008f7785ce00" "gitHead": "5ddcde4330774710f7646559446e008f7785ce00"
......
此差异已折叠。
{ {
"name": "chameleon-mixins", "name": "chameleon-mixins",
"version": "1.0.6", "version": "1.0.5",
"description": "chameleon-mixins", "description": "chameleon-mixins",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
"license": "Apache", "license": "Apache",
"devDependencies": { "devDependencies": {
"chai": "^4.2.0", "chai": "^4.2.0",
"chameleon-css-loader": "1.0.6", "chameleon-css-loader": "1.0.5",
"coveralls": "^2.11.9", "coveralls": "^2.11.9",
"eslint": "^5.9.0", "eslint": "^5.9.0",
"gulp": "^3.9.1", "gulp": "^3.9.1",
......
{ {
"name": "chameleon-template-parse", "name": "chameleon-template-parse",
"version": "1.0.6", "version": "1.0.5",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
...@@ -24,9 +24,9 @@ ...@@ -24,9 +24,9 @@
}, },
"devDependencies": { "devDependencies": {
"chai": "^4.2.0", "chai": "^4.2.0",
"chameleon-css-loader": "1.0.6", "chameleon-css-loader": "1.0.5",
"chameleon-mixins": "1.0.6", "chameleon-mixins": "1.0.5",
"chameleon-tool-utils": "1.0.6", "chameleon-tool-utils": "1.0.5",
"clean-webpack-plugin": "^0.1.19", "clean-webpack-plugin": "^0.1.19",
"coveralls": "^2.11.9", "coveralls": "^2.11.9",
"eslint": "^5.9.0", "eslint": "^5.9.0",
......
...@@ -52,7 +52,7 @@ exports.preParseAliComponent = function(source, type, options) { ...@@ -52,7 +52,7 @@ exports.preParseAliComponent = function(source, type, options) {
// 先 push view标签,然后再push组件标签 // 先 push view标签,然后再push组件标签
let isComponent = usingComponents.find((comp) => comp.tagName === item.tagName) || Object.keys(buildInComponents).includes(item.tagName); let isComponent = usingComponents.find((comp) => comp.tagName === item.tagName) || Object.keys(buildInComponents).includes(item.tagName);
let inheritNodes = (item.attrs || []).filter((attr) => { let inheritNodes = (item.attrs || []).filter((attr) => {
let inheritAttrsFromComp = ['c-if', 'c-else', 'c-else-if', 'v-if', 'v-else', 'v-else-if', 'class', 'style', 'v-bind:style', 'v-bind:class', ':style', ':class', 'c-show', 'v-show', 'id']; let inheritAttrsFromComp = ['c-if', 'c-else', 'c-else-if', 'v-if', 'v-else', 'v-else-if', 'class', 'style', 'v-bind:style', 'v-bind:class', ':style', ':class', 'c-show', 'v-show'];
// eslint-disable-next-line // eslint-disable-next-line
let inheritEvent = ['c-bind:click', 'c-bind:tap', 'c-bind:touchstart', 'c-bind:touchmove', 'c-bind:touchend', 'c-bind:touchcancel', 'c-catch:click', 'c-catch:tap', 'c-catch:touchstart', 'c-catch:touchmove', 'c-catch:touchend', 'c-catch:touchcancel']; let inheritEvent = ['c-bind:click', 'c-bind:tap', 'c-bind:touchstart', 'c-bind:touchmove', 'c-bind:touchend', 'c-bind:touchcancel', 'c-catch:click', 'c-catch:tap', 'c-catch:touchstart', 'c-catch:touchmove', 'c-catch:touchend', 'c-catch:touchcancel'];
let isInherit = inheritAttrsFromComp.includes(attr[1]) || inheritEvent.includes(attr[1]) || /^data-/.test(attr[1]) let isInherit = inheritAttrsFromComp.includes(attr[1]) || inheritEvent.includes(attr[1]) || /^data-/.test(attr[1])
......
{ {
"name": "chameleon-templates", "name": "chameleon-templates",
"version": "1.0.6", "version": "1.0.5",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
......
...@@ -7,7 +7,7 @@ const apiPrefix = 'https://api.chameleon.com'; ...@@ -7,7 +7,7 @@ const apiPrefix = 'https://api.chameleon.com';
cml.config.merge({ cml.config.merge({
templateLang: 'cml', templateLang: 'cml',
templateType: 'html', templateType: 'html',
platforms: ['web', 'weex', 'wx'], platforms: ['web', 'weex', 'wx', 'baidu', 'alipay', 'qq'],
buildInfo: { buildInfo: {
wxAppId: '123456' wxAppId: '123456'
}, },
...@@ -21,33 +21,25 @@ cml.config.merge({ ...@@ -21,33 +21,25 @@ cml.config.merge({
web: { web: {
dev: { dev: {
analysis: false, analysis: false,
console: false, console: false
isWrapComponent: false // 取消默认对组件的包裹
}, },
build: { build: {
analysis: false, analysis: false,
publicPath: `${publicPath}/web/`, publicPath: `${publicPath}/web/`,
apiPrefix, apiPrefix
isWrapComponent: false // 取消默认对组件的包裹
} }
}, },
weex: { weex: {
dev: { dev: {
isWrapComponent: false // 取消默认对组件的包裹
}, },
build: { build: {
publicPath: `${publicPath}/weex/`, publicPath: `${publicPath}/weex/`,
apiPrefix, apiPrefix
isWrapComponent: false // 取消默认对组件的包裹
}, },
custom: { custom: {
publicPath: `${publicPath}/wx/`, publicPath: `${publicPath}/wx/`,
apiPrefix apiPrefix
} }
},
optimize: {
watchNodeModules: true, // 设置为true对于调试 node_modules 里面的内容很有帮助
showWarning: true// 设置为true可以在构建过程中看到警告信息,比如编译过程中引入了同一个npm包的不同版本会在终端输出信息
} }
}) })
...@@ -8,9 +8,9 @@ ...@@ -8,9 +8,9 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"chameleon-api": "1.0.0", "chameleon-api": "1.0.0",
"chameleon-runtime": "1.0.1", "chameleon-runtime": "1.0.0",
"chameleon-store": "1.0.1", "chameleon-store": "1.0.0",
"chameleon-ui-builtin": "1.0.6", "chameleon-ui-builtin": "1.0.0",
"cml-ui": "1.0.3" "cml-ui": "1.0.0"
} }
} }
...@@ -36,5 +36,5 @@ ...@@ -36,5 +36,5 @@
"test": "mocha --recursive --reporter spec", "test": "mocha --recursive --reporter spec",
"break-test": "./node_modules/.bin/mocha --inspect-brk --recursive --reporter spec" "break-test": "./node_modules/.bin/mocha --inspect-brk --recursive --reporter spec"
}, },
"version": "1.0.6" "version": "1.0.5"
} }
\ No newline at end of file
...@@ -323,10 +323,7 @@ _.getJsonFileContent = function (filePath, confType) { ...@@ -323,10 +323,7 @@ _.getJsonFileContent = function (filePath, confType) {
if (itemPath[0] === '/') { if (itemPath[0] === '/') {
itemPath = itemPath.slice(1); itemPath = itemPath.slice(1);
} }
let usedPlatforms = item.usedPlatforms; targetObject.pages.push(itemPath);
if(!usedPlatforms || (usedPlatforms && usedPlatforms.includes(confType))){
targetObject.pages.push(itemPath);
}
} }
}) })
} }
...@@ -1181,10 +1178,6 @@ _.getCmlFileType = function(cmlFilePath, context, cmlType) { ...@@ -1181,10 +1178,6 @@ _.getCmlFileType = function(cmlFilePath, context, cmlType) {
}); });
let subProjectIndex = -1; let subProjectIndex = -1;
for (let i = 0; i < npmNames.length; i++) { for (let i = 0; i < npmNames.length; i++) {
//比如 配置 npmName: '@didi/cml-login',在windows中药改成对应的分隔符
if (_.isWin()) { // 修复windows平台下将npm页面全部解析成component的问题
npmNames[i] = npmNames[i].replace(/\//g,'\\')
}
if (~cmlFilePath.indexOf(npmNames[i])) { if (~cmlFilePath.indexOf(npmNames[i])) {
subProjectIndex = i; subProjectIndex = i;
break; break;
......
const envinfo = require('envinfo');
exports.name = 'info';
exports.usage = '[command] [options]';
exports.desc = 'Shows information about the local environment';
/* istanbul ignore next */
exports.register = function (commander) {
commander
.action(function (...args) {
envinfo.run(
{
System: ['OS', 'CPU'],
Binaries: ['Node', 'Yarn', 'npm'],
Browsers: ['Chrome', 'Edge', 'Firefox', 'Safari'],
npmGlobalPackages: ['chameleon-tool'],
npmPackages: [
'chameleon-tool'
]
},
{
showNotFound: true,
duplicates: true,
fullTree: true
}
).then(console.log)
})
}
...@@ -10,7 +10,6 @@ const path = require('path'); ...@@ -10,7 +10,6 @@ const path = require('path');
const fs = require('fs'); const fs = require('fs');
const crypto = require('crypto'); const crypto = require('crypto');
const cmlUtils = require('chameleon-tool-utils'); const cmlUtils = require('chameleon-tool-utils');
const {getEntryName} = require('../configs/utils.js');
/** /**
* 非web端构建 * 非web端构建
...@@ -228,10 +227,16 @@ function startCmlLinter(media) { ...@@ -228,10 +227,16 @@ function startCmlLinter(media) {
}); });
} }
} }
exports.getMD5 = function(weexjs) {
if (!weexjs) { exports.createConfigJson = function() {
return ''; let configJsonPath = path.join(cml.projectRoot, 'dist/config.json');
let configObj = {};
if (cml.utils.isFile(configJsonPath)) {
configObj = JSON.parse(fs.readFileSync(configJsonPath, {encoding: 'utf-8'}))
} }
// 获取weex jsbundle地址
let weexjs = configObj.weexjs || '';
let md5str = '';
const weexjsName = weexjs.split('/').pop(); const weexjsName = weexjs.split('/').pop();
const weexjsPath = path.resolve(cml.projectRoot, 'dist/weex/', weexjsName); const weexjsPath = path.resolve(cml.projectRoot, 'dist/weex/', weexjsName);
...@@ -239,17 +244,8 @@ exports.getMD5 = function(weexjs) { ...@@ -239,17 +244,8 @@ exports.getMD5 = function(weexjs) {
const md5sum = crypto.createHash('md5'); const md5sum = crypto.createHash('md5');
const buffer = fs.readFileSync(weexjsPath); const buffer = fs.readFileSync(weexjsPath);
md5sum.update(buffer); md5sum.update(buffer);
let md5str = md5sum.digest('hex').toUpperCase(); md5str = md5sum.digest('hex').toUpperCase();
return md5str
} }
}
exports.createConfigJson = function() {
let configJsonPath = path.join(cml.projectRoot, 'dist/config.json');
let configObj = {};
if (cml.utils.isFile(configJsonPath)) {
configObj = JSON.parse(fs.readFileSync(configJsonPath, {encoding: 'utf-8'}))
}
// 获取weex jsbundle地址
let config = cml.config.get(); let config = cml.config.get();
config.buildInfo = config.buildInfo || {}; config.buildInfo = config.buildInfo || {};
...@@ -261,12 +257,6 @@ exports.createConfigJson = function() { ...@@ -261,12 +257,6 @@ exports.createConfigJson = function() {
extAppId = config.buildInfo && config.buildInfo[`${extCommand}AppId`] extAppId = config.buildInfo && config.buildInfo[`${extCommand}AppId`]
} }
let {routerConfig, hasError} = cml.utils.getRouterConfig(); let {routerConfig, hasError} = cml.utils.getRouterConfig();
let entryName = getEntryName();
let weexjs = (configObj.entryName && configObj.entryName.js) || '';
let md5str = exports.getMD5(weexjs);
let mpa = routerConfig.mpa;
if (hasError) { if (hasError) {
throw new Error('router.config.json格式不正确') throw new Error('router.config.json格式不正确')
} }
...@@ -277,17 +267,8 @@ exports.createConfigJson = function() { ...@@ -277,17 +267,8 @@ exports.createConfigJson = function() {
throw new Error('router.config.json 中未设置web端需要的domain字段'); throw new Error('router.config.json 中未设置web端需要的domain字段');
} }
let {domain, mode} = routerConfig; let {domain, mode} = routerConfig;
routerConfig.routes.forEach(item => { routerConfig.routes.forEach(item => {
// 如果配置了weex多页面,那么每个路由都要重新计算对应的weexjs
if (mpa && mpa.weexMpa && Array.isArray(mpa.weexMpa)) { // 配置了weex多页面
let weexMpa = mpa.weexMpa;
for (let i = 0; i < weexMpa.length ; i++) {
if (Array.isArray(weexMpa[i].paths) && weexMpa[i].paths.includes(item.path)) {
weexjs = configObj[`${entryName}${i}`] && configObj[`${entryName}${i}`].js;
md5str = exports.getMD5(weexjs);
}
}
}
let webUrl = domain; let webUrl = domain;
if (mode === 'history') { if (mode === 'history') {
webUrl += item.url; webUrl += item.url;
......
...@@ -8,7 +8,6 @@ var config = require('../../configs/config'); ...@@ -8,7 +8,6 @@ var config = require('../../configs/config');
var dynamicApiMiddleware = require('./dynamicApiMiddleware'); var dynamicApiMiddleware = require('./dynamicApiMiddleware');
var responseTime = require('./responseTime'); var responseTime = require('./responseTime');
const liveLoadMiddleware = require('webpack-liveload-middleware'); const liveLoadMiddleware = require('webpack-liveload-middleware');
const cmlUtils = require('chameleon-tool-utils');
const fse = require('fs-extra'); const fse = require('fs-extra');
const tpl = require('chameleon-templates'); const tpl = require('chameleon-templates');
const proxy = require('chameleon-dev-proxy'); const proxy = require('chameleon-dev-proxy');
...@@ -18,7 +17,6 @@ const http = require('http'); ...@@ -18,7 +17,6 @@ const http = require('http');
const bodyParser = require('body-parser') const bodyParser = require('body-parser')
const argv = require('minimist')(process.argv); const argv = require('minimist')(process.argv);
const nopreview = argv.nopreview || argv.n; const nopreview = argv.nopreview || argv.n;
const {createProxyMiddleware} = require('http-proxy-middleware');
/** /**
* webpackConfig webpack的配置对象 * webpackConfig webpack的配置对象
...@@ -32,20 +30,11 @@ module.exports = function({webpackConfig, options, compiler}) { ...@@ -32,20 +30,11 @@ module.exports = function({webpackConfig, options, compiler}) {
var port = utils.getFreePort().webServerPort; var port = utils.getFreePort().webServerPort;
var autoOpenBrowser = true; var autoOpenBrowser = true;
var app = express(); var app = express();
app.use(bodyParser.json()); app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.text({ type: 'text/html' })) app.use(bodyParser.text({ type: 'text/html' }))
app.use(responseTime()); app.use(responseTime());
dynamicApiMiddleware(app, options); dynamicApiMiddleware(app, options);
// web端增加跨域自定义配置
let devProxy = options && options.devProxy || [];
if (webpackConfig.name === 'web' && Array.isArray(devProxy)) {
devProxy.forEach((proxyConfig) => {
app.use(proxyConfig.path, createProxyMiddleware(proxyConfig.options))
})
}
if (compiler) { if (compiler) {
if (options.hot === true) { if (options.hot === true) {
...@@ -129,36 +118,8 @@ module.exports = function({webpackConfig, options, compiler}) { ...@@ -129,36 +118,8 @@ module.exports = function({webpackConfig, options, compiler}) {
} }
uri += 'preview.html'; uri += 'preview.html';
var entry = utils.getEntryName(); var entry = utils.getEntryName();
const {routerConfig} = cmlUtils.getRouterConfig(); var jsbundle = `weex/${entry}.js`;
let mpa = routerConfig.mpa; let staticParams = { jsbundle, subpath, buildType: cml.activePlatform };
let weexBundles = [];
if (mpa && mpa.weexMpa && Array.isArray(mpa.weexMpa)) { // 配置了weex多页面
let weexMpa = mpa.weexMpa;
for (let i = 0; i < weexMpa.length ; i++) {
if (typeof weexMpa[i].name === 'string') {
weexBundles.push({
bundle: `weex/${weexMpa[i].name}.js`,
paths: weexMpa[i].paths
})
} else {
weexBundles.push({
bundle: `weex/${entry}${i}.js`,
paths: weexMpa[i].paths
})
}
}
} else { // 兼容原来的没有配置的情况
let allPaths = routerConfig.routes.reduce((result, current) => {
result.push(current.path);
return result;
}, [])
weexBundles.push({
bundle: `weex/${entry}.js`,
paths: allPaths
})
}
// var jsbundle = `weex/${entry}.js`;
let staticParams = { weexBundles, subpath, buildType: cml.activePlatform };
createRoutesReact({server, staticParams}); createRoutesReact({server, staticParams});
cml.log.notice('Listening at ' + uri); cml.log.notice('Listening at ' + uri);
......
...@@ -38,11 +38,7 @@ exports.initRouter = function initRouter() { ...@@ -38,11 +38,7 @@ exports.initRouter = function initRouter() {
exports.getRouteConfig = function getRouteConfig() { exports.getRouteConfig = function getRouteConfig() {
let {routerConfig, hasError} = cml.utils.getRouterConfig(); let {routerConfig, hasError} = cml.utils.getRouterConfig();
if (!hasError) { if (!hasError) {
routerConfig.routes = routerConfig.routes.filter((item) => { routerConfig = Object.assign(routerConfig, staticParams);// {jsbundle,subpath}
let usedPlatforms = item.usedPlatforms;
return (!usedPlatforms || (usedPlatforms && usedPlatforms.includes('web')) || (usedPlatforms && usedPlatforms.includes('weex')))
})
routerConfig = Object.assign(routerConfig, staticParams);// {weexBundles,subpath}
return JSON.stringify(routerConfig); return JSON.stringify(routerConfig);
} }
} }
......
/*
将 import router from '$ROUTER 转化为
import router from '$ROUTER?query=0'; //'$ROUTER?query=1'之类的
转化比较简单,可以用正则,该文件源文件在 configs/default/entry.js 中
*/
module.exports = function(content) {
this.cacheable(false);
const resourceQuery = this.resourceQuery
return content.replace('$ROUTER', `$ROUTER${resourceQuery}`)
}
...@@ -56,12 +56,10 @@ module.exports = function (options) { ...@@ -56,12 +56,10 @@ module.exports = function (options) {
] ]
var commonConfig = var commonConfig =
{ {
name: 'web',
context: path.resolve(root), context: path.resolve(root),
entry, entry,
output: { output: {
filename: getJsPath(), filename: getJsPath()
chunkFilename: getJsPath()
}, },
resolve: { resolve: {
alias: { alias: {
......
...@@ -19,7 +19,16 @@ module.exports = function (options) { ...@@ -19,7 +19,16 @@ module.exports = function (options) {
plugins: [ plugins: [
new CleanWebpackPlugin(['./*'], {root: outputPath, verbose: false}), new CleanWebpackPlugin(['./*'], {root: outputPath, verbose: false}),
new AssetsPlugin({ new AssetsPlugin({
filename: '/dist/config.json' filename: '/dist/config.json',
processOutput: function (assets) {
let config = cml.config.get();
let weexjs = assets[config.projectName].js;
return JSON.stringify({
weexjs
}, '', 4);
}
}) })
] ]
} }
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册