Closed guilhermeutzig closed 6 years ago
Slightly unrelated, but you're being a little too haphazard with the mutable config π¬The one "gotcha" of exposing the entire object.
You're removing all of the aliases, many of which PWA needs to remain intact. For reference, here are all of PWA's aliases.
The @
alias points to your /src
directory out of the box. If I were you, I'd use that (or at least add new aliases with the @
prefix) as to 100% avoid/bypass trying to resolve a npm dependency instead of your alias.
import myStyle from '@/styles/foobar.css'
import Hello from '@/js/hello';
// note that "@assets" is already setup for you
import Video from '@assets/video.mp4';
If you're dead-set on adding new aliases, I'd do it like this:
const { join } = require('path');
module.exports = function (config, env) {
// PUSH into extensions, not overwrite
config.resolve.extensions.push('.scss', '.css', '.pdf', '.zip', '.mp4', '.jpg', '.png');
// add individual aliases
//~> PS: still highly recommend you use "@___" aliases instead
// Note: `env.src` === "/src" directory
config.resolve.alias['styles'] = join(env.src, 'styles');
config.resolve.alias['js'] = join(env.src, 'js');
}
Lemme know how that goes π
Ohhh I got it, tested both ways and both worked!!
I will use @
prefix as you said, I was struggling a little bit to make it work, didn't quite get the concept of the thing.
Thank you very much for your help!
Awesome! π You're welcome
Hello everyone,
I'm trying an experiment with React and I've changed the
src
folder to:assets/
js/
styles/
index.html
index.js
The main reason of this is that I wanted to separate styles from javascripts, but now, the only way I can find my files, is using relative path
../styles/component/index.scss
...I already tried to do this on
pwa.config.js
:const resolve = require('resolve');
But returns the error: