-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
122 lines (114 loc) · 3.06 KB
/
webpack.config.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
const webpack = require('webpack');
const path = require('path');
/*
* We've enabled MiniCssExtractPlugin for you. This allows your app to
* use css modules that will be moved into a separate CSS file instead of inside
* one of your module entries!
*
* https://github.com/webpack-contrib/mini-css-extract-plugin
*
*/
// 把less css scss less 文件分离:要使用mini-css-extract-plugin插件
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebPackPlugin = require("html-webpack-plugin");
const OptimizeCss = require('optimize-css-assets-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
module.exports = {
mode: 'development',
entry: path.resolve(__dirname, 'src/index.js'),
output: {
library: 'CMdEditor',
libraryTarget: 'umd',
filename: 'cMdEditor.js',
path: path.resolve(__dirname, 'dist')
},
devtool: 'inline-source-map',
devServer: {
contentBase: path.join(__dirname, "dist"),
compress: true,
port: 9000
},
plugins: [
// 删除 dist 中旧文件
new CleanWebpackPlugin(['dist']),
// 生成 .html 文件
new HtmlWebPackPlugin({
template: "./src/index.html",
filename: "./index.html"
}),
// 压缩生成后的 .css
new OptimizeCss({
cssProcessor: require('cssnano')
}),
new MiniCssExtractPlugin({
path: path.resolve(__dirname, 'dist'),
// filename: "[name].[chunkhash:8].css",
filename: "cMdEditor.css",
chunkFilename: "[id].css"
})
],
module: {
rules: [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: ['env']
}
},
{
test: /\.css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
}
},
// 如果使用 `MiniCssExtractPlugin.loader` 这里就不要使用了
// 使用后会报错 `webpack ReferenceError: window is not defined`
// {
// loader: 'style-loader',
// options: {
// sourceMap: true
// }
// },
{
loader: 'css-loader',
},
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: [
// Notice: css 添加浏览器前缀
require('autoprefixer')()
]
}
}
]
},
{
test: /\.less$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
}
},
// "style-loader",
{loader: 'css-loader',options: {importLoaders: 2}}, //2代表css-loader后还需要几个loader
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: [
require('autoprefixer')({browsers:['last 2 versions']})
]
}
},
'less-loader'
]
}
]
},
}