@joyshion/taro-plugin-platform-yunshanfu
Version:
85 lines (78 loc) • 3.37 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var path = require('path');
var lodash = require('lodash');
function _interopNamespaceDefault(e) {
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
}
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
var index = (ctx) => {
ctx.registerPlatform({
name: 'ysf',
useConfigName: 'h5',
async fn({ config }) {
var _a;
console.log('云闪付小程序编译...');
const { appPath, outputPath, sourcePath } = ctx.paths;
const { initialConfig } = ctx;
const { port } = ctx.runOpts.options;
const { emptyDirectory, recursiveMerge, npm, ENTRY, SOURCE_DIR, OUTPUT_DIR } = ctx.helper;
emptyDirectory(outputPath);
const entryFileName = `${ENTRY}.config`;
const entryFile = path__namespace.basename(entryFileName);
const defaultEntry = {
[ENTRY]: [path__namespace.join(sourcePath, entryFile)]
};
const customEntry = lodash.get(initialConfig, 'h5.entry');
const h5RunnerOpts = recursiveMerge(Object.assign({}, config), {
entryFileName: ENTRY,
env: {
TARO_ENV: JSON.stringify('ysf'),
FRAMEWORK: JSON.stringify(config.framework),
TARO_VERSION: require(path__namespace.join(ctx.paths.nodeModulesPath, '@tarojs/taro/package.json')).version
},
devServer: { port },
sourceRoot: config.sourceRoot || SOURCE_DIR,
outputRoot: config.outputRoot || OUTPUT_DIR
});
h5RunnerOpts.entry = lodash.merge(defaultEntry, customEntry);
const htmlPluginOption = (_a = h5RunnerOpts.htmlPluginOption) !== null && _a !== void 0 ? _a : {};
htmlPluginOption.upsdk = `<script src="https://open.95516.com/s/open/js/upsdk.js"></script>`;
h5RunnerOpts.htmlPluginOption = htmlPluginOption;
let runnerPkg;
const compiler = typeof config.compiler === 'object' ? config.compiler.type : config.compiler;
switch (compiler) {
case 'webpack5':
runnerPkg = '@tarojs/webpack5-runner/dist/index.h5.js';
// 需要禁用webpack5的prebundle
h5RunnerOpts.compiler = {
type: 'webpack5',
prebundle: {
enable: false
}
};
break;
default:
runnerPkg = '@tarojs/webpack-runner/dist/index.js';
}
const webpackModule = await npm.getNpmPkg(runnerPkg, appPath);
const webpackRunner = webpackModule.default;
webpackRunner(appPath, h5RunnerOpts);
}
});
};
exports.default = index;
//# sourceMappingURL=index.js.map