webpack-sass-postcss-loader-单个css文件

来源:互联网 发布:java画流程 编辑:程序博客网 时间:2024/06/06 07:13

1:初始化webpack

mkdir webpack-demo && cd webpack-demonpm init -ynpm install --save-dev webpack

2: package.json 文件配置

{  "name": "webpack-demo",  "version": "1.0.0",  "description": "",  "main": "index.js",  "scripts": {    "test": "echo \"Error: no test specified\" && exit 1",    "build": "webpack",    "watch": "webpack --watch"  },  "keywords": [],  "author": "",  "license": "ISC",  "devDependencies": {    "autoprefixer": "^7.1.4",    "css-loader": "^0.28.7",    "extract-text-webpack-plugin": "^3.0.0",    "html-webpack-plugin": "^2.30.1",    "node-sass": "^4.5.3",    "postcss-loader": "^2.0.6",    "raw-loader": "^0.5.1",    "sass": "^1.0.0-beta.2",    "style-loader": "^0.18.2",    "ts-loader": "^2.3.4",    "webpack": "^3.5.5"  },  "dependencies": {    "lodash": "^4.17.4"  }}

3:postcss.config.js 文件配置

module.exports = {    plugins: {      'autoprefixer': {browsers: 'last 5 version'}    }  } 

4:webpack.config.js

const path = require('path');const ExtractTextPlugin = require('extract-text-webpack-plugin')const HtmlWebpackPlugin = require('html-webpack-plugin');// const webpack = require('webpack');const config = {    entry: {        a: './src/sass/a.scss',        b: './src/sass/b.scss'    },    output: {        filename: '[name].css',        path: path.resolve(__dirname, 'dist')    },    module: {        rules: [{            test: /\.scss$/,            use: ExtractTextPlugin.extract({                fallback: 'style-loader',                use: [                    { loader: 'css-loader', options: { importLoaders: 1 } },                    'postcss-loader',                    { loader: 'sass-loader' }                ]            })        }]    },    plugins: [        // new webpack.optimize.UglifyJsPlugin(),        // new HtmlWebpackPlugin({        //     template: './index.html'        // }),        new ExtractTextPlugin('[name].css')    ]}module.exports = config;

5:安装module

npm install

6:运行

npm run watch
阅读全文
0 0
原创粉丝点击