2016-10-19 22 views

Trả lời

5

Bạn có thể sử dụng webpack-text-extract-pluggin chịu trách nhiệm biên soạn tất cả các tệp css và nhóm chúng trong một tệp index.css.

Cũng lưu ý rằng bạn cũng cần cài đặt sass-loader để biên dịch scss.

Trong cấu hình webpack:

var ExtractTextPlugin = require('extract-text-webpack-plugin'); 
config = { 
    ..., 
    plugins: [ 
     ..., 
     new ExtractTextPlugin('index.css') 
    ], 
    module: { 
     loaders: [ 
      ... 
      { 
       test: /\.css$/, 
       loader: ExtractTextPlugin.extract('style','css') 
      }, 
      { 
       test: /\.scss$/, 
       loader: ExtractTextPlugin.extract('style', 'css!sass') 
      } 
     ] 
    } 
} 

Trong index.html:

<link rel="stylesheet" type="text/css" href="/index.css"> 

Trong bất kỳ tập tin javascript mà được thông qua webpack:

require("./styles/my-custom-file.scss"); 
3

Bạn có thể có một cái nhìn tại extract-text-webpack-plugin.

Sau khi yêu cầu này trong webpack.config.js của bạn:

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

Bạn có thể viết lại bộ nạp sass của bạn như thế này:

module: { 
    loaders: [ 
     {test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader'}, 
     {test: /\.scss$/, loader: ExtractTextPlugin.extract('style', 'css', 'sass')} 
    ] 
}, 
plugins: [ 
    new ExtractTextPlugin('bundle.css') 
] 

Đối với nhiều lựa chọn hơn và sử dụng kiểm tra liên kết ở trên.

+0

Cảm ơn @ erik-Martijn –

Các vấn đề liên quan