webpack中的extract-text-webpack-plugin外掛程式使用方法總結

來源:互聯網
上載者:User

標籤:highlight   ons   編譯   npm   load   babel   為什麼   name   說明   

為什麼要用 extract-text-webpack-plugin這個外掛程式,這個外掛程式可以為我們實現樣式模組化,並且在打包的時候可以產生一個總得css檔案。我是在react的項目中用到的。接下來怎麼用呐?

1,首先我們npm安裝 npm install extract-text-webpack-plugin --save-dev.

2,在webpack.config.js中進行配置 首先我們要引入

const ExtractTextWebpack = require("extract-text-webpack-plugin"); 關於裡邊參數的詳細說明可以看git官網https://github.com/webpack-contrib/extract-text-webpack-plugin
    module: {        loaders: [            {                test: /\.js(x)?$/,                loader: "babel-loader",                exclude: /mode_modules/            },            {                test: /\.css$/,                use: ExtractTextWebpack.extract({                    fallback: ‘style-loader‘,                    use: [‘css-loader‘],                    publicPath: path.resolve(__dirname, ‘dist‘)                })            }        ]    }

 3:我們想在編譯後看到這個檔案夾,這樣就會在我們的dist目錄下產生一個 style.css了,如果你用的是less。sass,stylus這個時候你只需要下載相應的loader然後在裡邊做相應的配置就好了

plugins: [        new HtmlWebpackPlugin({            template: path.resolve(__dirname, ‘./src/index.html‘)        }),        new ExtractTextWebpack("style.css")    ]

 

webpack中的extract-text-webpack-plugin外掛程式使用方法總結

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.