|
1 | 1 | import MagicString from 'magic-string';
|
2 | 2 | import { colors, defineAddon, defineAddonOptions, log } from '@sveltejs/cli-core';
|
3 |
| -import { |
4 |
| - array, |
5 |
| - common, |
6 |
| - functions, |
7 |
| - imports, |
8 |
| - object, |
9 |
| - variables, |
10 |
| - exports, |
11 |
| - kit as kitJs |
12 |
| -} from '@sveltejs/cli-core/js'; |
| 3 | +import { common, imports, variables, exports, kit as kitJs, vite } from '@sveltejs/cli-core/js'; |
13 | 4 | import * as html from '@sveltejs/cli-core/html';
|
14 | 5 | import { parseHtml, parseJson, parseScript, parseSvelte } from '@sveltejs/cli-core/parsers';
|
15 | 6 | import { addToDemoPage } from '../common.ts';
|
@@ -94,26 +85,13 @@ export default defineAddon({
|
94 | 85 | const { ast, generateCode } = parseScript(content);
|
95 | 86 |
|
96 | 87 | const vitePluginName = 'paraglideVitePlugin';
|
97 |
| - imports.addNamed(ast, { |
98 |
| - from: '@inlang/paraglide-js', |
99 |
| - imports: [vitePluginName] |
100 |
| - }); |
101 |
| - const { value: rootObject } = exports.createDefault(ast, { |
102 |
| - fallback: functions.createCall({ name: 'defineConfig', args: [] }) |
103 |
| - }); |
104 |
| - const param1 = functions.getArgument(rootObject, { |
105 |
| - index: 0, |
106 |
| - fallback: object.create({}) |
107 |
| - }); |
108 |
| - |
109 |
| - const pluginsArray = object.property(param1, { name: 'plugins', fallback: array.create() }); |
110 |
| - const pluginFunctionCall = functions.createCall({ name: vitePluginName, args: [] }); |
111 |
| - const pluginConfig = object.create({ |
112 |
| - project: './project.inlang', |
113 |
| - outdir: `./${paraglideOutDir}` |
| 88 | + imports.addNamed(ast, { imports: [vitePluginName], from: '@inlang/paraglide-js' }); |
| 89 | + vite.addPlugin(ast, { |
| 90 | + code: `${vitePluginName}({ |
| 91 | + project: './project.inlang', |
| 92 | + outdir: './${paraglideOutDir}' |
| 93 | + })` |
114 | 94 | });
|
115 |
| - functions.getArgument(pluginFunctionCall, { index: 0, fallback: pluginConfig }); |
116 |
| - array.append(pluginsArray, pluginFunctionCall); |
117 | 95 |
|
118 | 96 | return generateCode();
|
119 | 97 | });
|
|
0 commit comments