gpt4 book ai didi

node.js - Neutrinojs/vue 项目 : Importing vue files/templates from root folder

转载 作者:搜寻专家 更新时间:2023-10-30 22:10:59 24 4
gpt4 key购买 nike

我想从根文件夹开始导入,而不是往下几个文件夹。我该怎么做?

我在尝试为我的主页导入留言簿(比如 1999 年)脚本时遇到了这个问题。

import MyGuestbook from '../../components/MyGuestbook.vue' 编译。

从 '/src/components/MyGuestbook.vue' 导入 MyGuestbook 不会。

import MyGuestbook from '@/components/MyGuestbook.vue' 也没有。

GuestBookPage.vue

<template>
<div>
<MyGuestbook />
</div>
</template>

<script>
import MyGuestbook from '../../components/MyGuestbook.vue'

export default {
name: 'GuestbookPage',
components: {
MyGuestbook
}
};
</script>

MyGuestbook.vue

<template>
</div>
</div>
</template>

<script src="non-editable-comments-v0.1.0.js"></script>
<script>
window.safeComments('CommentTitle', 'CommentTargetID');

export default {
name: 'MyGuestbook'
};
</script>

[更新]

我知道我需要使用webpack,但是我的项目使用neutrinojs/vue(项目类型推荐)结合webpack。我对他们两个都不熟悉。到目前为止,添加 webpack.config.js 还没有奏效。

webpack.config.js

module.exports = {
resolve: {
extensions: [
'.js', '.vue', '.json'
],
alias: {
'@': resolve('src'),
'@root': resolve('.')
}
}
};

也没有编辑 .neutrinorc.js

module.exports = {
use: [
'@neutrinojs/standardjs',
[
'@neutrinojs/vue',
{
html: {
title: 'MySite'
}
}
],
'@neutrinojs/jest',
(neutrino) => {
neutrino.config.resolve.extensions
.add('.js')
.add('.json')
.add('.vue');

neutrino.config.resolve.alias
.set('@', 'src')
.set('@root', '.');
}
]
};

错误:

ERROR in ./node_modules/@neutrinojs/compile-loader/node_modules/babel-loader/lib?{"cacheDirectory":true,
"plugins":[["/home/folatt/Cloud/workspace/atom/Sites/MySite/node_modules/fast-async/plugin.js",
{"spec":true}],
"/home/folatt/Cloud/workspace/atom/Sites/MySite/node_modules/babel-plugin-syntax-dynamic-import/lib/index.js",
"/home/folatt/Cloud/workspace/atom/Sites/MySite/node_modules/babel-plugin-transform-object-rest-spread/lib/index.js"],
"presets":[["/home/folatt/Cloud/workspace/atom/Sites/MySite/node_modules/babel-preset-env/lib/index.js",
{"debug":false,"modules":false,
"useBuiltIns":true,"exclude":["transform-regenerator",
"transform-async-to-generator"],
"targets":{"browsers":[
"last 2 Chrome versions",
"last 2 Firefox versions",
"last 2 Edge versions",
"last 2 Opera versions",
"last 2 Safari versions",
"last 2 iOS versions"]}}]]}!.
/node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/docs/7.forum/GuestbookPage.vue
Module not found: Error: Can't resolve '@/components/YroGuestbook.vue' in '/home/folatt/Cloud/workspace/atom/Sites/MySite/src/docs/7.forum'
@ ./node_modules/@neutrinojs/compile-loader/node_modules/babel-loader/lib?{"cacheDirectory":true,
"plugins":[["/home/folatt/Cloud/workspace/atom/Sites/MySite/node_modules/fast-async/plugin.js",
{"spec":true}],
"/home/folatt/Cloud/workspace/atom/Sites/MySite/node_modules/babel-plugin-syntax-dynamic-import/lib/index.js",
"/home/folatt/Cloud/workspace/atom/Sites/MySite/node_modules/babel-plugin-transform-object-rest-spread/lib/index.js"],
"presets":[["/home/folatt/Cloud/workspace/atom/Sites/MySite/node_modules/babel-preset-env/lib/index.js",
{"debug":false,"modules":false,"useBuiltIns":true,
"exclude":["transform-regenerator","transform-async-to-generator"],
"targets":{"browsers":["last 2 Chrome versions",
"last 2 Firefox versions",
"last 2 Edge versions",
"last 2 Opera versions",
"last 2 Safari versions",
"last 2 iOS versions"]}}]]}!.
/node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/docs/7.forum/GuestbookPage.vue 8:0-57
@ ./src/docs/7.forum/GuestbookPage.vue
@ ./src/router/index.js
@ ./src/index.js
@ multi ./node_modules/webpack-dev-server/client?http://localhost:5000 ./node_modules/@neutrinojs/web/node_modules/webpack/hot/dev-server.js ./src/index

最佳答案

我错过了整个 babel-plugin 的东西。

yarn add babel-plugin-root-import -dev

.babelrc

{
"plugins": [
["babel-plugin-root-import", {
"rootPathSuffix": "src",
"rootPathPrefix": "@"
}]
]
}

我无法让别名解析起作用,但这确实似乎起作用。

关于node.js - Neutrinojs/vue 项目 : Importing vue files/templates from root folder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51916500/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com