question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Creating a separate bundle and requiring css before importing js fails

See original GitHub issue

I’m submitting a bug report

  • Library Version: 0.21.0

Please tell us about your environment:

  • Operating System: Windows 8

  • Node Version: 6.2.2

  • NPM Version: 3.20.5

  • Browser: all

  • Language: ESNext

Current behavior:

I’m trying to bundle a 3rd party library which contains css and js - material-design-lite to be precise. I tried to <require from="material.css"> before any JS is imported.

If I do that, I’m getting the following error:

vendor-bundle.js:4102 GET http://localhost:9000/scripts/mdl-bundle.css 404 (Not Found)

When I import 'material-design-lite' before that, everything is okay. I will add my aurelia.json configuration as an answer to this issue for readability.

Expected/desired behavior:

If the current behavior is a bug, please provide the steps to reproduce.

I will add this information in my first answer to this issue.

  • What is the expected behavior?

Being able to require a css file from a bundle before anything else.

  • What is the motivation / use case for changing the behavior?

Personally, I don’t have a problem with importing js first, but I think this could become a problem in lazy loading scenarios when you use “common chunks” in separate bundles.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
3cpcommented, Aug 12, 2021

FYI, in latest cli bundler, the explicit “path”, “main” are optional, the bundler will try to find from the common place if it’s not set. The “resources” is totally obsolete, the bundler traces files without that “resources” hint.

0reactions
3cpcommented, Aug 12, 2021

There is no such issue in dumber bundler. Also this issue doesn’t exist on latest aurelia-cli bundler which is totally different from the one in v0.21.0.

The bundler setup for latest aurelia-cli:

{
  "name": "mdl-bundle.js",
  "dependencies": [
    "material-design-lite"
  ]
},

If you only want to require css without automatically bundle js main file:

{
  "name": "mdl-bundle.js",
  "dependencies": [
    {
      "name": "material-design-lite",
      "lazyMain": true
    }
  ]
},

As long as you didn’t explicitly import js file, the bundle will only contain that css file.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can I use webpack to generate CSS and JS separately?
The first is to add an extra entry point for main. less, then use the Extract Text plugin to create the CSS bundle:...
Read more >
Code Splitting - webpack
Let's take a look at how we might split another module from the main bundle: project webpack-demo |- package.json |- package-lock.json |- webpack.config.js...
Read more >
Improving JavaScript Bundle Performance With Code-Splitting
So, let's code-split zxcvbn into a separate bundle, dynamically import it and load it only when the password input value changes, i.e. when...
Read more >
How to Bundle a Simple Static Site Using Webpack - SitePoint
And webpack will create a bundle.js file in the dist folder. ... and this file is, in turn, importing another four CSS files....
Read more >
A Guide to Managing Webpack Dependencies - Toptal
The Webpack module bundler processes JavaScript code and all static assets ... styles into separate CSS bundles instead of having them embedded in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found