提交 4d8cce14 编写于 作者: Y yylgit

mvvm-cml-loader

上级 4cf448d5
......@@ -117,7 +117,6 @@ module.exports = function createHelpers (
) {
// console.log(fileType)
const rawRequest = getRawRequest(loaderContext, options.excludedPreLoaders)
const {
defaultLoaders,
loaders,
......
#! /usr/bin/env node
#! /usr/bin/env node --inspect-brk
// --inspect-brk
require('./lib/index.js');
......
module.exports = function({type, media}) {
const utils = require('./utils.js');
cml.media = media;
utils.startReleaseOne(media, type);
}
\ No newline at end of file
......@@ -20,6 +20,7 @@ exports.getBuildPromise = async function (media, type) {
if (~['wx', 'baidu', 'alipay'].indexOf(type)) {
// 异步删除output目录
var outputpath = webpackConfig.output.path;
if (outputpath) {
await new Promise(function(resolve, reject) {
fse.remove(outputpath, function(err) {
if (err) {
......@@ -32,6 +33,7 @@ exports.getBuildPromise = async function (media, type) {
cml.log.error(message);
throw new Error(e)
})
}
}
return new Promise(function(resolve, reject) {
......@@ -73,6 +75,13 @@ exports.getBuildPromise = async function (media, type) {
* @param {*} type wx web weex
*/
exports.getOptions = function (media, type) {
if (!~['web','weex','alipay','baidu','wx'].indexOf(type)) {
return {
type: type,
media,
root: cml.projectRoot
};
}
let chameleonConfig = cml.config.get()[type][media];
if (!chameleonConfig) {
......
......@@ -33,6 +33,9 @@ module.exports = function (options) {
}
publicPath = options.publicPath || defaultPublichPathMap[type];
if(!publicPath) {
publicPath =`http://${config.ip}:${webServerPort}/${type}/`
}
let commonConfig = {
......
......@@ -5,6 +5,7 @@ const getWeexDevConfig = require('./getWeexDevConfig.js');
const getWeexBuildConfig = require('./getWeexBuildConfig.js');
const getMiniAppDevConfig = require('./getMiniAppDevConfig.js');
const getMiniAppBuildConfig = require('./getMiniAppBuildConfig.js');
const getExtendConfig = require('./mvvm/getExtendConfig.js');
const utils = require('./utils');
/**
......@@ -20,6 +21,10 @@ module.exports = async function (options) {
await utils.setFreePort();
let {type, media} = options;
let webpackConfig;
debugger
if (cml.config.get().extPlatform && ~Object.keys(cml.config.get().extPlatform).indexOf(type)) {
webpackConfig = getExtendConfig(options);
} else {
switch (type) {
case 'wx':
case 'alipay':
......@@ -45,9 +50,9 @@ module.exports = async function (options) {
}
break;
default:
break;
}
}
cml.utils.applyPlugin('webpackConfig', { type, media, webpackConfig }, function(params) {
if (type === params.type && media === params.media) {
......
const loaderUtils = require('loader-utils')
module.exports = function(source) {
const self = this;
const rawOptions = loaderUtils.getOptions(this) || {};
const context = (
this.rootContext ||
(this.options && this.options.context) ||
process.cwd()
)
function getPartLoaders(part) {
let loaders = self.loaders.map(loader => {
let loaderOptions = loader.options || {}
let options = {
part
}
return {
loader: loader.path,
options: {
...loaderOptions,
...options
}
}
})
let stringLoaders = stringifyLoaders(loaders);
let resourcePath = self.resourcePath;
return '!'+stringLoaders + '!' + resourcePath;
}
if (!rawOptions.part) {
debugger
source = `
var template = require('${getPartLoaders('template')}');
var style = require('${getPartLoaders('style')}');
var json = require('${getPartLoaders('json')}');
var script = require('${getPartLoaders('script')}');
module.exports = {
template,
style,
json,
script
}
`
console.log(source);
debugger
} else {
debugger
source = rawOptions.part
}
return source;
}
function stringifyLoaders (loaders) {
return loaders
.map(
obj =>
obj && typeof obj === 'object' && typeof obj.loader === 'string'
? obj.loader +
(obj.options ? '?' + JSON.stringify(obj.options) : '')
: obj
)
.join('!')
}
\ No newline at end of file
const merge = require('webpack-merge')
const path = require('path');
// const cmlLoader = path.join(__dirname, './extCmlLoader.js');
const getCommonConfig = require('../getCommonConfig');
const utils = require('../utils.js');
module.exports = function(options) {
let {type, media} = options;
let extendConfig = {
entry: {
app: path.join(cml.projectRoot, 'src/app/app.cml')
},
output: {
path: path.join(cml.projectRoot, 'dist/' + type)
},
module: {
rules: [
...utils.styleLoaders({type}),
{
test: /\.cml$/,
use: [{
loader: 'mvvm-cml-loader',
options: {
loaders: utils.cssLoaders({type, media}),
cmlType: type,
media,
check: cml.config.get().check,
}
}]
}
]
},
plugins: [
{
apply(compiler) {
compiler.plugin('should-emit', function(compilation) {
debugger
})
}
}
]
};
return merge(getCommonConfig(options), extendConfig);
}
\ No newline at end of file
// https://github.com/michael-ciniawsky/postcss-load-config
module.exports = {
"plugins": {
// to edit target browsers: use "browserslist" field in package.json
"postcss-import": {},
}
}
\ No newline at end of file
......@@ -63,6 +63,22 @@ exports.cssLoaders = function (options) {
// generate loader string to be used with extract text plugin
function generateLoaders(loader, loaderOptions) {
// 扩展流程
if (cml.config.get().extPlatform && ~Object.keys(cml.config.get().extPlatform).indexOf(options.type)) {
let extLoaders = [
getPostCssLoader('extend'),
{
loader: loader + '-loader',
options: Object.assign({}, loaderOptions, {
sourceMap: false
})
}
]
addMediaLoader(extLoaders, options.type);
return extLoaders;
}
var loaders = [cssLoader];
let result = [];
......
......@@ -24,11 +24,21 @@ module.exports.run = function () {
// commanderInstance.registerCommander({commander: subCommander})
// })
// }
// 扩展端
const extendPlatform = require('../commanders/extendPlatform.js');
if (cml.config.get().platformPlugin && cml.config.get().platformPlugin[first]) {
extendPlatform({platform: first, media: argv[3]});
} else {
// const extendPlatform = require('../commanders/extendPlatform.js');
// if (cml.config.get().platformPlugin && cml.config.get().platformPlugin[first]) {
// extendPlatform({platform: first, media: argv[3]});
// }
const extPlatform = require('../commanders/extPlatform.js');
if (cml.config.get().extPlatform && ~Object.keys(cml.config.get().extPlatform).indexOf(first)) {
extPlatform({type: first, media: argv[3]});
}
else {
commander.usage('[command] [options]')
commander.version(`${cmlpackage.name}@${cmlpackage.version}`)
let cmdList = ['init', 'dev', 'build', 'server', 'web', 'weex', 'wx', 'baidu', 'alipay'];
......
......@@ -197,11 +197,6 @@
"@babel/types": "7.2.2"
}
},
"@babel/helper-plugin-utils": {
"version": "7.0.0",
"resolved": "http://registry.npm.xiaojukeji.com/@babel/helper-plugin-utils/download/@babel/helper-plugin-utils-7.0.0.tgz",
"integrity": "sha1-u7P77phmHFaQNCN8wDlnupm08lA="
},
"@babel/helper-split-export-declaration": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.0.0.tgz",
......@@ -648,7 +643,8 @@
"asap": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz",
"integrity": "sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY="
"integrity": "sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY=",
"optional": true
},
"asn1": {
"version": "0.2.4",
......@@ -2213,7 +2209,6 @@
"resolved": "http://registry.npm.xiaojukeji.com/rework/download/rework-1.0.1.tgz",
"integrity": "sha1-MIBqhBNCtUUQqkEQhQzUhTQUSqc=",
"requires": {
"convert-source-map": "0.3.5",
"css": "2.2.4"
}
},
......@@ -2278,7 +2273,6 @@
"requires": {
"@babel/parser": "7.2.3",
"@babel/traverse": "7.2.3",
"bulk-require": "1.0.1",
"chalk": "2.4.2",
"chameleon-tool-utils": "0.3.0-alpha.2",
"cml-component-parser": "0.3.0-alpha.2",
......@@ -2316,10 +2310,8 @@
"resolved": "https://registry.npmjs.org/cml-htmllint/-/cml-htmllint-0.3.0-alpha.2.tgz",
"integrity": "sha512-oD/i71ivAGWppPmKAdsKj/jK1BvepHTAEOTqmdKwSpwLPFpzm2mHQdaBq9omLWflXkFE4JMH01aaeMtMRM7wgQ==",
"requires": {
"bulk-require": "1.0.1",
"htmlparser2": "3.10.0",
"lodash": "4.17.11",
"promise": "8.0.2"
"htmlparser2": "3.10.1",
"lodash": "4.17.11"
}
},
"cml-interface-parser": {
......@@ -2340,7 +2332,6 @@
"requires": {
"@babel/parser": "7.2.3",
"@babel/traverse": "7.2.3",
"bulk-require": "1.0.1",
"chameleon-tool-utils": "0.3.0-alpha.2"
}
},
......@@ -2504,7 +2495,6 @@
"requires": {
"@babel/generator": "7.2.2",
"@babel/parser": "7.4.3",
"@babel/plugin-syntax-jsx": "7.2.0",
"@babel/traverse": "7.2.3",
"@babel/types": "7.2.2",
"babylon": "6.18.0",
......@@ -7336,10 +7326,13 @@
"resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.7.tgz",
"integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s="
},
"mvvm-pack": {
"mvvm-cml-loader": {
"version": "0.0.1",
"resolved": "http://registry.npm.xiaojukeji.com/mvvm-pack/download/mvvm-pack-0.0.1.tgz",
"integrity": "sha1-vz6f751GJYc8pn2cmKrjBa22+vk="
"resolved": "https://registry.npmjs.org/mvvm-cml-loader/-/mvvm-cml-loader-0.0.1.tgz",
"integrity": "sha512-bUzxfNzMq/mcqAOlx03JIzyZNrrtUFrm1XF4zJm51bGrkEk0TfhaZkaCVo+Z/qQjSfSY0yqJD8pQ4OZtbUmJSA==",
"requires": {
"loader-utils": "1.2.3"
}
},
"nan": {
"version": "2.13.2",
......@@ -11462,14 +11455,6 @@
"integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==",
"dev": true
},
"promise": {
"version": "8.0.3",
"resolved": "http://registry.npm.xiaojukeji.com/promise/download/promise-8.0.3.tgz",
"integrity": "sha1-9ZLgmcbN3AANU47nKDuxkEUrC/Y=",
"requires": {
"asap": "2.0.6"
}
},
"promise-inflight": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/promise-inflight/-/promise-inflight-1.0.1.tgz",
......
......@@ -74,6 +74,7 @@
"less": "3.0.4",
"less-loader": "4.1.0",
"minimist": "1.2.0",
"mvvm-cml-loader": "0.0.1",
"mvvm-pack": "0.3.0-alpha.2",
"node-phpcgi": "0.3.7",
"node-watch": "^0.5.9",
......
......@@ -450,8 +450,8 @@ module.exports = function (content) {
output += 'module.exports.el = \'' + params.entry + '\'\n' +
'new Vue(module.exports)\n'
}
// console.log(output)
console.log(output)
debugger
// done
return output
}
......@@ -26,6 +26,7 @@ function convertLength (k, v) {
}
function genStyleString (input, loader) {
debugger
var output = '{}'
styler.parse(input, function (err, obj) {
if (err) {
......
......@@ -9,7 +9,6 @@ module.exports = function (source) {
let {cmlType, media, check = {}} = options;
const filePath = this.resourcePath;
let self = this;
debugger
const resolve = function(filePath, relativePath) {
let context = path.dirname(filePath);
......
此差异已折叠。
# Editor directories and files
.DS_Store
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
jspm_packages/
# Typescript v1 declaration files
typings/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
dist/
# ///////////////////////////
const path = require('path');
exports.stringifyLoaders = function (loaders) {
return loaders
.map(
obj =>
obj && typeof obj === 'object' && typeof obj.loader === 'string'
? obj.loader +
(obj.options ? '?' + JSON.stringify(obj.options) : '')
: obj
)
.join('!')
}
exports.getSelector = function() {
return path.resolve(__dirname, './selector.js')
}
exports.getPartLoaders = function({selectorOptions, partType, lang, loaders, resourcePath}) {
selectorOptions.partType = partType;
let resultLoaders = [
{
loader: exports.getSelector(),
options: selectorOptions
}
]
switch (partType) {
case 'style':
var styleLoader = loaders[lang];
resultLoaders = styleLoader.concat(resultLoaders);
break;
case 'script':
var jsLoader = loaders.js;
resultLoaders = jsLoader.concat(resultLoaders);
break;
default:
break;
}
let stringLoaders = exports.stringifyLoaders(resultLoaders);
return '!' + stringLoaders + '!' + resourcePath;
}
const loaderUtils = require('loader-utils')
const helper = require('./helper.js');
const cmlUtils = require('chameleon-tool-utils');
module.exports = function(source) {
let output = '';
const self = this;
const rawOptions = loaderUtils.getOptions(this) || {};
let {loaders, cmlType, media, check} = rawOptions;
const resourcePath = this.resourcePath;
// const context = (
// this.rootContext ||
// (this.options && this.options.context) ||
// process.cwd()
// )
let selectorOptions = {
cmlType,
media,
check
}
let parts = cmlUtils.splitParts({content: source});
if (parts.style.length > 0) {
throw new Error(`${resourcePath} only allow has one <style></style>`)
}
if (parts.style && parts.style[0]) {
let part = parts.style[0];
let lang = part.attrs && part.attrs.lang || 'less';
output += `
var style = require('${helper.getPartLoaders({selectorOptions, partType: 'style', lang, loaders, resourcePath})}');
`
}
output += `
var template = require('${helper.getPartLoaders({selectorOptions, partType: 'template', loaders, resourcePath})}');
`
output += `
var json = require('${helper.getPartLoaders({selectorOptions, partType: 'json', loaders, resourcePath})}');
`
output += `
var script = require('${helper.getPartLoaders({selectorOptions, partType: 'script', loaders, resourcePath})}');
`
debugger
return output;
}
{
"name": "mvvm-cml-loader",
"version": "0.0.1",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Chameleon-Team",
"license": "Apache",
"dependencies": {
"chameleon-tool-utils": "^0.3.0-alpha.2",
"loader-utils": "^1.2.3"
}
}
const loaderUtils = require('loader-utils')
const cmlUtils = require('chameleon-tool-utils');
module.exports = function(source) {
const rawOptions = loaderUtils.getOptions(this) || {};
let {partType} = rawOptions;
let parts = cmlUtils.splitParts({content: source});
let output = '';
switch (partType) {
case 'style':
output = parts.style[0].content;
break;
case 'script':
parts.script.forEach(item => {
if (item.cmlType !== 'json') {
output = item.content;
}
})
break;
case 'template':
output = parts.template && parts.template[0] && parts.template[0].content;
break;
case 'json':
parts.script.forEach(item => {
if (item.cmlType === 'json') {
output = item.content;
}
})
break;
default:
break;
}
return output;
}
\ No newline at end of file
......@@ -74,6 +74,7 @@ class Compile {
]
this.resolve = this.resolve.bind(this);
this.outputFileList = {}; // 输出对象
}
// path 是源文件路径 request是要解析的路径
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册