gpt4 book ai didi

javascript - Typescript RequireJs 快捷键 + 导航

转载 作者:行者123 更新时间:2023-12-03 12:37:12 29 4
gpt4 key购买 nike

我定义了这些 requireJs 选项:

require.config({
baseUrl: '/js/',
paths: {
jquery: '/components/jquery/dist/jquery',
foundation: '/components/foundation/js/foundation',
fastclick: '/components/fastclick/lib/fastclick',
angular: '/components/angular/angular',
angularRoute: '/components/angular-route/angular-route',
socketIO: '/components/socket.io-client/dist/socket.io'
},

shim: {
'foundation': {
deps: ['jquery', 'fastclick']
},
'angular': {'exports': 'angular'},
'angularRoute': ['angular']
},
priority: [
'angular'
]

});

如果我在 javascript 语法中使用 requireJs,这些工作一切正常。然后基本 url 和所有这些外部库的好快捷方式就可以工作了。

但我现在问你是否也可以以 Typescript 的方式使用这些快捷方式。因为如果我说:例如在文件中

import angular = require('angular');

它没有导入文件。我正在使用 amd 选项编译源代码。

有人可以为我提供如何使用这些导入语句浏览项目的链接。 my folder structure for client-side code

这个结构是我当前项目使用的结构。那里有一个客户端(公共(public))文件夹,如果我想在浏览器中访问 js 文件。我必须写:localhost/js/file.js现在,当我在 js 语法中使用 requireJs 时,我可以轻松编写诸如controllers/userController之类的内容,并且它导航到正确的文件夹,但是我如何在我的 import/require 中导航?目前我必须使用我正在使用导入的文件的相对路径,但这不是很明智

最佳答案

我这样做是为了让它发挥作用:)

/// <reference path="./types/angular/angular.d.ts" />
declare module 'angular'{
var angular:ng.IAngularStatic;
export = angular;
}

// now you can do:
import angular = require('angular');

关于javascript - Typescript RequireJs 快捷键 + 导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23686579/

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