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

Problems with ExtractTextPlugin on SCSS #51

Closed
b12k opened this issue Oct 31, 2015 · 8 comments
Closed

Problems with ExtractTextPlugin on SCSS #51

b12k opened this issue Oct 31, 2015 · 8 comments

Comments

@b12k
Copy link

b12k commented Oct 31, 2015

Extraction of CSS works absolutely OK.
But when I use "lang='sass'" I get this:

ERROR in ./~/extract-text-webpack-plugin/loader.js?{"remove":true}!./~/css-loader!./~/sass-loader!./~/vue-loader/lib/style-rewriter.js!./~/vue-loader/lib/selector.js?type=style&index=0!./src/App/app.vue
Module build failed: TypeError: content.trim is not a function
    at Object.module.exports (D:\OpenServer\domains\test.dev\node_modules\sass-loader\index.js:211:17)
 @ ./src/App/app.vue 1:0-229

My webpack.config.js:

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

var EXCLUDE = /node_modules|bower_components/;

module.exports = {
    context: path.resolve('src'),
    entry: './index.js',
    output: {
        path: path.resolve('dist'),
        publicPath: '/dist/',
        filename: 'scripts-bundle.min.js'
    },
    module: {
        preLoaders: [
            {
                test: /\.js$/,
                loader: 'eslint',
                exclude: EXCLUDE
            }
        ],
        loaders: [
            {
                test: /\.js$/,
                loader: 'babel',
                exclude: EXCLUDE
            },
            {
                test: /\.scss$/,
                loader: ExtractTextPlugin.extract('style', 'css!autoprefixer!sass'),
                exclude: EXCLUDE
            },
            {
                test: /\.less$/,
                loader: ExtractTextPlugin.extract('style', 'css!autoprefixer!less'),
                exclude: EXCLUDE
            },
            {
                test: /\.css/,
                loader: ExtractTextPlugin.extract('style', 'css!autoprefixer'),
                exclude: EXCLUDE
            },
            {
                test: /\.html$/,
                loader: 'raw',
                exclude: EXCLUDE
            },
            {
                test: /\.vue$/,
                loader: 'vue',
                exclude: EXCLUDE
            }
        ]
    },
    eslint: {
        configFile: path.resolve('.eslintrc')
    },
    babel: {
        optional: ['runtime'],
        loose: 'all',
        nonStandard: false,
        stage: 0
    },
    vue: {
        loaders: {
            css: ExtractTextPlugin.extract('css'),
            scss: ExtractTextPlugin.extract('css!sass')
        }
    },
    autoprefixer: {
        browsers: ['last 2 versions']
    },
    plugins: [
        new BowerPlugin,
        new ExtractTextPlugin('styles-bundle.min.css')
    ],
    watch: true,
    devtool: "source-map"
};

Tested css extraction on "vue-loader-example". The same problem. Here is config:

var webpack = require('webpack'),
    ExtractText = require('extract-text-webpack-plugin');

module.exports = {
  entry: './src/main.js',
  output: {
    path: './dist',
    publicPath: '/dist/',
    filename: 'build.js'
  },
  module: {
    loaders: [
      {
        test: /\.vue$/,
        loader: 'vue'
      }
    ]
  },
  vue: {
    loaders: {
      css: ExtractText.extract('css'),
      stylus: ExtractText.extract('css!stylus')
    }
  },
  plugins: [
    new ExtractText('build.css')
  ]
}

if (process.env.NODE_ENV === 'production') {
  module.exports.plugins = [
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: '"production"'
      }
    }),
    new webpack.optimize.UglifyJsPlugin({
      compress: {
        warnings: false
      }
    }),
    new webpack.optimize.OccurenceOrderPlugin()
  ]
} else {
  module.exports.devtool = '#source-map'
}

Thanx in advance!

@dannyfritz
Copy link

I'm having the same problem. Ultimately, I had to remove vue-loader until this and #53 are sorted out.

I can't quite put my finger on what the code is doing to transform it from a .vue to the 3 separate files, but this is the line i thought was smelly.

vue-loader/lib/loader.js

Lines 68 to 71 in 9985f1f

if (loader !== undefined) {
// lang with default or pre-configured loader
if (loader) loader += '!'
return loader + rewriter

A big question of mine was, do I have to specify the entire loader chain in both the lang="" attribute and on the vue.loaders.scss property? And then when using a plugin, how do the 2 loader strings interact?

@dannyfritz
Copy link

vue-loader is awesome now! thanks

@dannyfritz
Copy link

I'm actually running into one more problem related to this: source-maps.

This works:

less: ExtractTextPlugin.extract('css!less')

This does not:

less: ExtractTextPlugin.extract('css?sourceMap!less?sourceMap')

less-loader and sourcemaps

@yyx990803
Copy link
Member

Fixed in 0.6.3

@dannyfritz
Copy link

So it compiles and has a CSS sourcemap now, but it doesn't point to my original LESS code. It points to a compiled version of my Vue style.

I tried adding <style lang="less?sourceMap">, but that seems to break the extract-text-plugin and syntax highlighting.

2015-11-01_13-29-25

@b12k
Copy link
Author

b12k commented Nov 1, 2015

This is awesome! Thank you for an gorgeous framework!

@yyx990803
Copy link
Member

@dannyfritz fixed again in 6.0.4 :) Should have proper souce map support now

@dannyfritz
Copy link

@yyx990803 I could shed a tear it is so beautiful. Thanks for the awesome quick turn arounds! 😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants