Skip to content
This repository has been archived by the owner on Apr 28, 2018. It is now read-only.

Usage example with Webpack 2 is added. #8

Merged
merged 1 commit into from Feb 6, 2017

Conversation

ezze
Copy link
Contributor

@ezze ezze commented Feb 6, 2017

No description provided.

@coveralls
Copy link

coveralls commented Feb 6, 2017

Coverage Status

Coverage remained the same at 98.958% when pulling 6324adc on ezze:webpack-2-doc into 1ee2f36 on kisenka:master.

@kisenka kisenka merged commit acc697c into kisenka:master Feb 6, 2017
@kisenka
Copy link
Owner

kisenka commented Feb 6, 2017

Cool, thanks!

@kisenka
Copy link
Owner

kisenka commented Feb 6, 2017

@ezze does it works with Webpack 2? :)

@ezze
Copy link
Contributor Author

ezze commented Feb 6, 2017

@kisenka, yes, it does. I upgraded my project from Webpack 1 to Webpack 2 today and it works fine when resolving from both sass and JS code. The only major change I had to do is to move query part ?fill= of loader's regular expression to resourceQuery. Otherwise this condition is not passed. Do you have any issues with it?

I have something like this in my Webpack config:

const NODE_ENV = process.env.NODE_ENV === 'production' ? 'production' : 'development';
const NO_EXTRACT = !!process.env.NO_EXTRACT;
const THEME = process.env.THEME ? process.env.THEME : 'cyan';

const sassLoader = [{
        loader: 'css-loader',
        options: {
            discardComments: {
                removeAll: true
            }
        }
    },
    'postcss-loader',
    'svg-fill-loader/encodeSharp', {
        loader: 'resolve-url-loader',
        options: {
            keepQuery: true
        }
    }, {
        loader: 'sass-loader',
        options: {
            sourceMap: true,
            data: `$theme: "${THEME}"`
        }
    }
];

const sassRule = {
    test: /\.(sass|scss)$/,
    use: NO_EXTRACT ? ['style-loader'].concat(sassLoader) : ExtractTextPlugin.extract({
        use: sassLoader,
        fallback: 'style-loader',
        publicPath: '../'
    }),
    include: [
        path.resolve(__dirname, 'src')
    ]
};

const svgFillRule = {
    test: /\.svg$/,
    resourceQuery: /^\?fill=/,
    use: [
        'file-loader?name=img/vector/[name].[hash:6].[ext]',
        'svg-fill-loader'
    ]
};

const config = {
    module: {
        rules: [
            ...
            sassRule,
            svgFillRule
        ]
    },
    ...
};

...

if (!NO_EXTRACT) {
    config.plugins.push(new ExtractTextPlugin({
        filename: 'css/[name].' + (NODE_ENV === 'development' ? '' : '[chunkhash:6].') + 'css',
        allChunks: true
    }));
}

export default config;

@kisenka
Copy link
Owner

kisenka commented Feb 6, 2017

Do you have any issues with it?
No, I am on webpack 1 now, but planning to upgrade soon, so your experience is helpful.

I have something like this in my Webpack config:
Oh my, looking like programming in configuration! :)

@ezze
Copy link
Contributor Author

ezze commented Feb 6, 2017

Oh my, looking like programming in configuration! :)

Loader rules were splitted for easier excluding by commenting during the migration. Now they look better. Thanks. :)

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

Successfully merging this pull request may close these issues.

None yet

3 participants