spmjs / cmd-util Goto Github PK
View Code? Open in Web Editor NEWUtilities for common module definition.
Utilities for common module definition.
调用 ast.parseFirst , 无法识别字符串拼接的路径, 如:
require("./mycss" + myVar+ ".css");
Add a css parser
这样可以 import 外部的样式
@lepture 这个库只有你有权限
好像压缩后的不行,给你加个用例
npm i cmd-util
npm ERR! Invalid Version: 0.1.1a1
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Administrator\AppData\Local\npm-cache_logs\2022-10-08T03_30_45_407Z-debug-0.log
ast.js代码中多处出现以下类似代码,用于判断代码结点是否为对函数名为require的调用,然后再获取其参数,比如模块 id
if(node instanceof UglifyJS.AST_Call && node.start.value === 'require')
此种方式对如下代码也能判断通过
require('module-a')('abc')
但是,此时 node.args[0] 其实是 'abc',而不是 'module-a',也就是说通过上述方式解析require 对应的模块 id 参数值,很有可能是错的
正确的方式应该是
if(node instanceof UglifyJS.AST_Call && node.expression.name === 'require') {
var id = node.args[0].value
}
/*! define a */
/*! block e */
/*! import d */
a {color: ablack}
/*! endblock */
这里转换后import d
应该归于谁呢?
第一种归于所属模块
[
{
"id": "a",
"type": "block",
"code": [
{
"id": "e",
"type": "block",
"code": [
{
"id": "d",
"type": "import"
},
{
"type": "string",
"code": "a {color:black;}"
}
]
}
]
}
]
第二种归于全局
[
{
"id": "a",
"type": "block",
"code": [
{
"id": "e",
"type": "block",
"code": [
{
"type": "string",
"code": "a {color:black;}"
}
]
},
{
"id": "d",
"type": "import"
}
]
}
]
如题吧,能否把async
依赖放到async
属性中呢,这样便于用工具替换
require.async('jquery');
到完整路径
require.async('base/jquery/1.10.2/jquery');
把配置简化,现在sea.config
必须保留async
的别名配置!
直接上 性能测试 😄 有时间更新到版本库~
样式转换前:
/*! define a */
@charset "utf-8";
@import url('nav.css');
@import "foot.css";
/* import common.css *//**/
body { color: red; font-size: 12px; }
/* hello world */
/*! block e */
.a { color: black }
/*! endblock */
/*! block f */
.b { color: white }
/*! block g */
.c { color: yellow }
/*! endblock */
.d { color: green }
/*! endblock */
新版转换后:
/*! block a */
@charset "utf-8";
/*! import nav.css */
/*! import foot.css */
/* import common.css *//**/
body { color: red; font-size: 12px; }
/* hello world */
/*! block e */
.a { color: black }
/*! endblock e */
/*! block f */
.b { color: white }
/*! block g */
.c { color: yellow }
/*! endblock g */
.d { color: green }
/*! endblock f */
/*! endblock a */
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.