6
const path = require('path');

module.exports = {
  entry: './src/scss/screen.scss',

  output: {
    filename: 'screen.css',
    path: path.resolve(__dirname, 'dist'),
  },

  module: {
    rules: [
        {
          test: /\.scss$/,
          use: [
          'style-loader',
            'css-loader',
            'sass-loader'
          ]
        },
      {
        test: /\.jpg$/,
        use: [
          'file-loader',
        ],
      },
    ]
  }
};

This is my webpack.config.js. When I try to compile the SCSS into CSS it creates the screen.css file without any complaints, but the screen.css contains javascript code (from one of the loaders I guess).

Is it even possible to use webpack when the project doesn't really have any javascript file? I just have SCSS Files and Images.

2 Answers 2

4

You should build CSS files by [ExtractTextPlugin][1].

Btw, entry key is using only for js files. Webpack watch imports or requires from entry files and build them all in a single file (I could miss something)

You need to install extract-text-webpack-plugin and require it

var ExtractTextPlugin = require('extract-text-webpack-plugin')

Then update your loader

rules: [
  {
    test: /\.scss$/,
    use: ExtractTextPlugin.extract({
      fallback: "style-loader",
      use: [{loader: 'css-loader'}, 
            {loader: 'sass-loader'}]
    })
  }

And plugins

plugins: [
    new ExtractTextPlugin({
        filename: 'styles.css'
    })
]

However, webpack require have some entry js file. You can just add next code, but don't use this JS file

entry: './app.js',

output: {
    path: join(__dirname, '/build'),
    filename: 'bundle.js'
}

And read more about [entries][2] [1]: https://github.com/webpack-contrib/extract-text-webpack-plugin [2]: https://webpack.js.org/concepts/entry-points/

6
  • Not related to extract-text-plugin, the problem ivsterr has related to the fact that webpack suppose to bundle js files, and if in that js files there are imports for sass file, it will apply the sass-loader.
    – felixmosh
    Commented Aug 19, 2017 at 21:00
  • sass imports in js files? Really ?
    – NechiK
    Commented Aug 19, 2017 at 21:04
  • Yeap, why not? You can use extract-text-plugin to extract the styles from the bundle, but that is not relevant to the issue here.
    – felixmosh
    Commented Aug 19, 2017 at 21:05
  • As I see he needs to build native css file with compiled styles from scss. I gave him solution, how to do it and how all people do it. Why it is not relevant?
    – NechiK
    Commented Aug 19, 2017 at 21:10
  • Cause, he complained that he got js inside his final css file, the reason for that is what I wrote, the entry point should be js file.
    – felixmosh
    Commented Aug 19, 2017 at 21:14
-1

The problem with your webpack.config file is that you gave it an scss file as entry point.

Webpack suppose to bundle js files, therefore you need to specify some js file, there you can import a scss file.

Not the answer you're looking for? Browse other questions tagged or ask your own question.