johnagan / clean-webpack-plugin

A webpack plugin to remove your build folder(s) before building

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Remove source maps after build

jdavidferreira opened this issue · comments

Issue description or question

Is it possible to remove the source maps after run the build? I tried this to remove all the source maps inside the dist folder:

Webpack Config

{
  mode: 'production',
  devtool: 'hidden-source-map',
  entry: './src/index.js',
  output: {
    filename: 'main.js', 
    path: path.resolve(__dirname, 'dist'),
    publicPath: '/dist/'
  },
  plugins: [
    new CleanWebpackPlugin({
      cleanAfterEveryBuildPatterns: ['dist/*.map']
    })
  ]
}

But its not working.

Environment

System:
OS: Windows 10 10.0.18363
CPU: (12) x64 Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
Memory: 6.13 GB / 15.93 GB
Binaries:
Node: 13.12.0 - C:\Program Files\nodejs\node.EXE
npm: 6.14.4 - C:\Program Files\nodejs\npm.CMD
npmPackages:
clean-webpack-plugin: ^3.0.0 => 3.0.0
webpack: ^4.41.5 => 4.41.5

You should just tell webpack not to generate sourcemaps via devtool: false or devtool: 'none'. See https://webpack.js.org/configuration/devtool/

But to solve your issue, cleanAfterEveryBuildPatterns are relative to the build directory. Try cleanAfterEveryBuildPatterns: ['**/*.map'].

{
  mode: 'production',
  devtool: 'hidden-source-map',
  entry: './src/index.js',
  output: {
    filename: 'main.js', 
    path: path.resolve(__dirname, 'dist'),
    publicPath: '/dist/'
  },
  plugins: [
    new CleanWebpackPlugin({
      cleanAfterEveryBuildPatterns: ['**/*.map']
    })
  ]
}

I'm using a plugin that uploads the source maps to a server. I want to remove them after that.

No, it still does not work. 😕

I forgot protectWebpackAssets: false.

const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const path = require('path');

module.exports = {
	mode: 'production',
	devtool: 'hidden-source-map',
	entry: './src/index.js',
	output: {
		filename: 'main.js',
		path: path.resolve(__dirname, 'dist'),
		publicPath: '/dist/',
	},
	plugins: [
		new CleanWebpackPlugin({
			cleanAfterEveryBuildPatterns: ['**/*.map'],
			protectWebpackAssets: false,
		}),
	],
};

It works! Thank you. 😁

This is something I've been searching for and I noticed that many people do too, and I wanted to avoid doing the script "webpack --config webpack.prod.js && rm ./dist/*.js.map". I like this solution more.

protectWebpackAssets: false,

good job,because i want use sentry to record web error,first, i will upload source map to sentry.So , i need to remove them,after builded