Skip to content

Commit eae18c7

Browse files
authored
Feature/vite asset builder (#895)
* Add Vite support for Lucky project generation * Simplify to only support Vite for new projects
1 parent 3c29ba9 commit eae18c7

File tree

46 files changed

+453
-580
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+453
-580
lines changed

fixtures/browser_src_template/expected/bs-config.js

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
{
22
"license": "UNLICENSED",
33
"private": true,
4+
"type": "module",
45
"dependencies": {
56
"@rails/ujs": "^7.1.0",
67
"modern-normalize": "^2.0.0"
78
},
89
"scripts": {
9-
"heroku-postbuild": "yarn prod",
10-
"dev": "yarn run mix",
11-
"watch": "yarn run mix watch",
12-
"prod": "yarn run mix --production"
10+
"heroku-postbuild": "yarn build",
11+
"dev": "vite",
12+
"build": "vite build",
13+
"preview": "vite preview",
14+
"watch": "vite build --watch"
1315
},
1416
"devDependencies": {
15-
"@babel/compat-data": "^7.23.5",
16-
"browser-sync": "^2.29.3",
17-
"compression-webpack-plugin": "^10.0.0",
18-
"laravel-mix": "^6.0.49",
19-
"postcss": "^8.4.32",
20-
"resolve-url-loader": "^5.0.0",
2117
"sass": "^1.69.5",
22-
"sass-loader": "^13.3.2"
18+
"vite": "^5.0.0",
19+
"vite-plugin-compression": "^0.5.1",
20+
"vite-plugin-dev-manifest": "^1.2.1"
2321
}
24-
}
22+
}

fixtures/browser_src_template/expected/public/mix-manifest.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

fixtures/browser_src_template/expected/src/css/app.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//
99
// @import "./variables/colors" # Imports the file in src/css/variables/_colors.scss
1010
//
11-
// Note: importing with `~` tells webpack to look in the installed npm packages
11+
// Note: Vite automatically resolves imports from node_modules
1212
// https://stackoverflow.com/questions/39535760/what-does-a-tilde-in-a-css-url-do
1313

1414
@import 'modern-normalize/modern-normalize.css';
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { defineConfig } from 'vite'
2+
import { resolve } from 'path'
3+
import compression from 'vite-plugin-compression'
4+
import devManifest from 'vite-plugin-dev-manifest'
5+
6+
// https://vitejs.dev/config/
7+
export default defineConfig({
8+
// Root directory is project root (where vite.config.js is)
9+
root: '.',
10+
11+
// Public directory for static assets
12+
publicDir: 'public/assets',
13+
14+
// Build configuration
15+
build: {
16+
// Output directory
17+
outDir: 'public',
18+
// Don't empty the output directory (Lucky serves from public/)
19+
emptyOutDir: false,
20+
// Generate manifest for Lucky asset helpers
21+
manifest: true,
22+
// Define entry points
23+
rollupOptions: {
24+
input: {
25+
// These entry names map to asset paths in Lucky:
26+
// "app" -> asset("js/app.js")
27+
// "styles" -> asset("css/app.scss")
28+
app: resolve(__dirname, 'src/js/app.js'),
29+
styles: resolve(__dirname, 'src/css/app.scss')
30+
}
31+
},
32+
// Asset output configuration
33+
assetsDir: 'assets',
34+
// Source maps for production
35+
sourcemap: process.env.NODE_ENV === 'production' ? false : 'inline'
36+
},
37+
38+
// CSS configuration
39+
css: {
40+
devSourcemap: true
41+
},
42+
43+
// Server configuration for development
44+
server: {
45+
// This allows Vite to be accessed from Lucky's dev server
46+
origin: 'http://localhost:3001',
47+
port: 3001,
48+
strictPort: true,
49+
// Enable HMR
50+
hmr: {
51+
host: 'localhost'
52+
}
53+
},
54+
55+
// Preview server configuration (for testing production builds)
56+
preview: {
57+
port: 3001
58+
},
59+
60+
// Plugins
61+
plugins: [
62+
// Generate dev manifest for Lucky's compile-time asset validation
63+
devManifest({
64+
manifestName: 'manifest.dev',
65+
clearOnClose: false
66+
}),
67+
// Gzip compression for production builds
68+
process.env.NODE_ENV === 'production' && compression({
69+
algorithm: 'gzip',
70+
ext: '.gz',
71+
threshold: 1024,
72+
}),
73+
// Add Brotli compression if desired
74+
// process.env.NODE_ENV === 'production' && compression({
75+
// algorithm: 'brotliCompress',
76+
// ext: '.br',
77+
// threshold: 1024,
78+
// }),
79+
].filter(Boolean),
80+
81+
// Resolve configuration
82+
resolve: {
83+
alias: {
84+
'@': resolve(__dirname, 'src')
85+
}
86+
}
87+
})

fixtures/browser_src_template/expected/webpack.mix.js

Lines changed: 0 additions & 113 deletions
This file was deleted.

fixtures/browser_src_template__generate_auth/expected/bs-config.js

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
{
22
"license": "UNLICENSED",
33
"private": true,
4+
"type": "module",
45
"dependencies": {
56
"@rails/ujs": "^7.1.0",
67
"modern-normalize": "^2.0.0"
78
},
89
"scripts": {
9-
"heroku-postbuild": "yarn prod",
10-
"dev": "yarn run mix",
11-
"watch": "yarn run mix watch",
12-
"prod": "yarn run mix --production"
10+
"heroku-postbuild": "yarn build",
11+
"dev": "vite",
12+
"build": "vite build",
13+
"preview": "vite preview",
14+
"watch": "vite build --watch"
1315
},
1416
"devDependencies": {
15-
"@babel/compat-data": "^7.23.5",
16-
"browser-sync": "^2.29.3",
17-
"compression-webpack-plugin": "^10.0.0",
18-
"laravel-mix": "^6.0.49",
19-
"postcss": "^8.4.32",
20-
"resolve-url-loader": "^5.0.0",
2117
"sass": "^1.69.5",
22-
"sass-loader": "^13.3.2"
18+
"vite": "^5.0.0",
19+
"vite-plugin-compression": "^0.5.1",
20+
"vite-plugin-dev-manifest": "^1.2.1"
2321
}
24-
}
22+
}

fixtures/browser_src_template__generate_auth/expected/public/mix-manifest.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

fixtures/browser_src_template__generate_auth/expected/src/css/app.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//
99
// @import "./variables/colors" # Imports the file in src/css/variables/_colors.scss
1010
//
11-
// Note: importing with `~` tells webpack to look in the installed npm packages
11+
// Note: Vite automatically resolves imports from node_modules
1212
// https://stackoverflow.com/questions/39535760/what-does-a-tilde-in-a-css-url-do
1313

1414
@import 'modern-normalize/modern-normalize.css';

0 commit comments

Comments
 (0)