2

I have recently moved from grunt/bower to webpack but can't get sourcemaps to work. I get code references like debugger://VM8967 instead of real file names like I'm used to. I've tried many combinations of

mode: 'development', devtool: 'cheap-module-source-map',

as suggested in many places, like here and here but without any luck. This seems like very standard behavior that everyone would need so I'm sure I do some stupid mistake. Hope someone can help. I use:

"webpack": "^4.39.1",
"webpack-cli": "^3.3.6",
"webpack-dev-server": "^3.7.2"

And my webpack.config looks like this:

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,
  },
};
Tony Ngo
  • 19,166
  • 4
  • 38
  • 60
jola
  • 977
  • 2
  • 10
  • 31

1 Answers1

0

For js source map you can do like this

module.exports = {
  // ...
  devtool: false,
  plugins: [
    new webpack.SourceMapDevToolPlugin({
        filename: '[name].js.map',
        exclude: ['vendor.js']
    })
  ]
};

Link here

Tony Ngo
  • 19,166
  • 4
  • 38
  • 60
  • Thanks, I tried this but with no different output than before. Maybe something else in my config is conflicting? The changes I did in the config: ` devtool: false, plugins: [ ... new CopyWebpackPlugin([{ from: 'app/apple-touch-icon.png' }]), new HtmlWebpackPlugin({ template: 'app/index.html', }), new MiniCssExtractPlugin({ filename: 'style.css', }), new webpack.SourceMapDevToolPlugin({ filename: '[name].js.map', exclude: ['vendor.js'] }) ], devServer: { (as before) },` – jola Aug 16 '19 at 07:09