node -v): 8.1.2npm -v): 5.0.3A publicPath pointing outside the root folder where npm is run does result in incorrect paths for the js file (css/copyDirectory does still work). The elixir framework phoenix does have a nested assets folder for it's npm stuff, whereas the public path is in a different branch from the project root:
|-assets
| |- static
| | |- logo, …
| |- package.json
| |- webpack.mix.js
|-priv
|- static
|- js
|- css
mix.setPublicPath('../priv/static')
.js('js/app.js', 'js/app.js')
.sass('css/app.scss', 'css/app.css')
.copyDirectory('./static', '../priv/static');
This results in the following output of webpack:
/Users/benni/Sites/madeit/priv/static/js/app.js 182 kB 0 [emitted] …
css/app.css 152 kB 0 [emitted] …
Meaning the js file is being put in ../priv/static/Users/benni/[…]
ln -s ../priv/static output and
mix.setPublicPath('output')
.js('js/app.js', 'js/app.js')
.sass('css/app.scss', 'css/app.css')
.copyDirectory('./static', 'output');
Using that results in:
/js/app.js 182 kB 0 [emitted] /js/app
css/app.css 152 kB 0 [emitted] /js/app
and therefore correct paths (still curious about the leading /).
I'm having the same problem, I reported it here, at the moment I'm using that fix I mentioned.
That part about changing from / to \\ should be only needed on Windows.
Same here.
Problem is that the File instance is not resolving publicPath, only rootPath. Because of files that are in root path we should resolve both cases.
In file: src/File.js:93 something like
return this.path()
.replace(Mix.paths.root() + path.sep, '')
.replace(path.resolve(Mix.paths.root(), Config.publicPath), '');
should does job.
I have the same issue with this new 1.0 version. My combined js scripts are saved into Laravel dir and not into my public dir that is placed outside Laravel (same level of Laravel dir).
This code below works fine in the 0.12.1 version but give me an error on the new 1.0.7 version:
mix
.setPublicPath('../public_html')
.copyDirectory(paths.bootstrap + 'fonts/bootstrap/', '../public_html/fonts/bootstrap')
.copyDirectory(paths.fontawesome + 'fonts/', '../public_html/fonts/fontawesome')
.sass('resources/assets/sass/app.scss', '/css/all.css')
.combine([
'resources/assets/js/admin/plugins.js',
'resources/assets/js/admin/main.js'
], '../public_html/js/admin.js')
.version();
After some tests i changed my code to this and partially works but the 'js/admin.js' script is generated under Laravel dir and not under my public_html dir.
mix
.setPublicPath('../public_html')
.copyDirectory(paths.bootstrap + 'fonts/bootstrap/', '../public_html/fonts/bootstrap')
.copyDirectory(paths.fontawesome + 'fonts/', '../public_html/fonts/fontawesome')
.sass('resources/assets/sass/app.scss', '/css/all.css')
.combine([
'resources/assets/js/admin/plugins.js',
'resources/assets/js/admin/main.js'
], 'js/admin.js')
// Temp Fix
.copyDirectory('./js/', '../public_html/js')
.then(() => {
let fs = require('fs-extra');
// Not work properly
fs.remove('./js/');
})
.version();
Is there a fix for that issue? Any suggestion? Thanks.
@wanted80 look for to my post above. I said what happend and temporary fix (sadly inside node_modules... time to make PR...)
@routegroup I tried to solve the issue with your fix but didn't work in my case...
@wanted80 try with the fix I posted here, it's working fine for me, I'm on windows but it should work on linux too, just skip the part about changing from / to \\.
@TopFuel tried your fix and now it works fine. With that i can revert my code to the previous version and works. Thank you.
The PR #964 fixed the issue, it should be released soon 👍
I found that using this relative path style, on windows solves the issue for me (with browsersync example)
let mix = require('laravel-mix');
var publicDir = '..\\html\\public';
mix.setPublicPath(publicDir);
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
mix.webpackConfig({
plugins: [
new BrowserSyncPlugin({
files: [
'app/**/*',
publicDir + '/**/*',
'resources/views/**/*',
'resources/assets/**/*',
'routes/**/*'
]
})
]
}) ;
mix.sass('resources/assets/sass/app.scss', publicDir + '/css');
Many thanks to this issue here
Note: I was not able to use ..\\html/public' as suggested on the linked page.