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

unable to generate sourcemap with asset/resource #962

Open
samuelcolvin opened this issue Jun 3, 2021 · 6 comments · May be fixed by #968
Open

unable to generate sourcemap with asset/resource #962

samuelcolvin opened this issue Jun 3, 2021 · 6 comments · May be fixed by #968

Comments

@samuelcolvin
Copy link

Copied from webpack discussion: webpack/webpack#13505

My setup is successfully compiling sass/scss and outputting a .css file which I'm referencing in js, however unfortunately I can't get a .css.map (source map for the scss) file to be generated too.

What I'd really like is the equivalent of

./node_modules/.bin/sass --embed-sources src/styles/main.scss dist/assets/main.css

which generates main.css and main.css.map.

I have the following module rules in webpack.config.js:

    rules: [
      {
        test: /\.tsx?$/,
        loader: 'ts-loader',
        options: {
          // transpileOnly: true,
        },
      },
      {
        test: /\.s[ac]ss$/i,
        type: 'asset/resource',
        generator: {
          filename: 'assets/[name].css[query]',
        },
        use: [
          {
            loader: 'sass-loader',
            options: {
              sourceMap: true,
              sassOptions: {
                outputStyle: 'expanded',
              },
            },
          },
        ],
      },
      {
        test: /\.(css|png|ico|jpe?g|svg|woff2?|ttf)$/i,
        type: 'asset/resource',
      },
    ],

I I know that the sass-loader is generating a source map - I inserted a log statement here:

callback(null, result.css.toString(), map);

and the map is present and populated. However webpack seems to be discarding the map while I need it to be written to assets/[name].css.map.

I've tried numerous values of devtool but it doesn't seem to make any difference. I've also tried adding style-loader and css-loader, but that seems to break the css generating and doesn't cause a source map to be generated.

Is this a limitation of type: 'asset/resource', or am I doing something wrong? Could I implement my own loader to accomplish this?

Notable dependency version:

    "css-loader": "^5.2.6",
    "sass": "^1.34.1",
    "sass-loader": "^12.0.0",
    "style-loader": "^2.0.0",
    "ts-loader": "^9.2.2",
    "webpack": "^5.38.1",
    "webpack-cli": "^4.7.0"

I've also tried something like:

      {
        test: /\.s[ac]ss$/i,
        type: 'asset/resource',
        use: [
          {
            loader: 'sass-loader',
            options: {
              sassOptions: {
                sourceMap: true,  // tried as path too
                sourceMapEmbed: true,
                outputStyle: 'expanded',
              },
            },
          },
        ],
      },

See the above discussion for a custom loader I wrote which resolved this (at the price of lots of other problems)

@xoxys
Copy link

xoxys commented Dec 29, 2021

@alexander-akait What's needed to get the existing PR done?

@alexander-akait
Copy link
Member

Need finish #968 and rebase

@xoxys
Copy link

xoxys commented Dec 29, 2021

Not sure if @cap-Bernardito is still actively working on it. Anything I can help with? I guess I would have to supersede the PR in this case.

@alexander-akait
Copy link
Member

Yes, feel free to resend PR 👍

@jivemedia
Copy link

Still having this issue using asset/resource - take it this was never resolved?

@alexander-akait
Copy link
Member

@jivemedia Feel free to send a PR, you can use it #1010, I think we should to avoid using external for source maps and allow developers to provide any source maps configuration, because it is hard to say what is default good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
@xoxys @samuelcolvin @alexander-akait @jivemedia and others