
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
express-webapp-assets
Advanced tools
Webapp Assets(static web resources) Middleware/Server/Generator for [Express].
express-webapp-assets
is a development tool to develop single page/front-end webapp using preprocessors.
For practical example, see express-webapp-assets-seed
It is NOT a server application.
It is a development tool with built-in http server.
In development phase,
In deployment phase:
In the other words, it does copy, filter(render/compile/.../whatever), bundle(merge) and compress assets for you just in time or in batch.
For example, it does these tasks instead of you(or your [grunt]/[gulp] script):
$ less foo.less > foo.css
$ cssmin foo.css > foo.min.css
$ less bar.less > bar.css
$ cssmin bar.css > bar.min.css
$ coffee-script baz.coffee > bar.js
$ uglify-js baz.js > bar.min.js
$ coffee-script qux.coffee > qux.js
$ uglify-js qux.js > qux.min.js
$ cat foo.css bar.css > all.css
$ cssmin all.css > all.min.css
$ cat baz.js qux.js > all.js
$ uglify-js all.js > all.min.js
and replace
<link rel="stylesheet" href="foo.css" />
<link rel="stylesheet" href="bar.css" />
<script src="baz.js"></script>
<script src="qux.js"></script>
into
<link rel="stylesheet" href="all.min.css" />
<script src="all.min.js"></script>
To develop webapp working with local API server written in [Express]/[Node.js].
install node.js module:
$ npm install express-webapp-assets --save-dev
configure middleware:
express()
...
.use('/assets', require('express-webapp-assets')({src:'public/assets', ... configurations ... }))
.use('/api/v1', ... your api routes ...)
...
NOTE: this is NOT intended for production use. use generator and deploy to your static-content http servers.
To develop webapp working with external API server written in other frameworks/languages.
install node.js module global(or local if you want):
$ npm install express-webapp-assets -g
run server, use --server
or -S
CLI option:
$ express-webapp-asset --server
NOTE: this is NOT intended for production use. use generator and deploy to your static-content http servers.
It generates static files for all assets written in preprocessors.
And the generated files could be served with high-performance static-content http servers.
No annoying modifications and/or verbose deploy script to switch development/production assets.
install node.js module in global(or local if you want):
$ npm install express-webapp-assets -g
run generator, use --generator
or -G
CLI option:
$ express-webapp-assets --generator --env=production
Configurations could be a ./_assets.json
file or a _asset
property in package.json
:
{
host: 'localhost', // server mode only
port: 3000, // server mode only
root: 'public', // server mode only
mount: '/', // server mode only
src: 'public',
dst: '/build/public',
helpers: { }, // passed to preprocessors
filters: { }, // custom filters
env: 'development' // 'development', 'staging', 'production' or else
}
To specify configuration file, use --config
or -C
CLI option:
$ express-webapp-asset --config=asset_config.json
foo.js
or foo.min.js
resolved to foo.js
file..bundle
extension.
foo.js
or foo.min.js
resolved to foo.js.bundle
file.foo.css
or foo.min.css
resolved to foo.css.bundle
file.foo.html
resolved to foo.html.jade
foo.css
or foo.min.css
resolved to foo.js.less
foo.js
or foo.min.js
resolved to foo.js.coffee
.min
and compressable format(js, css).includes
directories.
for example,
SRC/test.html
or SRC/test.html.jade
...
link(rel="stylesheet",href="foo.css")
link(rel="stylesheet",href="bar.min.css")
link(rel="stylesheet",href="bootstrap-all.min.css")
script(src="baz.js")
script(src="qux.min.s")
script(src="bootstrap-all.min.js")
DST/test.html
<link rel="stylesheet" href="foo.css" />
<link rel="stylesheet" href="bar.min.css" />
<link rel="stylesheet" href="bootstrap-all.min.css" />
<script src="baz.js"></script>
<script src="qux.min.js"></script>
<script src="bootstrap-all.min.js"></script>
SRC/bootstrap-all.js.bundle
# all bootstrap scripts
jquery/dist/jquery.min.js
bootstrap/dist/js/bootstrap.min.js
will generate/serve DST/boostrap-all.js
and DST/bootstrap-all.min.js
asset SRC/bootstrap-all.css.bundle
# all bootstrap styles
bootstrap/dist/css/bootstrap.min.css
bootstrap/dist/css/bootstrap-theme.min.css
will generate/serve DST/bootstrap-all.css
and DST/bootstrap-all.min.css
asset SRC/foo.css
or SRC/foo.css.less
will generate/serve DST/foo.css
and DST/foo.min.css
.
asset SRC/bar.css
or SRC/bar.css.less
will generate/serve DST/bar.css
and DST/bar.min.css
.
asset SRC/baz.js
or SRC/baz.js.coffee
will generate/serve DST/baz.css
and DST/baz.min.css
.
asset SRC/qux.js
or SRC/qux.js.coffee
will generate/serve DST/qux.css
and DST/qux.min.css
.
and so on...
There are helpers for preprocessors.
for example, there are test.js.bundle
foo.coffee.js
bar.js
and test.html.jade
using test.min.js
(or test.js
):
html
head
!=js('test.min.js')
in 'development' env, it generates/serves test.html
, foo.js
and bar.js
:
<html>
<head>
<script src="foo.js"></script>
<script src="bar.js"></script>
but in NOT 'development' env, it generates/serves test.html
and test.min.js
(or test.js
):
<html>
<head>
<script src="test.min.js"></script>
for example, there are test.css.bundle
foo.less.css
bar.css
and test.html.jade
using test.min.css
(or test.css
):
html
head
!=css('test.min.css')
in 'development' env, it generates/serves test.html
and foo.css
and bar.css
:
<html>
<head>
<link rel="stylesheet" href="foo.css" />
<link rel="stylesheet" href="bar.css" />
but in NOT 'development' env, it generates/serves test.html
test.min.css
(or test.css
):
<html>
<head>
<link rel="stylesheet" href="test.min.css" />
may the SOURCE be with you...
FAQs
Webapp Assets Middleware/Server/Generator for Express
We found that express-webapp-assets demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.