Created
February 21, 2021 19:32
-
-
Save owenconti/3c40456e18bdffed7a0960dcdb00f8b4 to your computer and use it in GitHub Desktop.
Replacing Laravel Mix with Vite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createVuePlugin as Vue2Plugin } from 'vite-plugin-vue2'; | |
const { resolve } = require('path'); | |
const Dotenv = require('dotenv'); | |
Dotenv.config(); | |
const ASSET_URL = process.env.ASSET_URL || ''; | |
export default { | |
plugins: [ | |
Vue2Plugin(), | |
], | |
root: 'resources', | |
base: `${ASSET_URL}/dist/`, | |
build: { | |
outDir: resolve(__dirname, 'public/dist'), | |
emptyOutDir: true, | |
manifest: true, | |
target: 'es2018', | |
rollupOptions: { | |
input: '/js/app.js' | |
} | |
}, | |
server: { | |
strictPort: true, | |
port: 3000 | |
}, | |
resolve: { | |
alias: { | |
'@': '/js', | |
} | |
}, | |
optimizeDeps: { | |
include: [ | |
'vue', | |
'portal-vue', | |
'@inertiajs/inertia', | |
'@inertiajs/inertia-vue', | |
'@inertiajs/progress', | |
'axios' | |
] | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import vue from '@vitejs/plugin-vue'; | |
const { resolve } = require('path'); | |
const Dotenv = require('dotenv'); | |
Dotenv.config(); | |
const ASSET_URL = process.env.ASSET_URL || ''; | |
export default { | |
plugins: [ | |
vue(), | |
], | |
root: 'resources', | |
base: `${ASSET_URL}/dist/`, | |
build: { | |
outDir: resolve(__dirname, 'public/dist'), | |
emptyOutDir: true, | |
manifest: true, | |
target: 'es2018', | |
rollupOptions: { | |
input: '/js/app.js' | |
} | |
}, | |
server: { | |
strictPort: true, | |
port: 3000 | |
}, | |
resolve: { | |
alias: { | |
'@': '/js', | |
} | |
}, | |
optimizeDeps: { | |
include: [ | |
'vue', | |
'@inertiajs/inertia', | |
'@inertiajs/inertia-vue', | |
'@inertiajs/progress', | |
'axios' | |
] | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm uninstall laravel-mix | |
rm webpack.mix.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
composer require ohseesoftware/laravel-vite-manifest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Running locally | |
APP_ENV=local | |
ASSET_URL=http://localhost:3000 | |
// Running production build | |
APP_ENV=production | |
ASSET_URL=https://your-asset-domain.com |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"scripts": { | |
"start": "vite", | |
"production": "vite build" | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// postcss.config.js | |
module.exports = { | |
plugins: [ | |
require('postcss-import'), | |
require('tailwindcss'), | |
require('autoprefixer'), | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install --save-dev vite @vitejs/plugin-vue dotenv @vue/compiler-sfc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// app.blade.php | |
<head> | |
// ... rest of head contents here | |
@vite | |
</head> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How about frontend imports? How do we transform those? I mean something like:
<link rel="stylesheet" type="text/css" href="{{ mix('css/mail.css') }}">
How does that change with vite?