Commit 5ce9631d by hfpp2012 yinsigan

add sass loader

1 parent 8ccdf6ba
import React from 'react'; import React from 'react';
import '../main.css'; import '../main.scss';
export default class App extends React.Component { export default class App extends React.Component {
render() { render() {
......
.text-center { .text-center {
text-align: center; text-align: center;
h1 {
padding: 20px;
}
} }
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
"babel-preset-react": "^6.24.1", "babel-preset-react": "^6.24.1",
"css-loader": "^0.28.1", "css-loader": "^0.28.1",
"extract-text-webpack-plugin": "^2.1.0", "extract-text-webpack-plugin": "^2.1.0",
"node-sass": "^4.5.3",
"sass-loader": "^6.0.5",
"style-loader": "^0.17.0" "style-loader": "^0.17.0"
} }
} }
...@@ -11,6 +11,8 @@ yarn add html-webpack-plugin ...@@ -11,6 +11,8 @@ yarn add html-webpack-plugin
yarn add react react-dom yarn add react react-dom
yarn add --dev sass-loader node-sass
# 产品编译及压缩 # 产品编译及压缩
# https://webpack.js.org/guides/production-build/ # https://webpack.js.org/guides/production-build/
webpack -p webpack -p
......
...@@ -10,6 +10,15 @@ const HtmlWebpackPluginConfig = new HtmlWebpackPlugin({ ...@@ -10,6 +10,15 @@ const HtmlWebpackPluginConfig = new HtmlWebpackPlugin({
inject: 'body' inject: 'body'
}) })
const extractSass = ExtractTextPlugin.extract({
use: [{
loader: "css-loader"
}, {
loader: "sass-loader"
}],
fallback: "style-loader"
})
module.exports = { module.exports = {
entry: './client/index.js', entry: './client/index.js',
output: { output: {
...@@ -19,7 +28,7 @@ module.exports = { ...@@ -19,7 +28,7 @@ module.exports = {
module: { module: {
loaders: [ loaders: [
{ test: /\.(js|jsx)$/, loader: 'babel-loader', exclude: /node_modules/ }, { test: /\.(js|jsx)$/, loader: 'babel-loader', exclude: /node_modules/ },
{ test: /\.css$/, loader: ExtractTextPlugin.extract({ fallback: "style-loader", use: "css-loader" }), exclude: /node_modules/ } { test: /\.scss/, loader: extractSass, exclude: /node_modules/ }
] ]
}, },
plugins: [ plugins: [
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!