[英]Avoid require statement in the transpiled javascript
The following statements from a .ts
file: .ts
文件中的以下语句:
import {jquery as $} from 'jquery';
import {socketio} from 'socket.io';
get transpiled to: 变成:
var jquery_1 = require("jquery");
var socket_io_1 = require("socket.io");
Now the browser won't recognize require
. 现在浏览器无法识别require
。 What is the way out? 出路是什么? My tsconfg.json
looks like: 我的tsconfg.json
看起来像:
{
"compilerOptions": {
"target": "es5",
"outDir": "./dist",
"allowJs": true,
"module": "commonjs",
"noEmitOnError": false,
"noImplicitAny": false,
"strictNullChecks": true
},
"include": [
"index.ts",
"./lib/**/*",
"./public/**/*"
]
}
Is there a need to change something? 是否需要改变一些东西?
I used browserify to bundle the final file into a browser compatible javascript. 我使用browserify将最终文件捆绑到浏览器兼容的javascript中。
browserify input.js -o output.js
There could be errors thrown by the browserify saying for example Error: Cannot find module 'bufferutil' from ..
In that case, the respective modules could be installed from the npm. 可能会出现浏览器抛出的Error: Cannot find module 'bufferutil' from ..
,例如Error: Cannot find module 'bufferutil' from ..
在这种情况下,可以从npm安装相应的模块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.