Lassassin's avatar

Generating sourceMaps for scripts method in laravel-mix?

Hi, I am a beginner at laravel, and I have to migrate a very old project using laravel-mix. How do you generate sourceMaps for the scripts or combine method for laravel-mix ? Below is my source code and it is not generating sourceMaps for others.js. Also, is there anyway I can disable moduling for the js method of mix? TIA!

const mix = require('laravel-mix')
const { glb } = require('laravel-mix-glob')
const { resolve } = require('laravel-mix-glob/dist/Helpers')

mix
	.options({
		postCss: [require('tailwindcss')],
	})
	// lets mix sass files 
	.sass('resources/scss/app.scss', 'public/css/app.css')
	// .sass('resources/scss/pages/*.scss', 'public/css/pages')
	.sass(glb.src('resources/scss/pages/*.scss'), glb.out({ baseMap: 'resources/scss/pages', outMap: 'public/css/pages' }))
	// now mix js  
	.js('resources/js/app.js', 'public/js/app.js')
	.scripts(['resources/js/vendor/*.js', 'resources/js/lib/*.js', 'resources/js/utils/*.js', 'resources/js/ts/*.js'], 'public/js/others.js')
	.copyDirectory(['resources/js/page-specific'], 'public/js/pages')
	.version()
	// enable sourcemaps for css
	.sourceMaps(true, 'source-map')
0 likes
6 replies
tykus's avatar

Why are you bundling a script that is already in the public directory?

Lassassin's avatar

@tykus Sorry I didn't understand what you mean. Could you please elaborate on which script you mean?

tykus's avatar

@Lassassin I suppose source maps are not available for combined scripts/styles?

Lassassin's avatar

@tykus I guess so. I tried the following for mix:

mix.webpackConfig({
   devtool: 'source-map'
});

mix.webpackConfig({
   devtool: 'inline-source-map'
});

mix.webpackConfig({
   devtool: 'eval-source-map'
});

mix.webpackConfig({
   devtool: 'source-map',
   output: {
      sourceMapFilename: 'public/js/others.js.map'
   }
});

mix.scripts(['resources/js/vendor/*.js', 'resources/js/lib/*.js', 'resources/js/utils/*.js', 'resources/js/ts/*.js'], 'public/js/others.js')
   .webpackConfig({
      devtool: 'source-map'
   });

There is a sourcemap for app.js, so I was wondering if there is a way to disable module bundling for webpack? The project breaks if the libraries are wrapped in an IIFE

Please or to participate in this conversation.