From 0162d1270fe96522203c530e1de688984ae18c50 Mon Sep 17 00:00:00 2001 From: SleepWalker Date: Sat, 2 Apr 2016 13:57:45 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D1=83=D0=BF=D0=BF=D0=BE=D1=80=D1=82=20?= =?UTF-8?q?=D0=BA=D0=B0=D1=80=D1=82=D0=B8=D0=BD=D0=BE=D0=BA=20=D0=B2=20scs?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 ++ webpack.config.js | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 4287f79..d1d7fa0 100644 --- a/package.json +++ b/package.json @@ -68,10 +68,12 @@ "node-sass": "^3.4.2", "phantomjs-prebuilt": "^2.0.0", "postcss-loader": "^0.8.0", + "postcss-url": "^5.1.1", "react-addons-test-utils": "^0.14.3", "sass-loader": "^3.1.2", "sinon": "^1.15.3", "style-loader": "^0.13.0", + "url-loader": "^0.5.7", "webpack": "^1.12.9", "webpack-dev-server": "^1.14.0" } diff --git a/webpack.config.js b/webpack.config.js index 2cdcd30..8913634 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -6,6 +6,7 @@ var webpack = require('webpack'); var ExtractTextPlugin = require('extract-text-webpack-plugin'); var HtmlWebpackPlugin = require('html-webpack-plugin'); var cssnano = require('cssnano'); +var cssUrl = require("postcss-url"); var iconfontImporter = require('./webpack/node-sass-iconfont-importer'); /** @@ -41,6 +42,8 @@ try { throw err; } +var rootPath = path.resolve('./src'); + var webpackConfig = { entry: { app: path.join(__dirname, 'src'), @@ -71,7 +74,7 @@ var webpackConfig = { }, resolve: { - root: path.resolve('./src'), + root: rootPath, extensions: ['', '.js', '.jsx'] }, @@ -135,6 +138,10 @@ var webpackConfig = { test: /\.jsx?$/, exclude: /node_modules/, loader: 'babel' + }, + { + test: /\.(png|gif|jpg)$/, + loader: 'url?limit=1000' } ] }, @@ -147,6 +154,24 @@ var webpackConfig = { }, postcss: [ + cssUrl({ + url: function(url, decl, from, dirname, to, options, result) { + // scss не правильно резолвит относительные урлы. + // добавляем к урлам остаток пути, что бы они были относительно root + // + // Например: + // file: components/ui/foo.scss + // images/foo.png -> components/ui/images/foo.png + + if (url[0] !== '/') { + var relativeToRoot = dirname.split(rootPath + '/')[1]; + + return path.join(relativeToRoot, url); + } + + return url; + } + }), cssnano({ // sourcemap: !isProduction, autoprefixer: {