Skip to content
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

Can't Live Edit CSS/SCSS Sources in Chrome Workspaces without file:// #717

Closed
niedfelj opened this issue May 18, 2018 · 13 comments
Closed

Comments

@niedfelj
Copy link

Do you want to request a feature or report a bug?

FEATURE

What is the current behavior?
Sourcemap from sub module css (from sass-loader) is stringified with absolute paths

If the current behavior is a bug, please provide the steps to reproduce.

What is the expected behavior?
Would be great to be able to use Chrome 66 workspaces to live edit files, but Chrome requires that sourceMap has file:// at the beginning

If this is a feature request, what is motivation or use case for changing the behavior?
To use Chrome workspaces to live edit scss/css

Please mention other relevant information such as your webpack version, Node.js version and Operating System.
webpack 4.8.3
node 8.10.0
MacOS 10.13.4

I was able to get the correct behaviour by doing the following on lines 117..132 in loader.js

		var moduleJs;
		if(sourceMap && result.map) {
			// add a SourceMap
			map = result.map;
			if(map.sources) {
				map.sources = map.sources.map(function(source) {
					return "file://"+source.split("!").pop().replace(/\\/g, '/');
				}, this);
				map.sourceRoot = "";
			}
			map.file = map.file.split("!").pop().replace(/\\/g, '/');
			map = JSON.stringify(map);
			moduleJs = "exports.push([module.id, " + cssAsString + ", \"\", " + map + "]);";
		} else {
			moduleJs = "exports.push([module.id, " + cssAsString + ", \"\"]);";
		}

Does it make sense to set this as an option or use another webpack default, for example in the output I'm also using

    output: {
      devtoolModuleFilenameTemplate(info) {
        const newPath =  'file://' + path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')
        return newPath
      },
    },
@alexander-akait
Copy link
Member

alexander-akait commented May 18, 2018

@niedfelj seems you have invalid configuration webpack out of box work with workspaces

@niedfelj
Copy link
Author

@evilebottnawi What should it be? I'm working with the new Shopify slate/slate-tools project. Opened this ticket with them also

Shopify/slate#447

@niedfelj
Copy link
Author

Also reference this issue webpack/webpack#6400

@alexander-akait
Copy link
Member

Looks like we can close this issue in favor webpack/webpack#6400

@niedfelj
Copy link
Author

@evilebottnawi While they are related, they are not the same issue. css-loader is responsible for munging these sourceMaps, there is nothing webpack or that issue can do to resolve it by itself.

@alexander-akait
Copy link
Member

alexander-akait commented May 18, 2018

@niedfelj how you imagine we will fix it in css-loader?

@niedfelj
Copy link
Author

I guess with an option like sourceMapUrlPrefix or a similar callback function as mentioned above with devtoolModuleFilenameTemplate(info) (or maybe look for that output setting and use the same so they output the same file formats?

@alexander-akait
Copy link
Member

alexander-akait commented May 18, 2018

@niedfelj we should first solve this in webpack, maybe add new api, which allow us using this, no new option(s)

@niedfelj
Copy link
Author

niedfelj commented May 18, 2018 via email

@alexander-akait
Copy link
Member

@niedfelj 👍

@HairyRabbit
Copy link

HairyRabbit commented Jul 8, 2018

:)

Anything update here?

image

Happen when I chain loader by 'postcss-loader'

use: [
  'style-loader?sourceMap',
  'css-loader?sourceMap',
  'postcss-loader?sourceMap'
]

Fix sources path and prepend file:/// looks fine for me:

2

@alexander-akait
Copy link
Member

@HairyRabbit your problem already solved in last release and not related to top issue

@alexander-akait
Copy link
Member

Close in favor #622 (comment)

Anyway you can setup editing in dev tools:

  1. Open dev tools.
  2. Click Filesystem in on left panel.
  3. Click Add folder to workspace in left panel.
  4. Add src/lib directory.
  5. Change content of file.

Anyway we should respect devtoolModuleFilenameTemplate and other devtool options, close in favor #622 (comment). Thanks for issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants