Skip to content

Commit

Permalink
feat(build & core): add h5 runtime entry
Browse files Browse the repository at this point in the history
  • Loading branch information
allen-zh committed May 14, 2019
1 parent b428d64 commit f1f7ff9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
37 changes: 11 additions & 26 deletions packages/mars-build/src/compiler/file/compileModules.js
Expand Up @@ -100,37 +100,22 @@ function compile(val, key, destPath) {
async function compileUIModules(uiModules, destPath) {
for (const key of Object.keys(uiModules)) {
const {path: modPath, realName} = uiModules[key];
let coreEntry;
let entry;
let isH5 = false;
try {
coreEntry = require.resolve(realName + '/mars-core', {
paths: [process.cwd()]
});
entry = coreEntry.replace('mars-core/index.js', '');
}
catch (e) {
isH5 = true;
coreEntry = require.resolve(realName + '/main.js', {
paths: [process.cwd()]
});
entry = coreEntry.replace('/main.js', '');
}

const coreEntry = require.resolve(realName + '/mars-core', {
paths: [process.cwd()]
});
const entry = coreEntry.replace('mars-core/index.js', '');
const dest = path.resolve(destPath, modPath);

log.info('[compile:ui-module]:', getPathToCWD(entry));
await fs.copy(entry, dest);

if (!isH5) {
const coreDestPath = path.resolve(destPath, 'mars-core');
const uiCoreDestPath = path.resolve(dest, 'mars-core');
const coreRelativePath = path.relative(
uiCoreDestPath,
coreDestPath
);
fs.outputFileSync(uiCoreDestPath + '/index.js', `export * from '${coreRelativePath}';`);
}
const coreDestPath = path.resolve(destPath, 'mars-core');
const uiCoreDestPath = path.resolve(dest, 'mars-core');
const coreRelativePath = path.relative(
uiCoreDestPath,
coreDestPath
);
fs.outputFileSync(uiCoreDestPath + '/index.js', `export * from '${coreRelativePath}';`);
}
}

Expand Down
11 changes: 10 additions & 1 deletion packages/mars-build/src/compiler/runtime/compiler.js
Expand Up @@ -13,6 +13,7 @@ const PLUGIN_NAME = 'file-compiler';
const log = require('../../helper/log');
const webpack = require('webpack');
const path = require('path');
const fs = require('fs-extra');

/**
* compile
Expand All @@ -24,6 +25,7 @@ function compile(options) {
const {target, dest, framework} = options;
const destPath = dest.path;
let entry;
const coreDestDir = path.resolve(process.cwd(), destPath + '/' + dest.coreDir);
if (target === 'wx') {
entry = require.resolve('@marsjs/core/src/wx', {
paths: [process.cwd()]
Expand All @@ -34,6 +36,13 @@ function compile(options) {
paths: [process.cwd()]
});
}
else if (target === 'h5') {
// h5 runtime just copy it
entry = require.resolve('@marsjs/core/src/h5', {
paths: [process.cwd()]
});
return fs.copy(entry, path.resolve(coreDestDir, 'index.js'));
}
else {
return Promise.resolve();
}
Expand All @@ -42,7 +51,7 @@ function compile(options) {
webpack({
entry: [entry],
output: {
path: path.resolve(process.cwd(), destPath + '/' + dest.coreDir),
path: coreDestDir,
filename: 'index.js',
libraryTarget: 'commonjs'
},
Expand Down
8 changes: 4 additions & 4 deletions packages/mars-build/src/scripts/run.js
Expand Up @@ -33,10 +33,10 @@ function getBuildTasks(config = {}, options = {}) {
'copy:assets'
];

if (target !== 'h5') {
gulp.task('compile:runtime', getTaskRuntime(config, options));
buildTasks.push('compile:runtime');
}
// if (target !== 'h5') {
gulp.task('compile:runtime', getTaskRuntime(config, options));
buildTasks.push('compile:runtime');
// }

return buildTasks;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/mars-core/src/h5/index.js
@@ -0,0 +1,6 @@
/**
* @file h5 runtime entry
* @author zhangwentao
*/

export {default as Vue} from 'vue';

0 comments on commit f1f7ff9

Please sign in to comment.