如何改造现有文件为 CMD 模块

STM32CubeIDE离线安装PACK包完整指南:内网环境芯片支持包导入与批量部署 在嵌入式开发中,芯片支持包(Device Family Pack)是让IDE识别目标芯片的关键组件,其本质是一套包含设备头文件、启动文件、链接脚本和HAL库的完整描述档案。离线安装的核心原理是手动将PACK包放入IDE的Repository目录,并确保版本匹配与目录结构正确。这一技术方案解决了内网开发机、多机批量部署和网络不稳定场景下的环境搭建难题,广泛应用于企业内网、教学机房和版本锁定项目。STM32CubeIDE作为主流嵌入式开发环境,其PACK包管理机制与Keil不同,离线导入需关注版本兼容性、文件夹 阅读详情

如何改造现有文件为 CMD 模块

经过一段考察,我们终于要在项目中引入模块机制和 Sea.js 了,那么如何将现有的文件改造成 CMD 模块就成了重要的问题。下面针对一些典型场景来说明包装的方式。

首先还是请大家详细了解下 CMD 模块定义规范,只要洞悉事物的定义和本质,一切问题可迎刃而解。

改造主流模块

这里指的是 jQuery、Moment、Backbone、underscore 等业界主流模块,这些模块一般都有对 AMD 和 CommonJS 的支持代码,例如 jQuery 源文件的最后几行:

if ( typeof module === "object" && module && typeof module.exports === "object" ) {
    module.exports = jQuery;
} else {
    window.jQuery = window.$ = jQuery;

    if ( typeof define === "function" && define.amd ) {
        define( "jquery", [], function () { return jQuery; } );
    }
}

还有 Backbone 里:

var Backbone;
if (typeof exports !== 'undefined') {
  Backbone = exports;
} else {
  Backbone = root.Backbone = {};
}

对于有这些兼容代码的,只需要去掉 define.amd 的支持,或是直接包装上 define 就可以了。

define(function(require, exports, module) {
  // code here ...
});

如果没有模块化的兼容代码,有时候需要手动引入依赖,以及暴露对应的接口。

define(function(require, exports, module) {
  var $ = require('$');
  // code here ...
  module.exports = Placeholders;
});

可以参考 cmdjs/gallery 里的 Gruntfile 对这些主流模块的代码替换方式。

现有的 JS 文件

对于一些现有的普通 JS 文件,相对简单的多,参考 CMD 的书写规范,把那些暴露到全局命名空间的接口用 CMD 的方式进行改造就可以了。

比如现有文件 util.js 。

window.util = window.util || {};
util.addClass = function() {
  window.css();
};
util.queryString = function() {};

改为:

define(function(require, exports, module) {
  // 引入依赖
  var css = require('css');

  util.addClass = function() {
    css();
  };
  util.queryString = function() {};

  // 暴露对应接口
  module.exports = util;
});

这里不啰嗦,就是基本的 CMD 书写规范。实际的改造过程中,情况可以比上面的例子要复杂一些,具体情况具体解决就行。

改造 jQuery 插件

这也是一个经常遇到的问题,我们推荐以下的包装方式:

// jquery-plugin-abc
define(function(require, exports, module) {
  var $ = require('$');
  // 插件的代码
  $.fn.abc = function() {};
});

这样的改造方式实际上是强化了原有的 $ 对象(而不是重新包装出一个新的 $),在实际调用时,可以用下面的方式:

seajs.use(['$', 'jquery-plugin-abc'], function($) {
  // $ 有了 jquery-plugin-abc 所提供的插件功能
  $.abc();
});

更多 jQuery 插件的包装,可以参考 cmdjs/jquery 里的做法。

工具

除了手动的方式修改代码外,我们推荐使用 Grunt 来进行统一的改造,官方也通过 Grunt 改造了很多主流模块和 jQuery 插件,具体的操作手册见 引入 CMD 模块指南 。你可以在 cmdjs/gallery 和 cmdjs/jquery 中找到具体的 Gruntfile ,从而借鉴到您的项目中去。所有打包好的模块可以在 spmjs.org 中找到。

小结

上面提供的是原有代码包装为 CMD 书写规范 的方法,在具体上线前,可能还需要打包为具名模块(包含 ID 的模块)。关于构建方面的进一步知识可以参考 构建工具 。

这里提到的包装方式都比较典型和简单,具体的实践可能千差万别。您在项目中有什么探索、实践和问题,欢迎来这里分享和提问。

