rails-vite-plugin 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +13 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10,7 +10,8 @@ export const refreshPaths = [
|
|
|
10
10
|
let exitHandlersBound = false;
|
|
11
11
|
export default function rails(options = {}) {
|
|
12
12
|
const sourceDir = options.sourceDir ?? 'app/javascript';
|
|
13
|
-
const
|
|
13
|
+
const entrypointsDir = options.input === undefined ? detectEntrypointsDir(sourceDir) : null;
|
|
14
|
+
const input = options.input ?? (entrypointsDir ? discoverEntrypointInputs(sourceDir, entrypointsDir) : detectEntrypoint(sourceDir));
|
|
14
15
|
const publicDirectory = options.publicDirectory ?? 'public';
|
|
15
16
|
const buildDirectory = options.buildDirectory ?? 'vite';
|
|
16
17
|
const devMetaPath = options.devMetaFile ?? path.join('tmp', 'rails-vite.json');
|
|
@@ -67,7 +68,7 @@ export default function rails(options = {}) {
|
|
|
67
68
|
if (resolvedConfig.build.ssr)
|
|
68
69
|
return;
|
|
69
70
|
const outDir = resolvedConfig.build.outDir;
|
|
70
|
-
fs.writeFileSync(path.join(outDir, 'rails-vite.json'), JSON.stringify({ sourceDir }));
|
|
71
|
+
fs.writeFileSync(path.join(outDir, 'rails-vite.json'), JSON.stringify(entrypointsDir ? { sourceDir, entrypointsDir } : { sourceDir }));
|
|
71
72
|
},
|
|
72
73
|
configureServer(server) {
|
|
73
74
|
server.httpServer?.once('listening', () => {
|
|
@@ -76,6 +77,8 @@ export default function rails(options = {}) {
|
|
|
76
77
|
const devServerUrl = resolveDevServerUrl(address, resolvedConfig);
|
|
77
78
|
resolvedConfig.server.origin = devServerUrl;
|
|
78
79
|
const meta = { url: devServerUrl, sourceDir };
|
|
80
|
+
if (entrypointsDir)
|
|
81
|
+
meta.entrypointsDir = entrypointsDir;
|
|
79
82
|
if (reactRefresh)
|
|
80
83
|
meta.reactRefresh = true;
|
|
81
84
|
fs.writeFileSync(devMetaPath, JSON.stringify(meta));
|
|
@@ -135,11 +138,15 @@ function prefixWithSourceDir(entry, sourceDir) {
|
|
|
135
138
|
return `${sourceDir}/${entry}`;
|
|
136
139
|
}
|
|
137
140
|
const entrypointExtensions = /\.(mjs|js|mts|ts|jsx|tsx|css|scss|sass|less|styl|pcss)$/;
|
|
138
|
-
function
|
|
141
|
+
function detectEntrypointsDir(sourceDir) {
|
|
139
142
|
const entrypointsDir = path.join(sourceDir, 'entrypoints');
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
+
return fs.existsSync(entrypointsDir) ? 'entrypoints' : null;
|
|
144
|
+
}
|
|
145
|
+
function discoverEntrypointInputs(sourceDir, entrypointsDir) {
|
|
146
|
+
const absDir = path.join(sourceDir, entrypointsDir);
|
|
147
|
+
return discoverEntrypoints(absDir).map((entry) => `${entrypointsDir}/${entry}`);
|
|
148
|
+
}
|
|
149
|
+
function detectEntrypoint(sourceDir) {
|
|
143
150
|
for (const ext of ['.js', '.mjs', '.ts', '.mts', '.jsx', '.tsx']) {
|
|
144
151
|
const candidate = path.join(sourceDir, `application${ext}`);
|
|
145
152
|
if (fs.existsSync(candidate)) {
|