【发布时间】:2016-04-02 22:09:00
【问题描述】:
我正在尝试在 Webpack 中设置一个 Angular 2 应用程序(用 TypeScript 编写),以便在 IntelliJ IDEA 15 中对其进行调试。我正在使用 webpack-dev-server 在本地提供它。
我注意到的一件事是,当我在 IntelliJ 调试器或 Chrome 的检查器中查看我的应用程序时,我的应用程序文件很少出现在脚本选项卡的 webpack://. 部分。
这是我在 Chrome Inspector 中看到的内容,例如:
这显示了很少的文件。但这里有(一些)真正起作用的东西(如 IntelliJ IDEA 所示):
这是我的webpack.config.js 文件的样子:
// @AngularClass
/*
* Helper: root(), and rootDir() are defined at the bottom
*/
var path = require('path');
var webpack = require('webpack');
// Webpack Plugins
var CommonsChunkPlugin = webpack.optimize.CommonsChunkPlugin;
/*
* Config
*/
module.exports = {
// for faster builds use 'eval'
devtool: 'source-map',
debug: true, // remove in production
entry: {
// 'vendor': './src/vendor.ts',
'vendor': './src/vendor.ts',
'app': './src/app/app.ts' // our angular app
},
// Config for our build files
output: {
path: root('__build__'),
filename: '[name].js',
sourceMapFilename: '[name].map',
chunkFilename: '[id].chunk.js'
},
resolve: {
// ensure loader extensions match
alias: { // failed attempt to import into vendor.ts
jquery: path.join(__dirname, 'src/lib/jquery/jquery.min.js'),
'js.cookie': path.join(__dirname, 'src/lib/js.cookie/js.cookie.js'),
bootstrap: path.join(__dirname, 'src/lib/bootstrap/bootstrap.js')
},
extensions: ['', '.ts', '.js', '.json', '.css', '.html']
},
module: {
// preLoaders: [ { test: /\.ts$/, loader: 'tslint-loader' } ],
loaders: [
// Support for .ts files.
{
test: /\.ts$/,
loader: 'ts-loader',
query: {
'ignoreDiagnostics': [
2403, // 2403 -> Subsequent variable declarations
2300, // 2300 -> Duplicate identifier
2374, // 2374 -> Duplicate number index signature
2375 // 2375 -> Duplicate string index signature
]
},
exclude: [/\.(spec|e2e)\.ts$/, /node_modules\/(?!(ng2-.+))/]
},
// Support for *.json files.
{test: /\.json$/, loader: 'json-loader'},
// Support for CSS as raw text
{test: /\.css$/, loader: 'raw-loader'},
// support for .html as raw text
{test: /\.html$/, loader: 'raw-loader'}
],
noParse: [/angular2-polyfills/]
},
plugins: [
new CommonsChunkPlugin({name: 'vendor', filename: 'vendor.js', minChunks: Infinity}),
new CommonsChunkPlugin({name: 'common', filename: 'common.js', minChunks: 2, chunks: ['app', 'vendor']})
// include uglify in production
],
// Other module loader config
tslint: {
emitErrors: false,
failOnHint: false
},
// our Webpack Development Server config
devServer: {
historyApiFallback: true,
contentBase: 'src',
publicPath: '/__build__'
}
};
// Helper functions
function root(args) {
args = Array.prototype.slice.call(arguments, 0);
return path.join.apply(path, [__dirname].concat(args));
}
function rootNode(args) {
args = Array.prototype.slice.call(arguments, 0);
return root.apply(path, ['node_modules'].concat(args));
}
到目前为止,我还没有调试我的应用程序,如果调试器无法使用 Webpack 创建的源映射将正在运行的代码映射到我的源文件,这似乎不足为奇。
如果有人对我可能需要做什么有任何见解,我将不胜感激。
【问题讨论】:
标签: javascript typescript webpack angular webpack-dev-server