我的项目结构如下所示。
--Module UI
--Node_Modules
--Module Shared
--Module Shared
模块UI - 使用webpack构建的UI模块。它有一个本地npm参考Module Auth。
模块共享 - 共享模块是共享的通用模块。它符合tsc命令并公开其编译的javascript和typescript映射以供在其他项目中使用。它使用以下tsconfig.json选项。
"inlineSourceMap": true,
"inlineSources": true,
这会产生符合以下sourceMappingURL的javascript文件。
//# sourceMappingURL=data:application/json;base64 [BASE64 Encoded Source map and source.]
如果我将javascript文件直接包含在另一个项目中,则源映射和源代码将按预期工作。我无法找到将它们包含在我的webpack构建中的方法,以便源映射可以在打包构建中进行调试。
有没有人看到我应该改变的任何内容或有建议使其发挥作用?
npm命令构建
"build": "rimraf dist && rimraf wwwroot && webpack --config webpack.dev.js --progress --profile --bail"
webpack.dev.js
var webpack = require('webpack');
var webpackMerge = require('webpack-merge');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var commonConfig = require('./webpack.common.js');
var helpers = require('./config/helpers.js');
const ENV = process.env.NODE_ENV = process.env.ENV = 'dev';
module.exports = webpackMerge(commonConfig, {
output: {
path: helpers.root('wwwroot'),
publicPath: '/',
filename: '[name].[hash].js',
chunkFilename: '[id].[hash].chunk.js',
sourceMapFilename: '[name].js.map'
},
plugins: [
new webpack.NoEmitOnErrorsPlugin(),
new webpack.optimize.UglifyJsPlugin({ // https://github.com/angular/angular/issues/10618
mangle: {
keep_fnames: true
}
}),
new ExtractTextPlugin('[name].[hash].css'),
new webpack.DefinePlugin({
'process.env': {
'ENV': JSON.stringify(ENV)
}
}),
new webpack.LoaderOptionsPlugin({
htmlLoader: {
minimize: false // workaround for ng2
}
})
],
devServer: {
historyApiFallback: true,
stats: 'minimal'
}
});
webpack.common.js
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var helpers = require('./config/helpers.js');
module.exports = {
entry: {
'polyfills': './src/polyfills.ts',
'vendor': './src/vendor.ts',
'auth': './node_modules/CFPet.Auth/dist/app.auth.module.js',
'app': './src/main.ts'
},
resolve: {
extensions: ['.ts', '.js']
},
devtool: 'inline-source-map',
module: {
rules: [
{
test: /\.js$/,
use: ["source-map-loader"],
enforce: "pre"
},
{
test: /\.ts$/,
loaders: ['awesome-typescript-loader', 'angular2-template-loader']
},
{
test: /\.html$/,
loader: 'html-loader'
},
{
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
loader: 'file-loader?name=assets/[name].[hash].[ext]'
},
{
test: /\.css$/,
exclude: helpers.root('src', 'app'),
loader: ExtractTextPlugin.extract({ fallbackLoader: 'style-loader', loader: 'css-loader?sourceMap' })
},
{
test: /\.css$/,
include: helpers.root('src', 'app'),
loader: 'raw-loader'
}
]
},
plugins: [
// Workaround for angular/angular#11580
new webpack.ContextReplacementPlugin(
// The (\\|\/) piece accounts for path separators in *nix and Windows
/angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
helpers.root('./src'), // location of your src
{} // a map of your routes
),
new webpack.optimize.CommonsChunkPlugin({
name: ['app', 'auth','vendor', 'polyfills']
}),
new HtmlWebpackPlugin({
template: 'src/index.html'
})
]
};