提交 0855a7e3 编写于 作者: W wangmengjun

Merge branch '1.0.6-wmj' into '1.0.6'

1.0.6 wmj

See merge request cml/new-open-chameleon-sets!174
......@@ -44,6 +44,10 @@ cml.config.merge({
publicPath: `${publicPath}/wx/`,
apiPrefix
}
},
optimize: {
watchNodeModules: true, // 设置为true对于调试 node_modules 里面的内容很有帮助
showWarning: true// 设置为true可以在构建过程中看到警告信息,比如编译过程中引入了同一个npm包的不同版本会在终端输出信息
}
})
......@@ -1181,6 +1181,10 @@ _.getCmlFileType = function(cmlFilePath, context, cmlType) {
});
let subProjectIndex = -1;
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])) {
subProjectIndex = i;
break;
......
......@@ -18,6 +18,7 @@ const http = require('http');
const bodyParser = require('body-parser')
const argv = require('minimist')(process.argv);
const nopreview = argv.nopreview || argv.n;
const {createProxyMiddleware} = require('http-proxy-middleware');
/**
* webpackConfig webpack的配置对象
......@@ -31,11 +32,20 @@ module.exports = function({webpackConfig, options, compiler}) {
var port = utils.getFreePort().webServerPort;
var autoOpenBrowser = true;
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.text({ type: 'text/html' }))
app.use(responseTime());
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 (options.hot === true) {
......
......@@ -13,7 +13,7 @@ const ChameleonErrorsWebpackPlugin = require('chameleon-errors-webpack-plugin');
const fs = require('fs');
const cmlUtils = require('chameleon-tool-utils');
const ExtraWatchWebpackPlugin = require('extra-watch-webpack-plugin');
// const DuplicatePackageCheckerPlugin = require('duplicate-package-checker-webpack-plugin');
const DuplicatePackageCheckerPlugin = require('duplicate-package-checker-webpack-plugin');
module.exports = function (options) {
let {
......@@ -46,7 +46,7 @@ module.exports = function (options) {
if (!publicPath) {
publicPath = `http://${config.ip}:${webServerPort}/${type}/`
}
let chameleonConfig = cml.config.get();
let commonConfig = {
stats: cml.logLevel === 'debug' ? 'verbose' : 'none',
output: {
......@@ -144,7 +144,7 @@ module.exports = function (options) {
options: {
cmlType: type,
media,
check: cml.config.get().check
check: chameleonConfig.check
}
}
]
......@@ -158,11 +158,12 @@ module.exports = function (options) {
'process.env.platform': JSON.stringify(type)
}),
new ChameleonErrorsWebpackPlugin({
cmlType: type
cmlType: type,
showWarning: chameleonConfig.optimize && chameleonConfig.optimize.showWarning
})
]
}
if (cml.config.get().enableGlobalCheck === true) {
if (chameleonConfig.enableGlobalCheck === true) {
commonConfig.plugins.push(
new WebpackCheckPlugin({
cmlType: type,
......@@ -204,11 +205,11 @@ module.exports = function (options) {
dirs: [path.join(cml.projectRoot, 'mock/api')]
})
);
// commonConfig.plugins.push(
// new DuplicatePackageCheckerPlugin({
// verbose: true
// })
// );
commonConfig.plugins.push(
new DuplicatePackageCheckerPlugin({
verbose: true
})
);
}
// 兼容旧版api
commonConfig.plugins.push(new webpack.DefinePlugin({
......@@ -230,7 +231,11 @@ module.exports = function (options) {
assetNameRegExp: /\.css$/,
cssProcessorOptions: { safe: true, discardComments: { removeAll: true }, autoprefixer: false }
}),
new UglifyJsPlugin({})
new UglifyJsPlugin({
compress: {
drop_console: true
}
})
])
}
......@@ -245,7 +250,7 @@ module.exports = function (options) {
}
let subProject = cml.config.get().subProject;
let subProject = chameleonConfig.subProject;
if (subProject && subProject.length > 0) {
subProject.forEach(item => {
let npmName = cmlUtils.isString(item) ? item : item.npmName;
......
......@@ -175,7 +175,8 @@ var chameleonConfig = {
}
},
optimize: {
watchNodeModules: false// 默认不对node_modules中的文件进行watch,提升编译性能
watchNodeModules: false, // 默认不对node_modules中的文件进行watch,提升编译性能
showWarning: false// 为了兼容原来的配置,默认不开启构建过程中的警告信息,开启之后配合,DuplicatePackageCheckerPlugin 可以在构建过程中检查是否有重复npm包引入
}
}
......
......@@ -71,6 +71,7 @@
"glob-watcher": "^5.0.3",
"html-loader": "0.5.5",
"html-webpack-plugin": "2.30.1",
"http-proxy-middleware": "^1.0.4",
"inquirer": "6.0.0",
"interface-loader": "^1.0.6-alpha.5",
"ip": "1.1.5",
......
const check = require('./lib/check.js');
const chalk = require('chalk');
const IS_WIN = process.platform.indexOf('win') === 0
class WebpackCheckPlugin {
constructor(options) {
this.options = Object.assign({
......@@ -24,8 +24,13 @@ class WebpackCheckPlugin {
var type = options.cmlType;
compilation.modules.forEach(module => {
// 项目内的文件做校验
if (module.resource && module.resource.indexOf(cml.projectRoot) === 0) {
// 项目内的文件做校验 并且 对于路径包括chameleon-tool的不进行校验,因为cli可能会被安装在项目内部
let cliName = 'chameleon-tool';// 内网的会被替换成 @didi/chameleon-cli 注意windows下的兼容
if (IS_WIN) {
cliName = cliName.replace(/\//g, '\\')
}
let inChameleonTool = module.resource && module.resource.includes(cliName)
if (module.resource && module.resource.indexOf(cml.projectRoot) === 0 && !inChameleonTool) {
// 白名单内的文件不做校验
let whiteListFileLength = options.whiteListFile.length;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册