-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bundle up vite plugins in a nicer way
- Loading branch information
Showing
4 changed files
with
71 additions
and
65 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { hbs } from './hbs.js'; | ||
import { scripts } from './scripts.js'; | ||
import { compatPrebuild } from './build.js'; | ||
import { assets } from './assets.js'; | ||
import { contentFor } from './content-for.js'; | ||
|
||
export function classicEmberSupport() { | ||
return [hbs(), scripts(), compatPrebuild(), assets(), contentFor()]; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { templateTag } from './template-tag.js'; | ||
import { resolver } from './resolver.js'; | ||
import { mergeConfig, type UserConfig, type ConfigEnv } from 'vite'; | ||
import { esBuildResolver } from './esbuild-resolver.js'; | ||
|
||
export let extensions = ['.mjs', '.gjs', '.js', '.mts', '.gts', '.ts', '.hbs', '.hbs.js', '.json']; | ||
|
||
export function ember() { | ||
return [ | ||
templateTag(), | ||
resolver(), | ||
{ | ||
name: 'vite-plugin-ember-config', | ||
async config(config: UserConfig, env: ConfigEnv) { | ||
return mergeConfig( | ||
{ | ||
resolve: { | ||
extensions, | ||
}, | ||
|
||
optimizeDeps: { | ||
exclude: ['@embroider/macros'], | ||
extensions: ['.hbs', '.gjs', '.gts'], | ||
esbuildOptions: { | ||
plugins: [esBuildResolver()], | ||
}, | ||
}, | ||
|
||
build: { | ||
rollupOptions: { | ||
input: { | ||
main: 'index.html', | ||
...(shouldBuildTests(env.mode) ? { tests: 'tests/index.html' } : undefined), | ||
}, | ||
}, | ||
}, | ||
server: { | ||
port: 4200, | ||
}, | ||
}, | ||
config | ||
); | ||
}, | ||
}, | ||
]; | ||
} | ||
|
||
function shouldBuildTests(mode: string) { | ||
return mode !== 'production' || process.env.FORCE_BUILD_TESTS; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,15 @@ | ||
import { defineConfig } from "vite"; | ||
import { | ||
resolver, | ||
hbs, | ||
scripts, | ||
templateTag, | ||
optimizeDeps, | ||
compatPrebuild, | ||
assets, | ||
contentFor, | ||
} from "@embroider/vite"; | ||
import { resolve } from "path"; | ||
import { extensions, classicEmberSupport, ember } from "@embroider/vite"; | ||
import { babel } from "@rollup/plugin-babel"; | ||
|
||
export default defineConfig(({ mode }) => { | ||
return { | ||
cacheDir: resolve("node_modules", ".vite"), | ||
resolve: { | ||
extensions: [ | ||
".mjs", | ||
".gjs", | ||
".js", | ||
".mts", | ||
".gts", | ||
".ts", | ||
".hbs", | ||
".hbs.js", | ||
".json", | ||
], | ||
}, | ||
plugins: [ | ||
hbs(), | ||
templateTag(), | ||
scripts(), | ||
resolver(), | ||
compatPrebuild(), | ||
assets(), | ||
contentFor(), | ||
export default defineConfig({ | ||
plugins: [ | ||
classicEmberSupport(), | ||
ember(), | ||
|
||
babel({ | ||
babelHelpers: "runtime", | ||
|
||
// this needs .hbs because our hbs() plugin above converts them to | ||
// javascript but the javascript still also needs babel, but we don't want | ||
// to rename them because vite isn't great about knowing how to hot-reload | ||
// them if we resolve them to made-up names. | ||
extensions: [".gjs", ".js", ".hbs", ".ts", ".gts"], | ||
}), | ||
], | ||
optimizeDeps: optimizeDeps(), | ||
server: { | ||
port: 4200, | ||
}, | ||
build: { | ||
outDir: "dist", | ||
rollupOptions: { | ||
input: { | ||
main: "index.html", | ||
...(shouldBuildTests(mode) | ||
? { tests: "tests/index.html" } | ||
: undefined), | ||
}, | ||
}, | ||
}, | ||
}; | ||
babel({ | ||
babelHelpers: "runtime", | ||
extensions, | ||
}), | ||
], | ||
}); | ||
|
||
function shouldBuildTests(mode) { | ||
return mode !== "production" || process.env.FORCE_BUILD_TESTS; | ||
} |