suluke / express-middleware-rollup Goto Github PK
View Code? Open in Web Editor NEWExpress middleware for rollup
License: MIT License
Express middleware for rollup
License: MIT License
I think we can safely implement this if we make it configurable via an autoCreateDirectories option. This option could be off by default in compile mode but on in polyfill mode or something. And of course we can have the users decide whether they are ok with the directories being created.
The document needs some restructuring to mention that there are two concepts for operating this middleware and it must also reflect that there are different option sets for each of the modes.
Hi, my rollup init is this:
app.use(rollup({
mode: 'polyfill',
src: './',
root: __dirname,
cache: '../bin',
}));
app.use(express.static(path.join(__dirname, '../bin')));
The JS file is on app/base/public/js/main.js
.
My goal is, to get the main.js file from /static/js/main.js
instead of /base/public/js/main.js
in my html file.
How can i accomplish this?
// Edit
The same is possible with the postcss-middleware.
app.use('/static/css', postcssMiddleware({
src: request => path.join(__dirname, '**/public/css', request.path),
plugins: [ cssnext, ],
}));
Here i can access my css files via /static/css/main.css
.
But it's OK on the third time.
Currently the cache is only handled in checkNeedsRebuild()
but it seems that we need to handle it in processBundle()
or writeBundle()
, too.
https://github.com/suluke/express-middleware-rollup/blob/master/index.js
Hi @suluke, nice work! I like the idea behind this library, so much π
After some trial, src/dest
seems a bit redundant for me. I'm thinking another structure like below. Thoughts?
.
βββ server.js
βββ public
β βββindex.html
β βββ main.js # source file
β βββ lib
β βββ test.js
βββ cache
βββ main.js # bundled and compiled
And the code could be like this:
app.use(rollup({
root: 'public',
cache: 'cache'
}));
Pros:
If you like it, I'd like to send some PRs. I also have some other ideas. Thanks π
@suluke could you have a look at this, when you have a time?
https://github.com/cognitom/express-middleware-rollup/blob/co/lib/express-rollup.js
My attempt with co. I realized that it might make the logic simple, without promise hell.
If you like it I'll be pleased send a PR, though the main purpose why I started this refactoring was for just code-reading for myself π
For example:
*writeBundle(code, map, dest) {
try {
const stats = yield fsp.stat(dirname(dest));
if (!stats.isDirectory()) {
throw new Error('Directory to write to does not exist (not a directory)');
}
yield fsp.writeFile(dest, code);
if (map) {
yield fsp.writeFile(`${dest}.map`, map);
}
} catch (err) {
throw err;
}
}
rollup-plugin-commonjs
inserts a helper dependency \u0000commonjsHelpers
.
I think we need to filter such id which has no valid paths.
{ id: '/path/to/marked/lib/marked.js' }
{ id: '\u0000commonjsHelpers' }
At this point, the quick fix could be like this around this line:
const dependencies = bundle.modules
.map(module => module.id)
.filter(id => id[0] !== '\u0000');
BublΓ© made the process much faster than Babel. But still it takes 0.5 sec to 1.5 sec (depends on the code size) to transpilation in my environment. One workaround for this latency might be "pre cache".
How about such options like this?
app.use(rollup({
mode: 'polyfill',
src: 'public',
preCache: '*.js' // string or array of globs
}));
Then, the JavaScript files on the root dir would be automatically rolluped while starting up. It would be watched and re-rolluped when the file gets update.
In #14 an interesting use case is described:
When you have multiple bundles in separate directories, you may want to introduce a convention that a certain pattern in a path is always mapped onto a module.
For example, we have this layout:
- bundle 1
- assets
- js
-bundle2
- assets
- js
Then we want to map **/js/main.js
to the URL /js/<glob_match>.js
. I think this may be a bit complicated to implement. But let's think about it so we can come up with a solution
Hi there,
Can you publish the current state of master
as a new version to npm? v1.1.0
still has rollup@^0.26.2
as its dependency, which has a bug in it (it creates a var extends
variable which causes problems).
Thanks,
Brekk
Currently, we hard code a regex called extRegex
to match against incoming requests' urls for decising whether or not we are responsible for handling it. This could either be a deliberate limitation, or we should implement an option to change how we distinguish between requests we respond to and other requests.
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.