小编don*_*tos的帖子

TypeScript无法导入没有扩展名的文件

我正在尝试在新的Angular2项目中导入文件。入口文件“ main.ts”能够使用以下命令导入另一个打字稿文件:

import { AppModule }              from './module/app.module';
Run Code Online (Sandbox Code Playgroud)

另一方面,“ app.module.ts”无法导入没有文件扩展名的ts文件:

import { AppComponent }             from '../component/app.component';
Run Code Online (Sandbox Code Playgroud)

如果我在文件名中添加“ .ts”,则一切正常。

我怎么了 我假设我正在按照角度指南(https://angular.io/docs/ts/latest/guide/webpack.html)做所有事情

我安装了节点6.9.4,npm 4.2.0,打字稿2.3.2,Angular 4.1.0和Webpack 2.5.1

我的tsconfig.json

{
    "compilerOptions": {
        "target": "es6",
        "module": "commonjs",
        "moduleResolution": "node",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "noImplicitAny": true,
        "suppressImplicitAnyIndexErrors": true
    }
}
Run Code Online (Sandbox Code Playgroud)

我的webpack.config.js

var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var helpers = require('./helpers');

module.exports = {
    entry: {
        'polyfills': './src/polyfills.ts',
        'vendor': './src/vendor.ts',
        'app': './src/main.ts'
    },
    resolve: {
        extensions: …
Run Code Online (Sandbox Code Playgroud)

javascript node.js typescript webpack angular

6
推荐指数
1
解决办法
6419
查看次数

Chrome开发 - chrome.tabs.sendMessage不通知运行时

我正在尝试向新创建/更新的选项卡发送消息并在那里接收:

var tabAction = 'create';      // tabAction equals *create* or *update*

chrome.tabs[tabAction]({
    url:  chrome.extension.getURL('/somepage.htm'),
    active: true
}, function(_tab) {
    chrome.tabs.sendMessage(_tab.id, {
        message: 'some custom message',
        arg: 'some arg'
    });
});
Run Code Online (Sandbox Code Playgroud)

在此调用之后,其中一个脚本(包含在打开页面的标题中)必须接收此消息并执行进一步操作:

(function(window, document, jQuery) {
    "use strict";


    chrome.runtime.onMessage.addListener(function(message) {
        // Do stuff
    });
})(window, document, jQuery);
Run Code Online (Sandbox Code Playgroud)

现在我的问题:

如果tabAction设置为"create",一切正常 - 页面正在加载,主脚本发送消息,扩展调试器显示:"Invoked tabs.sendMessage"和"Notified of runtime.onMessage",页面脚本做了什么它必须.

如果tabAction设置为"update" - 正在重定向页面,主脚本也会发送消息,但消息不会发送到运行时; 调试器只在"Invoked tabs.sendMessage"处停止.

为何这种奇怪的行为?感谢所有进一步的回复.

javascript google-chrome google-chrome-extension google-chrome-app

4
推荐指数
1
解决办法
3452
查看次数