You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
2.5 KiB
63 lines
2.5 KiB
const path = require('path');
|
|
const fs = require('fs')
|
|
const fileName = 'tisplatform.json';
|
|
const production = process.env.NODE_ENV === 'production' || process.env.VUE_APP_SDK === 'sdk';
|
|
const uc = require("upper-case");
|
|
function resolve(dir) {
|
|
return path.join(__dirname,dir);
|
|
}
|
|
function parent_path_count(path_str,count) {
|
|
let path_temp = path_str;
|
|
for (let i = 0; i < count; i++) {
|
|
path_temp = path.resolve(path_temp,'..')
|
|
}
|
|
}
|
|
function createTisplatformPlugin(options){
|
|
this.options = options;
|
|
}
|
|
|
|
createTisplatformPlugin.prototype.apply = function (compiler) {
|
|
let _path = this.options.path;
|
|
let sdkName = this.options.sdkName;
|
|
let json = {};
|
|
if(!production) return;
|
|
compiler.plugin('compilation',function (compilation,options) {
|
|
compilation.plugin('html-webpack-plugin-before-html-processing',function (htmlPluginData,callback) {
|
|
// const title = htmlPluginData.plugin.options.title;
|
|
// const ROOT_DIR_NAME = path.resolve(__dirname,'../../').split(path.sep).pop()
|
|
// const title = uc(ROOT_DIR_NAME);
|
|
json[sdkName] = {
|
|
cssFiles : htmlPluginData.assets.css/*.map(css=>"/"+title+css)*/,
|
|
jsFiles : htmlPluginData.assets.js/*.map(js=>"/"+title+js)*/,
|
|
preload : true,
|
|
};
|
|
// console.log('资源',title,htmlPluginData)
|
|
console.log(htmlPluginData.assets.js);
|
|
// console.log('------------',_path);
|
|
console.log(htmlPluginData.assets.css);
|
|
})
|
|
})
|
|
compiler.plugin('done',function (compilation,options) {
|
|
console.log('compiler done')
|
|
fs.writeFileSync(path.join(_path,fileName),JSON.stringify(json,null,"\t"))
|
|
let config = JSON.parse(fs.readFileSync(path.join(_path,"esplug.json")));
|
|
config.id = sdkName;
|
|
config.icon = `/${sdkName}/icon.png`
|
|
config.entry = `/${sdkName}/`;
|
|
config.type = "app";
|
|
config.version = "2";
|
|
// console.log('config file:',config);
|
|
fs.writeFileSync(path.join(_path,"esplug.json"),JSON.stringify(config,null,"\t"));
|
|
|
|
//兼容kt,把描述文件统一放到manifest文件夹下
|
|
fs.mkdirSync(path.join(_path)+"/manifest");
|
|
fs.writeFileSync(path.join(_path,"manifest/esplug.json"),fs.readFileSync(path.join(_path,"esplug.json")));
|
|
|
|
//添加路径
|
|
// let css = fs.readFileSync(path.join(_path,"css/app.css"))
|
|
// console.log(css)
|
|
// .replace(/url\(/g,`url(${sdkName}/`)
|
|
})
|
|
}
|
|
|
|
module.exports = createTisplatformPlugin;
|