Hi!
We are using webpacker default configuration and importing scss files in jsx like this:
import './errors-popup.scss';
I am unable to get production compiled scss files under one applicaction-hash.css although css are in the manifest.json. After deploying site is without styles.
Should I import every single scss file in application.scss and then this file in application.js?
app/javascript
โโโ components
โย ย โโโ setup-container
โย ย โย ย โโโ configuration-container.jsx
โย ย โย ย โโโ form-step
โย ย โย ย โย ย โโโ form-step.jsx
โย ย โย ย โย ย โโโ form-step.scss
โย ย โย ย โโโ product-mapping-step
โย ย โย ย โย ย โโโ product-mapping-step.jsx
โย ย โย ย โย ย โโโ row.jsx
โย ย โย ย โโโ settings-step
โย ย โย ย โโโ settings-step.jsx
โย ย โโโ shared
โย ย โโโ errors-popup
โย ย โย ย โโโ errors-popup.jsx
โย ย โย ย โโโ errors-popup.scss
โย ย โโโ link-failure
โย ย โย ย โโโ link-failure.jsx
โย ย โโโ setup-navbar
โย ย โโโ setup-navbar.jsx
โย ย โโโ setup-navbar.scss
โย ย โโโ setup-step.jsx
โย ย โโโ setup-step.scss
โโโ packs
โย ย โโโ application.js
โย ย โโโ setup-container.js
โย ย โโโ shared.js
โโโ stylesheets
โโโ application.scss
โโโ shared
โโโ _colors.scss
โโโ _fonts.scss
production.js
process.env.NODE_ENV = process.env.NODE_ENV || 'production';
const environment = require('./environment');
environment.loaders.get('sass').use.find(item => item.loader === 'sass-loader').options.sourceMapContents = false;
module.exports = environment.toWebpackConfig();
environment.js
const { environment } = require('@rails/webpacker')
module.exports = environment
webpacker.yml
default: &default
source_path: app/javascript
source_entry_path: packs
public_output_path: packs
cache_path: tmp/cache/webpacker
resolved_paths: []
cache_manifest: false
extensions:
- .jsx
- .js
- .sass
- .scss
- .css
- .module.sass
- .module.scss
- .module.css
- .png
- .svg
- .gif
- .jpeg
- .jpg
dev_server:
hmr: false
development:
<<: *default
compile: true
dev_server:
https: false
host: localhost
port: 3035
public: localhost:3035
hmr: true
inline: true
overlay: true
compress: true
disable_host_check: true
use_local_ip: false
quiet: false
headers:
'Access-Control-Allow-Origin': '*'
watch_options:
ignored: /node_modules/
test:
<<: *default
compile: true
public_output_path: packs-test
production:
<<: *default
compile: false
cache_manifest: true
staging:
<<: *default
compile: false
cache_manifest: true
packs/application.js
import '../stylesheets/application.scss';
packs/setup-container.js
import WebpackerReact from 'webpacker-react';
import ConfigurationContainer from '../components/setup-container/configuration-container';
WebpackerReact.setup({ ConfigurationContainer });
application.html.erb
<%= stylesheet_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'setup-container' %>
<%= javascript_pack_tag 'shared' %>
There is no clear docs about it. I would like to remove maps and have all under two files. JS and CSS.
Thanks
I've the same problem. Also I cannot get fonts loaded in production. I ended up with abandoning webpacker.
@openscript I cannot count the number of times I've cursed webpack(er). It is not sustainable and a huge time sink whack-a-mole.
Were either of you able to resolve this issue?
@adenta Yes I eventually solved the issue for me.
I've created a new loader url.js:
module.exports = {
test: /\.(tiff|ico|svg|eot|otf|ttf|woff|woff2)$/i,
use: [{
loader: 'url-loader',
options: {
limit: 10000,
name: '[name]-[hash:5].[ext]'
}
}]
};
.. and loaded that during production:
const url = require('./loaders/url');
environment.loaders.prepend('url', url);
environment.loaders.get('file').test = /\.(jpg|jpeg|png|gif|tiff|ico|svg)$/i;
The problem was the file-loader which tried to load the fonts as well and somehow didn't work.
There is no need to override your url-loader here. Check https://github.com/rails/webpacker/blob/master/docs/assets.md
Webpack is not easy on the first look for sure. :/
Can this issue be closed ?
As for me, yes. Thank you for asking!
Currently I'm happy with webpacker. I see the massive progress it made since February. Thank you contributors ๐ฅฐ
@freezepl please consider closing the issue ๐
Most helpful comment
@openscript I cannot count the number of times I've cursed webpack(er). It is not sustainable and a huge time sink whack-a-mole.