Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to config HtmlWebpackPlugin #1192

Closed
bigopon opened this issue Oct 16, 2018 · 10 comments
Closed

How to config HtmlWebpackPlugin #1192

bigopon opened this issue Oct 16, 2018 · 10 comments

Comments

@bigopon
Copy link

bigopon commented Oct 16, 2018

❔ Question

Link to sandbox: (https://codesandbox.io/s/p7km1z3jlx)

Your Environment

Software Name/Version
Browser Brave

I'm having difficulty making the example in the link above work. The way a normal Aurelia app works is an entry script pointing to module aurelia-bootstrapper, which does all the bootstrapping, and then find element with attribute aurelia-app to find what module it should use for application startup (which in the link above, it's main). I'm not sure what I need to do to have this setup done in Codesandbox way. Could I have some hints for this? I was looking at other framework setup but none seems to use HtmlWebpackPlugin, and it's pretty hard to find where the setup is for Angular, Vue, React, Preact, Svelte

@lbogdan
Copy link
Contributor

lbogdan commented Oct 23, 2018

Hey @bigopon , thanks for opening this issue! We'll probably need to add an Aurelia template, as it seems to be doing some low-level stuff. Cc @CompuIves .

If you want to fiddle around (and maybe add an Aurelia template), you can find the existing templates' configuration here: https://github.com/CompuIves/codesandbox-client/tree/master/packages/common/templates .

You can also take a look at #709 , which is a PR adding templates for CxJS and Dojo.

@EisenbergEffect
Copy link

@lbogdan We are thrilled about the potential of getting Aurelia on CodeSandbox. Once that's setup, we're going to start embedding it directly within our documentation and hopefully our home page as well. We'll also be blogging about it (and using it in our official blog too). It will be great for our community. In light of that, would you be able to assist us a bit more directly in getting the template built out? We've been looking at a few examples but we see a good amount of variation and we aren't sure what the various APIs and settings are doing. @bigopon is the team member that's investigating it on our side.

@lbogdan
Copy link
Contributor

lbogdan commented Oct 27, 2018

@EisenbergEffect Sure, I'll try!
@bigopon Can you please point me to an Aurelia simple app github repo?

@bigopon
Copy link
Author

bigopon commented Oct 27, 2018

@lbogdan Thanks for helping!. I have 2 examples atm:

I can also setup 2 repos for simple / full for JS. Are they good as examples?

@lbogdan
Copy link
Contributor

lbogdan commented Oct 27, 2018

@bigopon @EisenbergEffect

So it looks like Aurelia's underlying development infrastructure is complex enough to require using a server / container template. I've taken your first repo and adapted it to work inside a container sandbox (you can take a look at what I did to achieve that, it's quite simple). This is the route we went with all the other complex frameworks out there (gatsby, next, nuxt).

To make an informed decision, the current pros/cons with this approach are:

  • pros
    • trivial to add an Aurelia server template to CodeSandbox (it would basically ran the same as in your local development environment - only in a container in the cloud - so it would support virtually any webpack configuration)
    • ability to run aurelia-cli inside the container running the sandbox (you'll have to fork my sandbox above to be able to open a terminal inside the container and run commands - ignore the "Connection Trouble" warning after forking, that was fixed in master)
  • cons
    • slower startup time (as we have to start a container, install the modules, run webpack-dev-server etc.)
    • server sandbox limit of 5 per user (as containers are still beta and we want to keep the number of server sandboxes under control)
    • we're using yarn internally (I've seen you're using npm, as you have a package-lock.json inside your example repo)
    • no sync of external file changes (i.e. files added by aurelia-cli) to the sandbox (they won't appear in the file list, so you won't be able to see / edit them) <- this is actually our focus at the moment, and we plan to release this feature sometime next week
    • webpack HMR is not working, as it tries to connect to https://localhost:8080/sockjs-node/... <- this should be easy to fix in webpack config
    • later edit: people have to fork a server sandbox to be able to make changes (and, in turn, to be logged in) - so they won't be able to just play around anonymously in a documentation embed, for example.

Please let me know what your thoughts are about this.

@bigopon
Copy link
Author

bigopon commented Oct 27, 2018

@lbogdan I feel it would require a much simpler version and preferably stay as plain as possible. For example, Html webpack plugin can be removed, if we know how to point index.html to the entry, copy webpack plugin is really needed as static resources can be loaded from CDNs, dynamic resources like CSS can still be bundled like normal. Aurelia webpack plugin can handle that I think. Npm / Yarn also wouldn't matter, as it was just to minimize amount of installations needed. So it would be nice we can have this kind of config to start with:

const { AureliaPlugin } = require('aurelia-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');

module.exports = {
  resolve: {
    extensions: [".ts", ".js"],
    modules: ["src", "node_modules"],
  },
  entry: {
    app: ["aurelia-bootstrapper"],
  },
  module: {
    rules: [
      { test: /\.ts$/, use: 'ts-loader' },
      { test: /\.html$/, loader: 'html-loader' }
    ]
  },
  plugins: [
    new AureliaPlugin(),
    // this can be removed if we can point to `dist/app.bundle.js` and run easily
    new HtmlWebpackPlugin({
      template: 'index.ejs'
    })
  ]
}

For your container example with the ability to have arbitrary webpack configuration, that would be the way to go for members who want to do everything in codesandbox. We probably want to have that too! But our main focus is to have first integration step done before we explore that option. cc @EisenbergEffect

@lbogdan
Copy link
Contributor

lbogdan commented Oct 27, 2018

The thing is that the client bundler is not webpack, but "webpack like", so it doesn't support webpack plugins out of the box (we would have to adapt AureliaPlugin to the bundler, which depending on what it does under the covers, could be quite complex). @CompuIves is the client bundler expert (as he completely wrote it 🙂 ), so I'll let him give you the achievability and pros/conf of the client template approach.

@bigopon
Copy link
Author

bigopon commented Oct 27, 2018

@lbogdan Thanks for that. @lbogdan @CompuIves For the context, I'm not sure if it will help clarify anything, current I'm using 2 base projects:

TS https://codesandbox.io/s/1zk698l74
JS https://codesandbox.io/s/woz49l74y7

@jods4
Copy link

jods4 commented Oct 29, 2018

@lbogdan AureliaPlugin is actually made up of many smaller parts. Some might be easier to reuse than others.
Overall it is deeply integrated with Webpack internal structure (how modules and dependencies are represented internally) so if you are just "webpack like" on the surface, I guess AureliaPlugin not gonna work well out of the box.

@lbogdan
Copy link
Contributor

lbogdan commented Mar 26, 2019

Closing this, as (hopefully) it was solved with the adding of the Aurelia template. Please reopen if that's not the case and I'm in the wrong here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants