Hi I’ve setup laravel mix with separate src directory and assets directory. in the main theme folder.
along the lines of
src
--js
--scss
assets
--css
--images
--fonts
--videos
Now in one of my .js
files I’d like to import images to use - usually I did it like this import imageFrames from "/images/3dbox/*.png";
But here I get an error Module not found: Error: Can't resolve '/images/3dbox/*.png' in 'C:\strony\sites\www\site\public_html\themes\base\src\js'
I’ve tried many webpack configurations but with no luck.
Current webpack config file
require("dotenv").config({ path: __dirname + "/./../../.env" });
let mix = require("laravel-mix");
// let host = process.env.APP_URL.replace("https://");
mix.setPublicPath("/");
mix.js("./src/js/main.js", "assets/js/").sass(
"./src/scss/main.scss",
"assets/css/"
);
mix.setResourceRoot("/assets/");
mix.browserSync({
host: `${process.env.APP_URL}`,
proxy: `${process.env.APP_URL}`,
notify: false,
files: ["./assets/css/*.css", "./**/*.htm", "./assets/js/*.js"],
});
mix.minify(["./assets/css/main.css", "./assets/js/main.js"]);
mix.sourceMaps(); // Enable sourcemaps
mix.options({
processCssUrls: false, // Process/optimize relative stylesheet url()'s. Set to false, if you don't want them touched.
});
mix.webpackConfig({
devtool: "inline-source-map",
plugins: [
{
apply(compiler) {
// Intercept done hook to modify CustomTasksPlugin tap function
compiler.hooks.done.intercept({
register: (tapInfo) => {
let firstRun = true;
if (tapInfo.name === "CustomTasksPlugin") {
const fn = tapInfo.fn;
tapInfo.fn = (stats, callback, ...args) => {
// Only run tap function (tasks) for first build
if (firstRun) {
fn(stats, callback, ...args);
firstRun = false;
} else {
callback();
}
};
}
return tapInfo;
},
});
},
},
],
});