0

I am trying to compile sass/scss to css for production.

Essentially I was wondering how can you create a file structure for your assets in prod and get the scss files to get complied to css in prod? I have seen in many TUTs, everything gets dumped in a distor public folder. I can do it for JS, but how would you do it for all my assets? Example in the public folder there is a JS folder a image folder, css etc.

This is my webpack.config.js

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

module.exports = {
    entry: {
        app: ['./src/js/app.js']
    },
    output: {
        path: path.resolve(__dirname, 'public/js'),
        filename: 'app.bundle.js',
        publicPath: 'js'
    },
    devServer: {
        inline: true,
        contentBase: './public',
        port: 8888
    },
    module: {
        rules: [
            { 
              test: /\.scss$/, 
              use: ExtractTextPlugin.extract({
                fallback: 'style-loader',
                use : 'css-loader!sass-loader'
              })

            }
        ]
      },
    plugins: [
            new ExtractTextPlugin('styles.css')
    ]
}
Antonio Pavicevac-Ortiz
  • 7,239
  • 17
  • 68
  • 141
  • 1
    From what I can tell based on the provided webpack output, it spit out the styles.css file correctly. Please check `public/js` folder. EDIT: Just noticed you edited the question. You can change the `output.path` to be just `public` and then you should be able to change the configuration of ExtractTextPlugin to write the styles into `css/styles.css`. Same for `output.filename` when it comes to JS build artifacts. – Marek Suscak Apr 29 '17 at 21:50
  • @MarekSuscak Thanks for the info but I can't seem to get that suggestion to work? – Antonio Pavicevac-Ortiz Apr 29 '17 at 21:59
  • 1
    Check out this test repo I set up for you (instructions in readme): https://github.com/mareksuscak/webpack-so-1 – Marek Suscak Apr 29 '17 at 23:04
  • That worked my friend! You saved some hair on my head from being pulled out! – Antonio Pavicevac-Ortiz Apr 30 '17 at 00:40

0 Answers0