我想要我的文件总是由我的项目的根目录而不是相对于当前模块.
例如,如果你看看https://github.com/visionmedia/express/blob/2820f2227de0229c5d7f28009aa432f9f3a7b5f9/examples/downloads/app.js第6行,你会看到
express = require('../../')
Run Code Online (Sandbox Code Playgroud)
这真是糟糕的IMO.想象一下,我想把我的所有例子都放在根目录上,只有一个级别.这是不可能的,因为我必须在每个示例中更新超过30个示例和多次.对此:
express = require('../')
Run Code Online (Sandbox Code Playgroud)
我的解决方案是基于root的特殊情况:如果一个字符串以$开头,那么它相对于项目的根文件夹.
任何帮助表示赞赏,谢谢
现在我正在使用require.js,它允许您以一种方式编写,并在客户端和服务器上运行.Require.js还允许您创建自定义路径.-«
现在我转到webpack + gulp,我使用enhanced-require来处理服务器端的模块.请参阅此处的基本原理:http://hackhat.com/p/110/module-loader-webpack-vs-requirejs-vs-browserify/
按照此解决方案,我正在通过的baseUrl编译器选项使用相对于根的导入,但是我遇到了一个问题,其中Atom IDE向我显示了如下看起来的错误:tsconfig.json
Cannot find module 'core/nav-menu/nav-menu.component'.
导入看起来像(在中src/app/core/nav-menu.module.ts):
import { NavMenuComponent } from 'core/nav-menu/nav-menu.component';
Run Code Online (Sandbox Code Playgroud)
Atom中的TSLint找不到相对于根目录的导入文件,但是Angular编译器没有问题。
我不确定我的tslint.json配置是否错误...一切都在我在同一台机器上的另一个项目中按预期工作,但是我无法发现该项目的不同之处,从而导致了此问题。
tslint.json:
{
"rulesDirectory": [
"node_modules/codelyzer"
],
"rules": {
"arrow-return-shorthand": true,
"callable-types": true,
"class-name": true,
"comment-format": [
true,
"check-space"
],
"curly": true,
"deprecation": {
"severity": "warn"
},
"eofline": true,
"forin": true,
"import-blacklist": [
true,
"rxjs/Rx"
],
"import-spacing": true,
"indent": [
true,
"spaces"
],
"interface-over-type-literal": true,
"label-position": true,
"max-line-length": [
true,
140
],
"member-access": false,
"member-ordering": [
true, …Run Code Online (Sandbox Code Playgroud)