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

SourceMap not working with Webpack 4.8.1 #141

Closed
heyalbert opened this issue May 12, 2018 · 10 comments
Closed

SourceMap not working with Webpack 4.8.1 #141

heyalbert opened this issue May 12, 2018 · 10 comments

Comments

@heyalbert
Copy link

Hey guys,

Sadly, sourcemap is not working at all. Webpack 4.8.1 doesn't generate a .map in combination with mini-css-extract-plugin and sass-loader. Any fix?

Plugin configuration:

        new MiniCssExtractPlugin({
            filename: 'css/styles.css'
        }),

Rules:

...
devtool: "source-map", // any "source-map"-like devtool is possible
    module: {
        rules: [
            {
                test: /\.css$/,
                use: [
                    MiniCssExtractPlugin.loader,
                    {
                        loader: 'css-loader',
                        options: { sourceMap: true },
                    },
                ]
            },
            {
                test: /\.scss$/,
                use: [
                    MiniCssExtractPlugin.loader,
                    {
                        loader: 'css-loader',
                        options: { sourceMap: true },
                    },
                    {
                        loader: 'sass-loader',
                        options: { sourceMap: true },
                    },
                ]
...

Output:

          Asset       Size      Chunks             Chunk Names
 css/styles.css  101 bytes        main  [emitted]  main
    ./bundle.js    412 KiB        main  [emitted]  main
./bundle.js.map   88 bytes  main, main  [emitted]  main, main
     index.html  230 bytes              [emitted]
Entrypoint main = css/styles.css ./bundle.js ./bundle.js.map ./bundle.js.map

As you can see, a style.css.map is not generated.

Furthermore: I started a project to try out different configurations.
https://github.com/heyalbert/webpack-starterkit

@alexander-akait
Copy link
Member

@heyalbert interesting, looks like bug, feel free to investigate and send PR 👍

@matallo
Copy link

matallo commented May 15, 2018

I've been able to replicate and get both working, @heyalbert do you happen to have OptimizeCSSAssetsPlugin ?

@pldg
Copy link

pldg commented May 23, 2018

I confirm that source maps will not be generated if OptimizeCSSAssetsPlugin is enable.

I'm using "webpack": "^4.8.3", "mini-css-extract-plugin": "^0.4.0", "optimize-css-assets-webpack-plugin": "^4.0.1"

@alexander-akait
Copy link
Member

Looks like bug in OptimizeCSSAssetsPlugin, somebody create issue?

@hbobenicio
Copy link

Same issue here. When I use OptimizeCSSAssetsPlugin along side with MiniCssExtractPlugin, even if the project is configured to use source maps (devtool: 'source-maps' or with SourceMapDevToolPlugin), the source map is not generated.

@hbobenicio
Copy link

@evilebottnawi

I've created this issue there:
NMFR/optimize-css-assets-webpack-plugin#53

@hbobenicio
Copy link

Got it working! Just realized that the defaults are {} and it's passed to cssnano. You need to setup the map property on it. Just did:

      new OptimizeCSSAssetsPlugin({
        cssProcessorOptions: {
          map: {
            inline: false
          }
        }
      })

and it worked for me. Created also a PR for better docs at their README.md

Anyway. I think this is not related to this project and this issue can be closed.
Maybe some docs could be improved here to, like replacing the suggested

new OptimizeCSSAssetsPlugin({})

to

      new OptimizeCSSAssetsPlugin({
        cssProcessorOptions: {
          map: {
            inline: false // set to false if you want CSS source maps
          }
        }
      })

Can anyone confirm if it works for you guys, before changing docs?

@pldg
Copy link

pldg commented May 30, 2018

Still buggy, incorrect filename reference

@hbobenicio
Copy link

Yes... I see now your point, @pldg . You're totally correct, this is still buggy. Sorry for my blidness! And thanks for taking the time to explaining it.

@shafqatalix
Copy link

shafqatalix commented Jul 31, 2018

this works:
new OptimizeCSSAssetsPlugin({ cssProcessorOptions: { map: { inline: false, annotation: true, } } })

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

7 participants