webpack require css的方法,默認會把css 打入到js文件中,加載順序有問題,若是須要打出獨立的css文件css
安裝 webpack plugin 插件html
npm install extract-text-webpack-plugin --save
react
修改 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")
參考文章: