Skip to content

Making webpacker aware of vue.config.js #2221

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

Closed
gkatsanos opened this issue Aug 8, 2019 · 6 comments
Closed

Making webpacker aware of vue.config.js #2221

gkatsanos opened this issue Aug 8, 2019 · 6 comments
Labels
support Questions or unspecific problems

Comments

@gkatsanos
Copy link

gkatsanos commented Aug 8, 2019

Several Vue libraries and vue itself recommend a vue.config.js file as a means to pass configuration options to Webpack.
I can't figure out how to make webpack aware of the file (or, where to place it)
My structure is

app/javascript/manager/styles
├── application.styl
├── flags.scss
└── main.scss

I tried putting vue.config.js in app.

@jakeNiemiec
Copy link
Member

It seems that vue.config.js is meant to fill the same role as webpacker.yml. As in they both provide a "batteries included" way to configure webpack.

I don't think they are compatible since they compete to fill the same job (in different ways).

@gkatsanos
Copy link
Author

Seems I was able to pass the config I wanted directly on the environment file that is passed to webpacker - but I would like to know how I can pass options to the base webpack config if I want to do more advanced stuff like tree shaking, code splitting and lazy loading..

@jakeNiemiec
Copy link
Member

jakeNiemiec commented Aug 8, 2019

Glad it worked out. Tree shaking should be on by default to vanilla webpack.

You can find code splitting and lazy loading docs here.

@jakeNiemiec jakeNiemiec added the support Questions or unspecific problems label Aug 8, 2019
@zeroedin
Copy link

@gkatsanos can you show a more detailed example of what you did to "pass the config directly on the environment". I'm not following what you did there.

My use case is trying to load a _variables.scss file for every component programmatically like described here https://css-tricks.com/how-to-import-a-sass-file-into-every-vue-component-in-an-app/ but I can't seem to get webpacker aware of the vue.config.js in the root dir. Hoping what you figured out might help me.

@jonyhayama
Copy link

jonyhayama commented Aug 18, 2020

@zeroedin I know this is kind of an old issue, but just to let you know what I've found out :)

I don't know if you've ran into this issue, but it I've built on top of it and got the _variables.scss to "autoload".

here's the code I've added before module.exports = environment on the config/webpack/environment.js:

// Get the actual sass-loader config
const sassLoader = environment.loaders.get('sass')
const sassLoaderConfig = sassLoader.use.find(function(element) {
  return element.loader == 'sass-loader'
})

// Use Dart-implementation of Sass (default is node-sass)
const options = sassLoaderConfig.options
options.implementation = require('sass')
options.additionalData = `@import "@/../assets/scss/_variables.scss";`

@guillaumebriday
Copy link
Member

I think you should mix Webpacker and vue.config.js, they achieve the same goal and would conflict. If you want to use Rails and Vue-cli you should try this https://github.com/guillaumebriday/rails-vue-cli

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

No branches or pull requests

5 participants