question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Output files outside of the public path directory

See original GitHub issue
  • Laravel Mix Version: 1.2.0
  • Node Version: 8.1.2
  • NPM Version: 5.0.4
  • OS: LMDE 2 Betsy

Description:

I have posted this issue before but was pretty much disregarded and closed. I don’t think it was understood what I was trying to achieve. I have a repository this time so that you can see exactly what I am trying to do.

I am trying to mix a file and output the resulting file outside of my public path. In a Laravel project am I taking a file from resources/assets/js/app.js and trying to output it to resources/assets/js/app2.js and in the same file grab a sass file from resources and output the result of mix.sass() to the public folder. So I am trying to output files to two different directories in the same mix file like you could do with Laravel Elixir. See the repo for a live example. I want the mix-manifest.json to go inside the public folder so setting the project root as the public path is not what I want.

My current workaround is having two mix files for outputting to resources and public respectively. Another workaround would be having the project root as the public path and then after compiling the assets, moving the mix-manifest.json to the public folder but then the directories would be pointing to stuff inside the resources folder which is not what I want either.

Steps To Reproduce:

A live example is available at this repository.

This issue is a duplicate of #951 but this is more in depth and hopefully you will understand what I want to achieve.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:8

github_iconTop GitHub Comments

8reactions
sayhicoelhocommented, Dec 3, 2017

According to my Laravel project structure:

/laravel
/public_html

I’ve successfully configured the laravel-mix using the following code:

let mix = require('laravel-mix');
let path = require('path');

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel application. By default, we are compiling the Sass
 | file for the application as well as bundling up all the JS files.
 |
 */

mix.setPublicPath(`..${path.sep}public_html`);

mix.js('resources/assets/js/app.js', 'js')
   .sass('resources/assets/sass/app.scss', 'css');
2reactions
AdamBassettcommented, Jan 4, 2018

The code that I found to work the best for this in 5.5 is:

mix.setPublicPath(path.normalize('html'));`
mix.setResourceRoot(path.normalize('html'));

mix.js('resources/assets/js/app.js', 'html/js')
   .sass('resources/assets/sass/app.scss', `'html/css');

This puts the mix-manifest.json in the html root.

Hope this helps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Output files outside of the public path directory #986 - GitHub
In a Laravel project am I taking a file from resources/assets/js/app. js and trying to output it to resources/assets/js/app2. js and in the ......
Read more >
Using absolute path for files outside public_html - php
Generally speaking, you should put all directories that you need access from PHP inside public_html, and also use relative paths.
Read more >
Public Path - webpack
Essentially, every file emitted to your output.path directory will be referenced from the output.publicPath location. This includes child chunks (created ...
Read more >
Accessing files outside the Drupal directory tree
I am trying to access a large mp4-file, which - for security reasons and out of convenience - is stored ABOVE the root...
Read more >
CWE-22: Improper Limitation of a Pathname to a Restricted ...
"Path traversal" is preferred over "directory traversal," but both terms are ... Because of the lack of output encoding of the file that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found