-
Notifications
You must be signed in to change notification settings - Fork 287
/
webpack.common.js
145 lines (142 loc) · 3.65 KB
/
webpack.common.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* eslint-disable */
const webpack = require('webpack')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { VueLoaderPlugin } = require('vue-loader')
const VuetifyLoaderPlugin = require('vuetify-loader/lib/plugin')
const path = require('path')
const config = {
development: {
__CLIENT_ID__: '530831729511-eq8apt6dhjimbmdli90jp2ple0lfmn3l.apps.googleusercontent.com',
__DEV_CSP__: process.env.MOZ ? '' : ' http://localhost:8098 chrome-extension://nhdogjmejiglipccpnnnanhbledajbpd',
__EXT_NAME__: 'better-onetab (dev)',
__CONTENT_SCRIPTS_MATCHES__: process.env.MOZ ? '*://*/*' : 'http://127.0.0.1:3000/*',
},
production: {
__CLIENT_ID__: '530831729511-dclgvblhv7var13mvpjochb5f295a6vc.apps.googleusercontent.com',
__DEV_CSP__: '',
__EXT_NAME__: '__MSG_ext_name__',
__CONTENT_SCRIPTS_MATCHES__: 'https://boss.cnwangjie.com/*',
}
}
const resolve = (...paths) => path.join(__dirname, ...paths)
const mode = process.env.NODE_ENV || 'development'
const moz = process.env.MOZ
module.exports = {
entry: {
app: ['./src/app/index.js'],
background: ['./src/background/index.js'],
content: './src/content.js',
exchanger: './src/exchanger.js',
},
output: {
path: resolve('dist'),
filename : '[name].js',
},
plugins: [
new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, /zh-cn/),
new webpack.DefinePlugin({
DEBUG: mode === 'development',
PRODUCTION: mode !== 'development',
MOZ: moz,
}),
new CleanWebpackPlugin(['dist']),
new CopyWebpackPlugin([
{
from: 'src/manifest.json',
to: 'manifest.json',
transform(content, path) {
content = content.toString()
if (mode in config) {
Object.entries(config[mode]).map(([key, value]) => {
content = content.replace(new RegExp(key, 'g'), value)
})
}
return content
}
},
{ from: 'src/assets/icons', to: 'assets/icons' },
{ from: 'src/_locales', to: '_locales' },
]),
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'src/app/index.html',
excludeChunks: ['background', 'content', 'exchanger'],
inject: true,
}),
new VueLoaderPlugin(),
new VuetifyLoaderPlugin(),
],
performance: {
hints: false,
},
optimization: {
splitChunks: {
name: true,
minChunks: Infinity,
},
minimizer: [],
},
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
'vue$': 'vue/dist/vue.esm.js',
'@': resolve('src'),
}
},
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
},
{
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('src')],
},
{
test: /\.css$/,
use: [
'vue-style-loader',
'css-loader'
]
},
{
test: /\.scss$/,
use: [
'vue-style-loader',
'css-loader',
'sass-loader'
]
},
{
test: /\.styl/,
use: [
'vue-style-loader',
'css-loader',
'stylus-loader'
]
},
{
test: /\.(woff2?|eot|ttf|otf|svg)(\?.*)?$/,
loader: 'file-loader',
options: {
useRelativePath: true,
},
},
{
test: /\.png$/,
use: 'url-loader?mimetype=image/png'
},
{
test: /\.md$/,
use: [
{ loader: "html-loader" },
{ loader: "markdown-loader" },
]
},
]
}
}