我最近已经从咕unt咕b的声音转移到了webpack,但是无法使用源地图。我得到像debugger:// VM8967这样的代码引用,而不是像我以前那样使用真实文件名。我已经尝试过许多
组合mode: 'development', devtool: 'cheap-module-source-map',
许多地方都建议使用
,例如here和here,但是没有运气。这似乎是每个人都需要的非常标准的行为,所以我确定我犯了一些愚蠢的错误。希望有人能帮忙。我使用:
"webpack": "^4.39.1",
"webpack-cli": "^3.3.6",
"webpack-dev-server": "^3.7.2"
我的webpack.config看起来像这样:
const path = require('path');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
module.exports = {
entry: './app/index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
},
module: {
rules: [
{
test: /\.(js)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, { loader: 'css-loader' }],
},
{
test: /\.(eot|woff|ttf|woff2|svg|png|jpg)$/,
use: [
{
loader: 'file-loader',
options: {
outputPath: 'assets',
},
},
],
},
],
},
plugins: [
new CopyWebpackPlugin([{ from: 'app/images', to: 'images' }]),
new CopyWebpackPlugin([{ from: 'app/languages', to: 'languages' }]),
new CopyWebpackPlugin([{ from: 'app/views', to: 'views' }]),
new CopyWebpackPlugin([{ from: 'app/robots.txt' }]),
new CopyWebpackPlugin([{ from: 'app/404.html' }]),
new CopyWebpackPlugin([{ from: 'app/.htaccess' }]),
new CopyWebpackPlugin([{ from: 'app/favicon.ico' }]),
new CopyWebpackPlugin([{ from: 'app/apple-touch-icon.png' }]),
new HtmlWebpackPlugin({
template: 'app/index.html',
}),
new MiniCssExtractPlugin({
filename: 'style.css',
}),
],
devServer: {
contentBase: path.join(__dirname, 'dist'),
compress: true,
port: 9000,
},
};
答案 0 :(得分:0)
对于js源映射,您可以这样做
module.exports = {
// ...
devtool: false,
plugins: [
new webpack.SourceMapDevToolPlugin({
filename: '[name].js.map',
exclude: ['vendor.js']
})
]
};
链接here