preactjs / wmr

👩‍🚀 The tiny all-in-one development tool for modern web apps.
https://wmr.dev/
MIT License
4.92k stars 109 forks source link

Confusing dist directory behavior #331

Open robdodson opened 3 years ago

robdodson commented 3 years ago

I'm not sure if this is related to #73 but I wanted to log my experience because it took me a while to figure out what was going on. I thought I could run eleventy and have it output to dist/ and then tell wmr to use dist/ as its public directory with the hopes that it would overwrite the files in there. Maybe a bad idea but I didn't realize that under the hood wmr also wants to create a dist/ directory. When I would run my build script, eleventy would create the dist/ dir, and then wmr would delete the dist/ dir and complain that it couldn't find the dist/ dir. I'm assuming this is because wmr starts with a clean step that tries to remove dist/.

I have the following eleventy setup:

package.json

{
  "name": "wmr-eleventy",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "clean": "rm -rf dist",
    "eleventy": "eleventy",
    "wmr:build": "wmr build --public dist",
    "build": "run-s clean eleventy wmr:build"
  },
  "devDependencies": {
    "@11ty/eleventy": "^0.11.1",
    "npm-run-all": "^4.1.5",
    "wmr": "^1.1.0"
  }
}

.eleventy.js

module.exports = function (eleventy) {
  eleventy.addPassthroughCopy('js');

  return {
    dir: {
      input: 'views',
      output: 'dist',
      includes: '../templates/includes',
      layouts: '../templates/layouts',
      data: '../data',
    },
    dataTemplateEngine: 'njk',
    markdownTemplateEngine: 'njk',
    htmlTemplateEngine: 'njk',
    templateEngineOverride: 'njk',
  };
};

I figure the correct sequence of steps would be to have eleventy output to an intermediate dir, like public, and then let wmr work against that. Though it's kind of a bummer to have src -> intermediate -> output in my project.

developit commented 3 years ago

I think there might be a way to do this by customizing the public option to point to dist, but I need to give it a try using your example.