提交 f6f5f508 编写于 作者: Y yylgit

cmlType multi

上级 5f0b7989
......@@ -838,7 +838,7 @@ _.findPolymorphicComponent = function(interfacePath, content, cmlType) {
}
let targetScript = null;
for (let i = 0;i < parts.script.length;i++) {
if (parts.script[i].cmlType === cmlType) {
if (~parts.script[i].cmlType.split(',').indexOf(cmlType)) {
targetScript = parts.script[i];
}
}
......
......@@ -3,8 +3,17 @@ const path = require('path');
const getCommonConfig = require('../getCommonConfig');
const utils = require('../utils.js');
const {MvvmGraphPlugin} = require('mvvm-pack');
module.exports = function(options) {
let {type, media} = options;
let npmName = cml.config.get().extPlatform[type];
let PlatformPlugin = require(path.join(cml.projectRoot, 'node_modules', npmName)); // eslint-disable-line
// 用户端扩展插件
let platformPlugin = new PlatformPlugin({
cmlType: type,
media
});
let extendConfig = {
entry: {
app: path.join(cml.projectRoot, 'src/app/app.cml')
......@@ -33,7 +42,7 @@ module.exports = function(options) {
new MvvmGraphPlugin({
cmlType: type,
media
})
}, platformPlugin)
]
};
// options.moduleIdType = 'hash';
......@@ -44,6 +53,16 @@ module.exports = function(options) {
item.options.publicPath = commonConfig.output.publicPath
}
})
// 用户可以扩展webpack的rules用于处理特有文件后缀
if (platformPlugin.webpackRules && platformPlugin.webpackRules instanceof Array) {
extendConfig = merge(extendConfig, {
module: {
rules: platformPlugin.webpackRules
}
})
}
return merge(commonConfig, extendConfig);
}
\ No newline at end of file
const cmlUtils = require('chameleon-tool-utils');
const fs = require('fs');
const path = require('path');
module.exports = function({interfacePath, content}) {
......
const cmlUtils = require('chameleon-tool-utils');
const fs = require('fs');
const path = require('path');
const {resolveRequire} = require('./resolveRequire.js');
......@@ -25,7 +24,7 @@ module.exports = function({interfacePath, content, cmlType, resolve}) {
}
let methodScript = null;
for (let i = 0;i < parts.script.length;i++) {
if (parts.script[i].cmlType === cmlType) {
if (~parts.script[i].cmlType.split(',').indexOf(cmlType)) {
methodScript = parts.script[i];
}
}
......
......@@ -2,17 +2,17 @@ class CMLNode {
constructor(options = {}) {
this.ext;
this.realPath; // 文件物理地址
this.nodeType; // App/Page/Component/Module // 节点类型 CML文件分为App/Page/Component 其他的为Module CML文件中的每一个部分也是一个Node节点
this.moduleType; // template/style/script/json/asset CML为CML文件
this.dependencies = []; // 该节点的直接依赖编译及诶点 app.cml依赖pages.cml pages.cml依赖components.cml js依赖js cmss依赖cmss
this.childrens = []; // 子模块 CML才有子模块
this.parent; // 父模块 CML文件中的子模块才有
this.nodeType; // app/page/component/module // 节点类型 app/page/component 其他的为module cml文件中的每一个部分也是一个Node节点
this.moduleType; // template/style/script/json/asset
this.dependencies = []; // 该节点的直接依赖 app.cml依赖pages.cml pages.cml依赖components.cml js依赖js
this.childrens = []; // 子模块 cml文件才有子模块
this.parent; // 父模块 cml文件中的子模块才有
this.source; // 模块源代码
this.convert; // AST JSON
this.convert; // 源代码的格式化形式
this.output; // 模块输出 各种过程操作该字段
this.identifier; // 节点唯一标识
this.modId; // 模块化的id
this.extra;
this.modId; // 模块化的id requirejs
this.extra; // 节点的额外信息
Object.keys(options).forEach(key => {
this[key] = options[key];
})
......
......@@ -4,22 +4,14 @@ const Log = require('./log.js');
const EventEmitter = require('events');
const cmlUtils = require('chameleon-tool-utils');
const parser = require('../mvvm-babel-parser/lib');
const merge = require('webpack-merge');
class Compiler {
constructor(webpackCompiler) {
constructor(webpackCompiler, plugin) {
this.moduleRule = [ // 文件后缀对应module信息
{
test: /\.css|\.less$/,
moduleType: 'style',
attrs: {
lang: 'less'
}
},
{
test: /\.stylus|\.styls$/,
moduleType: 'style',
attrs: {
lang: 'stylus'
}
test: /\.css|\.less|\.stylus|\.styls$/,
moduleType: 'style'
},
{
test: /\.js|\.interface$/,
......@@ -39,6 +31,13 @@ class Compiler {
this.log = new Log();
this.event = new EventEmitter();
this.webpackCompiler = webpackCompiler;
// 用户扩展文件类型
if (plugin.moduleRule && plugin.moduleRule instanceof Array) {
this.moduleRule = this.moduleRule.concat(plugin.moduleRule);
}
}
run(modules) {
......@@ -152,7 +151,10 @@ class Compiler {
// 创建单个节点
createNode(module) {
let options = {};
options.realPath = module.resource;
if (~module.resource.indexOf('images/chameleon.png')) {
debugger
}
options.realPath = module.resource; // 会带参数
options.ext = path.extname(module.resource);
options.nodeType = module._nodeType || 'module';
options.identifier = module.request;
......
const path = require('path');
const MvvmCompiler = require('./compiler.js');
class mvvmGraphPlugin {
constructor(options = {}) {
constructor(options = {}, platformPlugin) {
this.options = options;
this.platformPlugin = platformPlugin;
}
apply(compiler) {
let self = this;
let npmName = cml.config.get().extPlatform[this.options.cmlType];
let PlatformPlugin = require(path.join(cml.projectRoot, 'node_modules', npmName)); // eslint-disable-line
let plugin = new PlatformPlugin(this.options);
let mvvmCompiler = new MvvmCompiler(compiler);
let mvvmCompiler = new MvvmCompiler(compiler, self.platformPlugin);
compiler._mvvmCompiler = mvvmCompiler;
// 监听cml中查找组件
cml.event.on('find-component', function({context, cmlFilePath, comPath, cmlType}, result) {
......@@ -19,7 +16,7 @@ class mvvmGraphPlugin {
mvvmCompiler.emit('find-component', {context, cmlFilePath, comPath, cmlType}, result);
}
})
plugin.register(mvvmCompiler);
self.platformPlugin.register(mvvmCompiler);
compiler.plugin('should-emit', function(compilation) {
debugger
......
......@@ -10,6 +10,7 @@
"license": "ISC",
"dependencies": {
"chameleon-tool-utils": "0.3.0-alpha.2",
"mvvm-babel-parser": "0.3.0-alpha.2"
"mvvm-babel-parser": "0.3.0-alpha.2",
"webpack-merge": "^4.2.1"
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册