Giter Club home page Giter Club logo

express-middleware-rollup's People

Contributors

cognitom avatar dependabot[bot] avatar jharris4 avatar suluke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

express-middleware-rollup's Issues

Discussion: Automatic directory creation

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.

Update Readme to mention polyfill mode

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.

How to serve static&cached file from different location.

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.

Proposal: cache dir instead of src and dest

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:

  • More straightforward
  • We could simply remove the middleware after the native support on browsers

If you like it, I'd like to send some PRs. I also have some other ideas. Thanks πŸ˜‰

co?

@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;
  }
}

Some plugins insert dependencies not on the file system

rollup-plugin-commonjs inserts a helper dependency \u0000commonjsHelpers.
I think we need to filter such id which has no valid paths.

  • usual dependencies: { id: '/path/to/marked/lib/marked.js' }
  • inserted dependencies: { 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');

Discussion: Pre cache

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.

Discussion: Multiple bundles support (Globs?)

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

Discussion: Option to configure request urls the middleware responds to

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.