forked from ixrock/XTranslate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
executable file
·132 lines (125 loc) · 3.4 KB
/
webpack.config.ts
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
123
124
125
126
127
128
129
130
131
132
import path from 'path'
import webpack from 'webpack'
import HtmlWebpackPlugin from 'html-webpack-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
export = () => {
var isProduction = process.env.NODE_ENV === "production";
var srcPath = path.resolve(__dirname, 'src');
var distPath = path.resolve(__dirname, 'dist');
var optionsPage = path.resolve(__dirname, "options.html");
var componentsDir = path.resolve(srcPath, 'components');
return {
context: srcPath,
entry: {
app: path.resolve(componentsDir, "app/index.tsx"),
background: path.resolve(srcPath, "background/background.ts"),
pageScript: path.resolve(srcPath, "user-script/user-script.tsx"),
pageStyle: path.resolve(srcPath, "user-script/user-script.scss"),
},
output: {
path: distPath,
publicPath: './',
filename: '[name].js'
},
mode: isProduction ? "production" : "development",
devtool: isProduction ? false : "inline-source-map",
optimization: {
minimize: isProduction,
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
fallback: {
crypto: false // ignore browser polyfill warnings from "crypto-js" package
}
},
module: {
rules: [
{
test: /\.tsx?$/,
use: [
{
loader: 'ts-loader',
options: {
compilerOptions: {
// allow to use dynamic import(),
// https://webpack.js.org/guides/code-splitting/#dynamic-imports
module: "esnext"
}
}
}
]
},
{
test: /\.s?css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
sourceMap: true
}
},
{
loader: "sass-loader",
options: {
additionalData: `@import "vars";`,
sassOptions: {
includePaths: [componentsDir]
},
}
},
]
},
{
test: /\.(txt|log)$/,
use: 'raw-loader'
},
{
test: /\.(jpg|png|svg|map|ico)$/,
use: {
loader: 'file-loader',
options: {
name: "assets/[name]-[hash:6].[ext]",
esModule: false,
},
}
},
{
test: /\.(ttf|eot|woff2?)$/,
use: {
loader: 'file-loader',
options: {
name: "assets/[name].[ext]",
esModule: false,
},
},
},
]
},
plugins: [
new HtmlWebpackPlugin({
inject: true,
hash: true,
chunks: ["common", "app"],
filename: path.basename(optionsPage),
template: optionsPage
}),
new MiniCssExtractPlugin({
filename: "[name].css",
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(isProduction ? "production" : "development"),
}
}),
new CopyWebpackPlugin({
patterns: [
{ from: "../manifest.json" },
{ from: "../_locales", to: "_locales" },
{ from: "../assets", to: "assets" },
]
}),
],
};
};