lhapaipai / vite-plugin-symfony

Vite plugin to use your bundler with Symfony
https://symfony-vite.pentatrion.com
Other
43 stars 11 forks source link

entrypoins duplications and wrong vendor positions #4

Closed FluffyDiscord closed 2 years ago

FluffyDiscord commented 2 years ago

entrypoints.json contains duplicated entries and vendor entries should have higher priority and be at the top or else they will overwrite styles (js seems to be fine)

js "vite": "2.7.13" "vite-plugin-symfony": "0.2.4" (I can't use vite 2.8 and plugin 0.3.0 because vite hangs forever on "vite" command)

php "pentatrion/vite-bundle": "1.2.0"

manifest.json

{
  "app.ts": {
    "file": "app.846b3626.js",
    "src": "app.ts",
    "isEntry": true,
    "imports": [
      "_Review.427f71db.js",
      "_vendor.2cadf0be.js"
    ],
    "css": [
      "app.7e74fc02.css"
    ]
  },
  "admin.ts": {
    "file": "admin.f68184bc.js",
    "src": "admin.ts",
    "isEntry": true,
    "imports": [
      "_vendor.2cadf0be.js",
      "_Review.427f71db.js"
    ],
    "css": [
      "admin.522c4232.css"
    ]
  },
  "_vendor.2cadf0be.js": {
    "file": "vendor.2cadf0be.js",
    "css": [
      "vendor.e55cb455.css"
    ]
  },
  "_Review.427f71db.js": {
    "file": "Review.427f71db.js",
    "imports": [
      "_vendor.2cadf0be.js"
    ]
  }
}

generated entrypoints.json

{
  "isProd": true,
  "entryPoints": {
    "app": {
      "js": [
        "/build/app.846b3626.js"
      ],
      "css": [
        "/build/app.7e74fc02.css", <-- should be last
        "/build/vendor.e55cb455.css", <-- dupe, should be first
        "/build/vendor.e55cb455.css" <-- dupe
      ],
      "preload": [
        "/build/Review.427f71db.js",
        "/build/vendor.2cadf0be.js", <-- dupe
        "/build/vendor.2cadf0be.js" <-- dupe
      ]
    },
    "admin": {
      "js": [
        "/build/admin.f68184bc.js"
      ],
      "css": [
        "/build/admin.522c4232.css", <-- should be last
        "/build/vendor.e55cb455.css", <-- dupe, should be first
        "/build/vendor.e55cb455.css" <-- dupe
      ],
      "preload": [
        "/build/vendor.2cadf0be.js", <-- dupe
        "/build/Review.427f71db.js",
        "/build/vendor.2cadf0be.js" <-- dupe
      ]
    }
  }
}

vite.config.js

import {defineConfig} from "vite"
import symfonyPlugin from "vite-plugin-symfony"
import { svelte } from "@sveltejs/vite-plugin-svelte"
import autoPreprocess from 'svelte-preprocess'
import viteDefineEnvs from "vite-define-envs-plugin"
import { nodeResolve } from '@rollup/plugin-node-resolve'

export default defineConfig({
    plugins: [
        nodeResolve({
            dedupe: ['svelte', 'svelte/transition', 'svelte/internal'],
        }),
        symfonyPlugin(),
        svelte({
            preprocess: autoPreprocess()
        }),
        new viteDefineEnvs(["NODE_ENV"], "process.env"),
    ],
    root: "./assets",
    base: "/build/",
    build: {
        manifest: true,
        emptyOutDir: true,
        assetsDir: "",
        outDir: "../public/build/",
        rollupOptions: {
            input: {
                app: "./app.ts",
                admin: "./admin.ts",
            },
        },
    },
    resolve: {
        alias: [
            {
                find: /^~.+/,
                replacement: (val) => {
                    return val.replace(/^~/, "");
                },
            },
        ],
    },
});
lhapaipai commented 2 years ago

Thanks @FluffyDiscord , I've published for you v0.2.5