locust改造一:cmd执行语句后台运行方法 问题起源 最近在做locust的性能工具改造,将django+locust融合在一起,然后有个很尴尬的地方,我生成了locust_server.py文件,然后要启动服务器的话需要用cmd命令行来启动,预期逻辑是: 1、界面配置接口信息 2、生成locust_server.py文件 3、启动locust服务器:通过cmd运行locust_server.py文件 os.system("python l... 阅读详情

相关推荐

BAT,VBS转EXE文件改造者

支持任何可双击打开的文件转成EXE。(如CMD,BAT,VBS等等) 还可以整合别的软件,加密码,设置打开方式(支持没界面,最小化,最大化运行。) 并可以设置自己的版权信息。

在当前文件夹下进行cmd操作

直接在上面的地址那进行按cmd,再按回车键就可以了,不用一个个的再去找地址,这样会方便很多,而且默认c盘,再切到其它磁盘会非常的麻烦。直接在这里打上cmd在进行回车就行了,这是正在运行的一个。

m0_73933036的博客 967

cmdize:将普通js转换为CMD模块

Cmdize(已弃用) 别用了,用CommonJS写代码,仅此而已。 将普通js转换成CMD模块。() 支持一些著名的 JavaScript 库(jQuery、underscore、momentjs)和无依赖的 JS Normal 文件。 为实验项目,重要场合慎用! 安装 $ npm install cmdize -g 在 cli 中使用 有一个 js 文件exmple.js : window . abc = "abc" ; 命令它! $ cmdize example.js Reading /Users/afc163/Desktop/example.js ... No found any global variables. cmdized.js is generated. >> /Users/afc163/Projects/cmdize/example-cmdized.

将一些js库改写成符合cmd规范的模块

在进行seajs编码的时候,遇到很到js库都不是使用cmd规范进行编码的。这时怎么办呢?当然是改写喽 第一是:jQuery了,版本jquery-1.8.1.js(不同的版本有不同的改法) //查询到define,将那边的if语句替换成如下格式,O啦 if ( typeof define === "function" && define.cmd) { define( fu...

shuizhongyue_的专栏 376

Nginx反向代理MinIO私有桶签名失效?一招解决Host头校验问题

本文详细解析了Nginx反向代理MinIO私有桶时出现的签名失效问题,重点解决了Host头校验导致的"SignatureDoesNotMatch"错误。通过精准配置proxy_set_header保持Host头一致性,并提供了二级目录代理和调试指南,帮助开发者高效解决这一常见技术难题。

weixin_29201313的博客 321

若依前后端分离版集成nacos

服务动态配置与服务注册发现根据公司要求,需要将项目集成到nacos中,当前项目是基于若依前后端分离版开发的,若依的版本为3.8.3,若依框架中整合的springBoot版本为2.5.14。Nacos核心提供两个功能:服务注册与发现,动态配置管理。

NDF923的专栏 4645

Powershell + clink整合cmd教程

Powershell + clink整合cmd教程 首先看一下效果图,看看是不是你想要的 store下载terminal 下面更改每次win + r 键进入终端都是通过这个terminal进入 终端中安装oh-my-posh winget install JanDeDobbeleer.OhMyPosh 2. powershell改造 安装完成之后,修改poweshell中的配置文件,链接到oh-my-posh上 notepad $PROFILE 如果没有这个文件存在,就先用下边的命令

Code_star的博客 4206

电商数据分析18——电商广告投放的数据分析与优化

在当今的电商行业中,广告投放是提高品牌知名度、吸引潜在客户和增加销售额的关键策略之一。随着市场竞争的加剧,仅仅依靠直观判断和传统方法已经无法满足广告投放的需求。数据分析在这里扮演了至关重要的角色,它可以帮助企业更准确地定位目标受众,评估广告效果,优化广告内容,从而提高广告效率和投资回报率(ROI)。

theskylife的博客 5703

seajs使用插件问题

如何改造现有文件为 CMD 模块 #971 https://github.com/seajs/seajs/issues/971

kongjiea笔记 1181

YOLOv8 TensorRT C++部署实战详解:从XMake构建到推理流水线

本项目实现了一个基于YOLOv8和TensorRT的高性能火灾烟雾检测系统,具有以下核心特点: 技术架构:采用TensorRT 8.6+进行GPU加速推理,结合CUDA 12.1和OpenCV 4.8+,实现高效计算机视觉处理。系统使用XMake替代CMake构建,配置更简洁高效。

hscing的博客 1065

倍福TC3 PLC高速采集实战:如何用PLC-Recorder实现0.24ms级时间戳同步

本文详细介绍了倍福TC3 PLC与PLC-Recorder实现0.24ms级时间戳同步的工程实践方案。通过硬件拓扑设计、时间源选择优化、报文结构封装及同步验证方法,为工业自动化领域的高精度数据采集提供了可靠解决方案,特别适用于精密装配、激光切割等微秒级同步要求的场景。

weixin_29193359的博客 372

简单分页插件simplePagination改造为CMD模块

简单分页simplePagination的官网地址 http://flaviusmatis.github.io/simplePagination.js/这个是基于jquery的插件形式,为了适用于CMD规范下的开发,比如方便seajs引用,将simplePagination改造成一个模块。改造后的simplePagination.jsdefine(function(require, exports

笔心 4287

wireshark提取视频数据之RTP包中提取H264和H265

本文主要描述从wireshark包数据中提取出H264和H265裸流数据方法,裸流通过RTP封包方式发送,从抓包中直接提取视频流数据,进而进行流媒体问题定位

技术控的笔记 17万+

jQuery焦点图插件改造为CMD模块

说明之前写过一个jquery的焦点图插件http://blog.youkuaiyun.com/qinshenxue/article/details/9199619,最近项目用到了seajs,为了符合模块开发的原则,把插件改造为CMD模块演示源码html代码<div id="banner" class="slider"> <ul class="slider-box"> <li style=

笔心 2038

AI测试干货:Claude Code Skill 从入门到精通

本文介绍了Claude Code Skill功能如何解决AI重复工作问题。传统提示词方式需要人工复制粘贴,而Skill功能通过建立AI工作记忆库实现智能触发和分层加载。Skill包含工作指令、文档和资源,能自动执行任务。文章以API测试用例生成为例,展示了Skill的创建流程和结构化设计,包括测试框架、覆盖场景和输出格式,显著提升测试工程师的工作效率。

blues_C的博客 2440

【YOLOv8科研级优化】基于YOLOv9的GELAN模块重构C2f结构,实现精度与效率的同步提升

打开确保模型解析器能识别GELANBlock模块。通过将YOLOv9的GELAN模块集成到YOLOv8的C2f模块中,我们实现了一个“强特征表达+高效计算”的目标检测模型。这个改进不仅在工程上能提升复杂场景下的检测效果,更在科研上提供了“多分支特征融合”的创新思路——这种思路可以延伸到其他检测网络(如Faster R-CNN、SSD)的改进中,帮你在论文中打造独特的研究点。

know_F0727的博客 203

使用cmd模块实现交互式程序

      这两天一直忙着用cmd模块写一个交互式程序来着,前天到凌晨5:00才睡,昨天晚上到2:00才睡。就是为了实现命令的自动完成功能,没成想这么一个小东东费了我九牛二虎之力啊!!!!     还好的是最终还是实现了,只不过现在回过头来想一想,这么做法不好,记得一个老师上课的时候讲过“花费20%左右的努力可以获得80%的效率,可是要获得90%以上的完美效果就可能要花费你另外的80%的辛苦!!!

秋枫林的专栏 4986

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

CMD基础知识

一. 在public目录下建立一个index.html文件,所有页面中的内容都在 这里面实现,index.html中需要导入的文件有: 1. CMD框架的sea.js文件 <script src="js/seajs_modules/sea.js"></script> 2. 自己创建的主配置seajs_config.js文件 ...

RenJi0316的博客 255

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

如何让模块支持AMD/CMD和commonjs标准

前段时间在看一些前端模块化方面的知识,现在自己就来写一个符合amd/cmd 和commonjs标准的模块。在文中会穿插一些AMD/CMD,commonjs的基础知识,主要是为了让自己复习一下。了解的同学们可以直接略过。 一 原模块 该模块是一个实现类数组转为数组功能的模块 (function(arrayLike){ function ...

weixin_34279246的博客 406

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

将Windows的CMD改造成Linux风格的命令行

参加XCON2004,看大牛牛们演示时的命令行都很特别,回来自己研究了一下,原来Prompt命令就可以实现。写了个批处理linux.bat存在C:/根目录下rem========================================Prompt yztgx#doskey ls=dirdoskey pwd=cdclsrem======================

yztgx的专栏 3979

【备忘录】兼容amd与cmd

主流模块的代码替换方式参考:https://github.com/cmdjs/galleryjquery引入cmd模块:https://github.com/cmdjs/jqueryamd config:https://github.com/amdjs/amdjs-api/blob/master/CommonConfig.md umdjs:https://github.com/umdjs/umd...

weixin_30402085的博客 100

web前端.js--seajs--把easyUI改造成功标准CMD模块的方法

(function(factory) {     if (typeof define === 'function') {         define(factory);     } else {         factory();     } })(function(require) { var jQuery = require("jquery"); easyUI

2214
上一篇: seajs 配置说明
下一篇: redis添加到windows服务中
赢阡
博客等级 码龄10年 6粉丝 15原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值