Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel Mix mix-manifest.json support #18

Open
sebszocinski opened this issue Mar 12, 2021 · 3 comments
Open

Laravel Mix mix-manifest.json support #18

sebszocinski opened this issue Mar 12, 2021 · 3 comments

Comments

@sebszocinski
Copy link

Hey does anyone know how to reference the mix-manifest.json file inside a pug file? The docs for it apply to html or blade so I assume we need some magic here?

@matejsvajger
Copy link
Owner

You can attach it to the locals object in you build config:

mix.pug('src/*.pug', 'dist', {
    locals: {
        manifest: require('mix-manifest.json')
    }
});

and access it in your pug file something like this:

script(src=`{manifest['/js/app.js']}`)

Hope this helps!

@sebszocinski
Copy link
Author

Hey @matejsvajger thanks! I tried that but I can't seem to be able to reference mix-manifest.json, I keep getting this error:

[webpack-cli] Error: Cannot find module 'mix-manifest.json'

My mix config is below (Laravel app):

mix.js('resources/js/_app.js', 'public/js').vue()
	.sass('resources/sass/_vendor.sass', 'css')
	.sass('resources/sass/_app.sass', 'css')
	.pug('resources/pug/**/*.pug', 'resources/views', {
		ext: '.antlers.html',
		excludePath: 'resources/pug',
		locals: {
			manifest: require('mix-manifest.json')
		}
	})
	.tailwind()
	.webpackConfig({
		module: {
			rules: [{
				test: /\.pug$/,
				oneOf: [
					{
						resourceQuery: /^\?vue/,
						use: ['pug-plain-loader']
					}
				]
			}]
		}
	})
	.setPublicPath('public')
	.env(process.env.ENV_FILE)
	.browserSync(browserSyncOptions)
	.disableSuccessNotifications();

I can see my mix-manifest.json file is being written to my public folder so I tried referencing that but nothing worked.

@sebszocinski
Copy link
Author

Hey @matejsvajger ok I got it building with manifest: require('./public/mix-manifest.json') but the script source doesn't seem to work in the pug file using:

script(src=`{manifest['/js/_app.js']}`)

The output in browser is like this:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants