Skip to content

Commit

Permalink
fix: support nuxt preview without vite serving allow list
Browse files Browse the repository at this point in the history
close #2287
  • Loading branch information
johnsoncodehk committed Feb 12, 2023
1 parent afe17ca commit 0934463
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
25 changes: 19 additions & 6 deletions packages/preview/bin/nuxi.js
Expand Up @@ -10,12 +10,25 @@ const jsConfigPath = path.resolve(workspace, 'nuxt.config.js');
const tsConfigPath = path.resolve(workspace, 'nuxt.config.ts');

fs.readFileSync = (...args) => {
if (args[0] === jsConfigPath || args[0] === tsConfigPath) {
let configExtraContent = readFileSync(path.resolve(__dirname, 'nuxi', 'configExtraContent.ts'), { encoding: 'utf8' });
configExtraContent = configExtraContent.replace("'{PLUGIN_PATH}'", JSON.stringify(path.resolve(__dirname, 'nuxi', 'plugin.ts')));
return readFileSync(...args) + configExtraContent;
}
return readFileSync(...args);
if (args[0] === jsConfigPath || args[0] === tsConfigPath) {
const configExtraContent = readFileSync(path.resolve(__dirname, 'nuxi', 'configExtraContent.ts'), { encoding: 'utf8' });
return readFileSync(...args) + configExtraContent;
}
return readFileSync(...args);
};

createNuxtPlugin();

import('file://' + nuxiBinPath);

function createNuxtPlugin() {

if (!fs.existsSync(path.resolve(workspace, 'node_modules', '.volar'))) {
fs.mkdirSync(path.resolve(workspace, 'node_modules', '.volar'));
}

const proxyConfigPath = path.resolve(workspace, 'node_modules', '.volar', 'nuxt.plugin.ts');
const pluginContent = fs.readFileSync(path.resolve(__dirname, 'nuxi', 'plugin.ts'), { encoding: 'utf8' });

fs.writeFileSync(proxyConfigPath, pluginContent);
}
2 changes: 1 addition & 1 deletion packages/preview/bin/nuxi/configExtraContent.ts
Expand Up @@ -27,7 +27,7 @@ module.exports.default.vue.compilerOptions.nodeTransforms.push(
if (!module.exports.default.plugins)
module.exports.default.plugins = [];

module.exports.default.plugins.push({ src: '{PLUGIN_PATH}', ssr: false });
module.exports.default.plugins.push({ src: './node_modules/.volar/nuxt.plugin.ts', ssr: false });

function addEvent(node, name: string, exp: string) {
node.props.push({
Expand Down

0 comments on commit 0934463

Please sign in to comment.