webpack react 單獨打包 CSS

webpack react 單獨打包 CSS

webpack require css的方法,默認會把css 打入到js文件中,加載順序有問題,若是須要打出獨立的css文件css

操做步驟:

step1:

安裝 webpack plugin 插件html

npm install extract-text-webpack-plugin --savereact

step2:

修改 webpack.config.js 配置webpack

引用plugingit

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

config的module 中:web

{ test: /\.less$/, loader: ExtractTextPlugin.extract("style-loader", "css-loader","less-loader") },

最後plugins添加npm

plugins: [ new ExtractTextPlugin("./css/[name][hash:8].css") ]

問題

Q: Module build failed: ReferenceError: window is not defined.less

A: 修改loaderui

錯誤示範: loader: ExtractTextPlugin.extract("style-loader!css-loader!less-loader")

正確示範: loader: ExtractTextPlugin.extract("style-loader", "css-loader","less-loader")

參考文章: 

1. https://webpack.github.io/docs/stylesheets.html

2. http://stackoverflow.com/questions/28223040/window-not-defined-error-when-using-extract-text-webpack-plugin-react

相關文章
相關標籤/搜索