This repository has been archived by the owner on Jun 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
.juggrc.ts
121 lines (113 loc) · 2.83 KB
/
.juggrc.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
import { extendConfig } from '@axew/jugg';
import { IgnorePlugin } from 'webpack';
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const WriteFilePlugin = require('write-file-webpack-plugin');
const pkg = require('./package.json');
const IS_PROD = process.env.NODE_ENV === 'production';
export default extendConfig({
sourceMap: false,
publicPath: IS_PROD ? './' : '/',
tsCustomTransformers: {
before: [
[
'ts-import-plugin',
{
libraryDirectory: 'lib',
libraryName: 'antd',
style: true,
},
],
'@axew/jugg-plugin-react/lib/ts-rhl-transformer',
],
},
webpack: ({ config }) => {
config.entryPoints.clear().end();
config
.entry('content')
.add(`./src/content`)
.end();
['background', 'options', 'popup'].forEach(name => {
config
.entry(name)
.add(`./src/${name}`)
.end()
.plugin(`html-${name}`)
.use(HtmlWebpackPlugin, [
{
template: `./src/documents/${name}.ejs`,
filename: `${name}.html`,
chunks: [name],
inject: true,
},
]);
});
config
.plugin('copy')
.use(CopyPlugin, [
[
{ from: 'public' },
{
from: 'public/manifest.json',
transform(content) {
// generates the manifest file using the package.json informations
return Buffer.from(
JSON.stringify({
description: pkg.description,
version: pkg.version,
name: pkg.displayName,
...JSON.parse(content.toString()),
}),
);
},
},
],
])
.end()
.plugin('write-file')
.use(WriteFilePlugin)
.end()
// ref: https://github.com/jmblog/how-to-optimize-momentjs-with-webpack#/
// en, zh-cn
.plugin('ignore-moment-locale')
.use(IgnorePlugin, [/^\.\/locale$/, /moment$/])
.end();
if (!IS_PROD) {
config.resolve.alias.merge({
'react-dom': '@hot-loader/react-dom',
});
}
config.resolve.alias.merge({
'@ant-design/icons/lib/dist$': '@/antdIcon',
});
return {
devServer: {
port: 4000,
},
};
},
html: false,
filename: '[name]',
css: {
loaderOptions: {
css: {},
less: {
modifyVars: {
'primary-color': '#66ccff',
'link-color': '#66ccff',
'border-radius-base': '2px',
},
},
postcss: {},
},
},
define: {
DEFINE: {
name: pkg.name,
displayName: pkg.displayName,
version: pkg.version,
FAKE_POPUP_URL: IS_PROD ? '' : process.env.FAKE_POPUP_URL,
},
},
chunks: false,
});