-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.4.js
54 lines (53 loc) · 1.28 KB
/
webpack.config.4.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
let path = require('path');
let HtmlWebpackPlugin = require('html-webpack-plugin');
let CleanWebpackPlugin = require('clean-webpack-plugin');
let webpack = require('webpack');
let ExtractTextWebpackPlugin = require('extract-text-webpack-plugin');
module.exports = {
entry: './src/index.js',
output: {
filename: '[name].[hash:8].js',
path: path.resolve('./build')
},
devServer: {
contentBase: './build',
port: 3000,
compress: true,
open: true,
hot: true
},
plugins: [
new ExtractTextWebpackPlugin({
filename:'css/index.css'
}),
new webpack.HotModuleReplacementPlugin(),
new CleanWebpackPlugin(['./build']),
new HtmlWebpackPlugin({
template: './src/index.html',
title: 'webpack',
hash: true,
}),
],
mode: 'development',
resolve: {},
module: {
rules: [ // 从右往左写
{
test: /\.css$/, use: ExtractTextWebpackPlugin.extract({
use: [
{ loader: 'css-loader' }
]
})
},
{
test: /\.less$/, use: ExtractTextWebpackPlugin.extract({
use:[
{ loader: 'css-loader' },
{ loader: 'less-loader' }
]
})
}
]
}
}
// 1.抽离样式 抽离到一个css文件 通过css文件的方式来引用