Broke page styles of Vue.js app (Webpack template) when live changing it in Chrome DevTools
I find another solution. Thanks to answer of @munstrocity regarding changing cheap-module-eval-source-map
to eval-source-map
. Unfortunately, this change didn't fix for me my styles in Chrome Dev Tools but give me good point to check.
After a bit I found, that changing cacheBusting: true,
to false
in config/index.js
help to solve that and now it's possible to change style in Chrome Dev Tools.
// file: config/index.js
...
// If you have problems debugging vue-files in devtools,
// set this to false - it *may* help
// https://vue-loader.vuejs.org/en/options.html#cachebusting
cacheBusting: false,
...
Hope this will help anyone! :)
Issue with dev-tools style editing in Nuxt.js
on nuxt.config.js
file, disable the sourceMaps
for scss files with the loader property
export default {
// ...
build: {
loaders: {
scss: { sourceMap: false },
},
},
// ...
}
see in ~> nuxtjs.org/api/configuration-build/#loaders
Running ng server with --hmr still causes page to reload on changes
It looks like I had to add the following in the main.ts
declare var module: any;
if (module['hot']) {
module['hot'].accept();
module['hot'].dispose(() => ɵresetCompiledComponents());
}
I still get the message mentioned in my original post but at least I see a different behavior. If there are any other things to tweak please let me know :)
Webpack style-loader / css-loader: url() path resolution not working
I was able to solve the problem myself. In case it could help others in the future, please find the solution below.
- First of all, if you are using both
postcss-loader
with thepostcss-import
plugin, ANDcss-loader
, turn off / delete thepostcss-import
plugin. You do not need more than one tool that resolves@import
rules. This is not really a problem if the order of loaders is correct, but you might as well remove it. - In the sass-loader docs, you can read the following:
Since Sass/libsass does not provide url rewriting, all linked assets
must be relative to the output.
If you're just generating CSS without passing it to the css-loader, it must be relative to your web root.
If you pass the generated CSS on to the css-loader, all urls must be relative to the entry-file (e.g. main.scss).
More likely you will be disrupted by this second issue. It is natural to expect relative references to be resolved against the .scss file in which they are specified (like in regular .css files). Thankfully there are two solutions to this problem:
Add the missing url rewriting using the resolve-url-loader. Place it before the sass-loader in the loader chain.
Library authors usually provide a variable to modify the asset path. bootstrap-sass for example has an $icon-font-path. Check out this working bootstrap example.
I decided to follow bullet two, and add in resolve-url-loader
above sass-loader
in the Webpack config. It now works as expected.
My final Webpack config (for now) looks like this:
{
test: /\.s?[ac]ss$/,
exclude: /node_modules/,
use: [
isProduction
? MiniCssExtractPlugin.loader
: {
// creates style nodes from JS strings
loader: 'style-loader',
options: {
sourceMap: true,
// convertToAbsoluteUrls: true
}
},
{
// CSS to CommonJS (resolves CSS imports into exported CSS strings)
loader: 'css-loader',
options: {
sourceMap: true,
importLoaders: 2
// url: false,
// import: false
}
},
{
loader: 'postcss-loader',
options: {
config: {
ctx: {
cssnext: {},
cssnano: {},
autoprefixer: {}
}
},
sourceMap: true
}
},
{
loader: 'resolve-url-loader',
options: {
attempts: 1,
sourceMap: true
}
},
{
// compiles Sass to CSS
loader: 'sass-loader',
options: { sourceMap: true }
}
]
},
Side Notes
- I noticed that source map paths under "no domain" in Chrome's debugger are repeated. If anyone figures out why, please do share
Remember to include the below side effects in
package.json
, so tree shaking, which happens in production mode, does not delete the extracted css"sideEffects": [
".css",
".scss"
],
Related Topics
How to Force Nested List Items to Be The Same Width as Parent List Item
CSS3 Transition - Change Animation "Anchor Point"
Are There Appearance CSS Rules for Webkit-Overflow-Scrolling: Touch "Handle" in iOS 5
How to Use Calc() Inside Another Function
CSS3 /CSS - Spinning Background Image
Django Staticfiles at Url Root
Why Doesn't Ie10 Display Nested CSS3 3D Transformed Elements
Negative Margins in CSS: Good Tutorial and Tricks Site
Scss Function for Animation Keyframes
CSS Fonts: Howto Convert Multiple Ttf Files into One File
How Can The Pseudo Element Detect The Height of The Non-Pseudo Element
How to Align Panelgrid to Center? Jsf-Primefaces
How to Stack Two Arrow Images (Upvote/Downvote) on Top of Eachother Using CSS
Vscode - Change Highlight Color of Current File
Bootstrap - About Fonts Files (.Eot .Svg .Ttf .Woff and .Woff2) Roles and Usages