我一直在尝试将我的 TypeScript“应用程序”捆绑到一个 javascript 文件中。
我没有使用任何捆绑器,而是 TSC(使用 TypeScript 2.2)。除了我自己的 ts 文件之外,我的应用程序还使用了 immutablejs 等外部模块。
我阅读了所有可能的线程、文档,但找不到仅使用 TSC 将外部模块(来自 node_modules )捆绑到我编译/转译的 javascript 文件的方法。
在下面,您可以找到我的最新代码/配置示例以及我的尝试结果。
配置文件
{
"compilerOptions": {
"target": "es5",
"module": "system",
"removeComments": true,
"sourceMap": true,
"allowJs": true
}
}
Run Code Online (Sandbox Code Playgroud)
app.ts - 注意:./something.ts 已成功绑定。
/// <reference path="../node_modules/immutable/dist/immutable.d.ts" />
import * as something from "./something";
import * as Immutable from "immutable";
console.log( something.test );
const map1 = Immutable.Map( { a: 1, b: '2', c: 'cu' });
console.log( map1.get( 'a') )
Run Code Online (Sandbox Code Playgroud)
1#:使用 tsc-bundle ( https://www.npmjs.com/package/typescript-bundle ) …
通过npm i resize-start-end -S'.
这是包提供的说明:
// ESM
import resizeStartEnd from 'resize-start-end';
// or CommonJS
const resizeStartEnd = require('resize-start-end');
Run Code Online (Sandbox Code Playgroud)
我正在尝试将该包包含在我的 Hugo 静态目录中的 JS 文件中。以上都不起作用(找不到)。
我的 js 位于static/src/js并且 gulp 将它连接到static/js.
建议表示赞赏。
我有一个前端构建,它使用 Dockerfile 的变体进行多个步骤:开发、CI(使用 Jenkins)和生产。我不想连续下载用于 CI 和生产构建映像的 node_modules(这两者都在同一个盒子上连续发生)。Dev 的 node_modules 托管在一个卷上,以降低重新启动开发容器的开销。
这三个阶段都共享同一个.dockerignore文件,其中有一行不包括node_modules. 是否可以通过类似的方式添加 node_modules COPY node_modules/* node_modules/?我徒劳地寻找在 CI 和生产构建的构建部分期间使用绑定安装的方法。这似乎是不可能的。
我正在使用运行 Node v8.11.3 的 Gatsby v1.1.52。
当我运行时,gatsby serve我收到一条消息,提示我有一个UPDATE AVAILABLE: The latest version ofserve is 9.1.0。我试过跑步npm update -g gatsby' and 'npm update -g gatsby-cli。
我找不到任何文档:手册条目不存在,选项 ( gatsby ?) 不包含更新命令,gatsby serve ?只能再次为网站提供服务。
我找到了一个名为 serve 的全局 npm 包,但它在 5.6.0 版上,我认为它与本例中引用的包不同,但我在这里抓住了稻草。
任何想法我需要运行什么命令才能更新serve?
npm install 后出现此错误:
+-- 未满足对等依赖@angular/common@6.1.10
+-- 未满足对等依赖 @angular/core@6.1.10
`--文件保护程序@1.3.8
编译后得到这个错误:
./node_modules/@agm/core/fesm5/agm-core.js 4538:120-128 中的警告“在'@angular/core'中找不到导出'??inject'
./node_modules/@agm/core/fesm5/agm-core.js 4538:34-52 中的警告“在‘@angular/core’中找不到导出‘??defineInjectable’
我的 package.json 是:
{
"name": "web-app",
"version": "2.1.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"ng": "ng",
"start": "ng serve",
"public": "ng serve --port 8080 --host 0.0.0.0",
"build": "ng build --prod --build-optimizer",
"lint": "tslint \"src/**/*.ts\"",
"test": "ng test",
"pree2e": "webdriver-manager update --standalone false --gecko false",
"e2e": "protractor"
},
"private": true,
"dependencies": {
"@agm/core": "^1.0.0-beta.2",
"@angular/animations": "^6.1.10",
"@angular/cdk": "^6.4.7",
"@angular/common": "^6.1.10",
"@angular/compiler": "^6.1.0",
"@angular/core": …Run Code Online (Sandbox Code Playgroud) 在我的package.json文件中,我指定了我的nodejs应用程序的类型module,因为如果我不这样做,似乎我不能使用import语句。这是现在的样子:
{
"name": "...",
"version": "1.0.0",
"description": "....",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "...."
},
"author": "",
"license": "ISC",
"devDependencies": {
"lodash": "^4.17.15"
},
"type": "module"
}
Run Code Online (Sandbox Code Playgroud)
但是如果我将"type": "module"加到我的package.json文件中,我就不能再使用require语句了,因为我得到了一个ReferenceError: require is not defined错误。
如果我"type": "module"从package.json 中删除该行,并将所有导入重写为 requires,则一切正常,没有错误。
我似乎无法找到任何迹象,这import与require在同一个脚本不能混用或一起使用,我失去了一些东西在这里,或我有一些其它的错误?我怎样才能决定在同一个脚本中使用这两种语句?
为什么我需要这个,是因为我想要 …
我正在尝试从 node_modules 转译一个模块“react-device-detect”,但还无法实现。以下是我尝试过的:
module.exports = withLess({
webpack: (config, { isServer, defaultLoaders }) => {
// other configs
config.module.rules.push({
test: /\\.+(ts|tsx)$/,
include: [path.join(__dirname, 'node_modules/react-device-detect')],
// exclude: /node_modules/,
use: [{ loader: 'ts-loader' }],
});
config.module.rules.push({
test: /\\.+(js|jsx)$/,
include: [path.join(__dirname, 'node_modules/react-device-detect')],
// exclude: /node_modules/,
use: [{ loader: 'babel-loader' }],
});
return config;
},
});
Run Code Online (Sandbox Code Playgroud)
我也单独尝试过这些规则,但没有奏效。
更新 1: 完成 next.config.js 配置 @felixmosh
const webpack = require("webpack");
const withLess = require("@zeit/next-less");
const { parsed: localEnv } = require("dotenv").config();
require("dotenv").config({
path: process.env.NODE_ENV === "production" ? ".env.production" …Run Code Online (Sandbox Code Playgroud) 我试图运行一个简单的代码块,以 React "render" method 为特色,但浏览器没有显示文本。
import React from 'react';
import ReactDOM from 'react-dom';
ReactDOM.render(<h1>Hello World</h1>,document.getElementById('root'));
Run Code Online (Sandbox Code Playgroud)
我使用 VS Code 作为编辑器,因此我输入了“运行和调试 Node.js”命令。它提出了以下警告
(node:3004) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
Run Code Online (Sandbox Code Playgroud)
在 package.json 文件中设置“type:module”解决了问题,但另一方面出现了另一个问题
(node:18968) ExperimentalWarning: The ESM module loader is experimental.
warning.js:32
SyntaxError: Unexpected token '<'
at Loader.moduleStrategy (internal/modules/esm/translators.js:81:18)
at async link (internal/modules/esm/module_job.js:37:21)
Run Code Online (Sandbox Code Playgroud)
那不允许我写任何标签。我错过了什么,我该如何解决?下面是 index.html 文件和文件结构
<html>
<head>
<title> React Test</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
拜托,我开始学习npm。如果我想要安装“@fullcalendar”并使用它,我会收到错误:“未捕获的类型错误:无法解析模块说明符“tslib”。相对引用必须以“/”、“./”或“../”开头。 ”
我有这个结构: www/templates/node_modules/www/templates/assets/calendar.js
这是我的 calendar.js 文件的开始:
import {Calendar} from '../node_modules/@fullcalendar/core/main.js';
import dayGridPlugin from '../node_modules/@fullcalendar/daygrid/main.js';
import timeGridPlugin from '../node_modules/@fullcalendar/timegrid/main.js';
import listPlugin from '../node_modules/@fullcalendar/list/main.js';
other code
Run Code Online (Sandbox Code Playgroud)
在导入 {Calendar} 的那一刻,它抛出错误。在@fullcalendar/core/main.js 我看到:
import './vdom';
import { __extends, __assign } from 'tslib';
import { render, createElement, CalendarRoot, CustomContentRenderContext, CalendarContent, flushToDom, DelayedRunner, CalendarDataManager, isArraysEqual, applyStyleProp, CalendarApi } from '@fullcalendar/common';
export * from '@fullcalendar/common';
Run Code Online (Sandbox Code Playgroud)
但我认为 tslib(和其他导入库)的方式是不正确的。但是 tslib 在目录 www/templates/node_modules/tslib 中。我不想编辑已安装的包(我认为这不是正确的方法)。我可以在 npm config 中设置路径吗?有可能的?或者最好的方法是什么?
谢谢。
我想知道 node_modules 文件夹到底是什么以及用于什么。我知道当我们使用 npm 下载任何库时,该库会转到 node_modules,但我知道当我们要将其上传到 github 时,我们必须忽略 node_modules 文件夹,因为它占用大量空间。通过 package.json 我们可以使用 npm i 下载所有依赖项,我的问题是...假设我想将我的应用程序/网站部署到某个服务器/主机,我是否也必须将 node_modules 文件夹上传到服务器?另一件事,通常我从网站下载我的 jquery 和 bootstrap 并复制到我的项目内的 css/js 文件夹中,但是这次我尝试使用 npm 并且一切都转到 node_modules 并且我使用的是cordova,当我执行命令cordova时build 既不生成我的 jquery 也不生成我的引导程序。所以这就是我的问题,如果我想主持我的项目,我真的必须上传 node_modules 吗?当它是cordova或ionic时,我还必须将node_modules复制到www文件夹吗?如果是,那么使用 npm 下载库有什么意义?这是真的吗?哪一个更好?去网站下载文件并粘贴到 www 或通过 npm 下载?
node-modules ×10
npm ×5
javascript ×4
node.js ×4
angular ×1
angular6 ×1
bootstrap-4 ×1
bundle ×1
compilation ×1
docker ×1
dockerfile ×1
fullcalendar ×1
gatsby ×1
glob ×1
hugo ×1
jenkins ×1
jquery ×1
next.js ×1
reactjs ×1
transpiler ×1
typescript ×1
webpack ×1