-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
81 lines (76 loc) · 2.34 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
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const UglifyJSPlugin = require("uglifyjs-webpack-plugin");
const {ImageminWebpackPlugin} = require("imagemin-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const fs = require('fs');
function generateHtmlPlugins(templateDir) {
const templateFiles = fs.readdirSync(path.resolve(__dirname, templateDir));
return templateFiles.map(item => {
const parts = item.split('.');
const name = parts[0];
const extension = parts[1];
const injectStatus = name === 'index';
return new HtmlWebpackPlugin({
filename: `${name}.html`,
template: path.resolve(__dirname, `${templateDir}/${name}.${extension}`),
inject: true
})
});
}
const htmlPlugins = generateHtmlPlugins('./src/templates/');
module.exports = {
entry: {
popup: path.join(__dirname, "src/index.ts")
},
output: {
path: path.join(__dirname, "dist"),
filename: "[name].js"
},
devServer: {
host: '127.0.0.1',
compress: true,
disableHostCheck: true
},
module: {
rules: [
{
exclude: /node_modules/,
test: /\.tsx?$/,
use: ["ts-loader"]
},
{
test: /\.less$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader','less-loader']
},
{
test: /\.(png|gif|jpe?g)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[path][name].[ext]',
},
},
'img-loader',
],
},
{
test: /\.woff($|\?)|\.woff2($|\?)|\.ttf($|\?)|\.eot($|\?)|\.svg($|\?)/,
loader: 'url-loader?limit=30000&name=[name]-[hash].[ext]'
}
]
},
plugins: [
new CopyWebpackPlugin([
{from: 'src/icon', to: 'src/icon'},
]),
new MiniCssExtractPlugin({
filename: './src/componentsLibrary.css',
})
].concat(htmlPlugins),
resolve: {
extensions: [".ts", ".tsx", ".js", '.css']
}
};