G
G
Grigory Dikiy2017-09-12 08:50:33
Sass
Grigory Dikiy, 2017-09-12 08:50:33

Webpack 2 Sass loader?

Good day! Can't save CSS file after loaders.
Base config

var path = require("path")
var webpack = require('webpack')

module.exports = {
    context: __dirname,

    entry: {
        app: './app/app.js',
        style: './sass/main.scss',
        vendors: ['react'],
    },

    output: {
        path: path.resolve('../static/bundles/local/'),
        filename: '[name]-[hash].js',
    },

    plugins: [
        new webpack.optimize.CommonsChunkPlugin({name: 'vendors', filename: 'vendors.js'}),
    ], // add all common plugins here

    module: {
        rules: []
    },
    
    resolve: {
        modules: ['node_modules', 'bower_components'],
        extensions: ['.js', '.jsx']
    },
}

And the main config
var webpack = require('webpack')
var BundleTracker = require('webpack-bundle-tracker')
var ExtractTextPlugin = require("extract-text-webpack-plugin")
var autoprefixer = require("autoprefixer")
var config = require('./webpack.base.config.js')
var path = require('path')

config.devtool = "#eval-source-map"
config.entry.app = ['webpack-dev-server/client?http://localhost:3001', 'webpack/hot/only-dev-server', './app/app.js'];
config.output.publicPath = 'http://localhost:3001/assets/bundles/';

config.plugins = config.plugins.concat([
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoEmitOnErrorsPlugin(),
    new BundleTracker({ filename: '../static/bundles/webpack-stats.json' }),
    new ExtractTextPlugin('../static/css/main.min.css', {
        allChunks: true
    })
])

config.devServer = {
    publicPath: config.output.publicPath,
    hot: true,
    inline: true,
    historyApiFallback: false,
    stats: 'errors-only',
    port: '3001',
    headers: {
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
        "Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization"
    }
}

config.module.rules.push(
    { test: /\.jsx?$/, exclude: /node_modules/, use: ['react-hot-loader', 'babel-loader'] },
    { test: /\.scss$/, use: ExtractTextPlugin.extract(['css-loader', 'sass-loader'])}
)

module.exports = config

I run it like this:
"start:dev": "webpack-dev-server --config webpack.dev.config.js",

The task is simple: save the file exactly where I specified in the ExtractTextPlugin, but for some reason it does not save

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Grigory Dikiy, 2017-09-12
@frilix

dev server does not save files to disk, so this code did not work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question