forked from lusakasa/saka-key
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
131 lines (125 loc) · 3.81 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
123
124
125
126
127
128
129
130
131
const webpack = require('webpack');
const MinifyPlugin = require('babel-minify-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const GenerateJsonPlugin = require('generate-json-webpack-plugin');
const merge = require('webpack-merge');
// process.traceDeprecation = true;
// markdown convert to html
const marked = require('marked');
const renderer = new marked.Renderer();
module.exports = function (env) {
console.log(env);
const [mode, platform, benchmark, firefoxBeta ] = env.split(':');
let version = require('./manifest/common.json').version;
if (firefoxBeta) version += 'beta';
const config = {
entry: {
'background_page': './src/background_page/index.js',
'content_script': './src/content_script/index.js',
'content_script_loader': './src/content_script/loader.js',
// 'help': './src/help/index.js',
'extensions': './src/pages/extensions/index.js',
'info': './src/pages/info/index.js',
'options': './src/pages/options/index.js'
// 'popup': './src/popup/index.js',
},
output: {
path: __dirname + '/dist',
filename: '[name].js',
sourceMapFilename: '[name].js.map' // always generate source maps
},
devtool: 'source-map',
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
// require.resolve needed to work with linked modules
// (e.g. saka-action in development) or build will fail
// presets: [require.resolve('babel-preset-stage-3')]
}
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.md$/,
use: [
{
loader: 'html-loader'
},
{
loader: 'markdown-loader',
options: {
renderer
}
}
]
}
]
},
resolve: {
modules: [
'./src',
'./node_modules'
]
},
plugins: [
new webpack.optimize.ModuleConcatenationPlugin(),
new CopyWebpackPlugin([
{
from: 'static'
},
{
context: 'src/options',
from: '**/default.json',
to: 'default_[folder].json'
},
{
context: 'src/options',
from: '**/config.json',
to: 'config_[folder].json'
}
]),
new GenerateJsonPlugin('manifest.json', merge(
require('./manifest/common.json'),
require(`./manifest/${platform}.json`),
{ version }
), null, 2)
]
};
// extension id must be specified in calls to chrome.runtime.connect
// otherwise clients won't be able to reconnect to background page
// and background commands will stop working
const EXTENSION_ID = JSON.stringify(platform === 'chrome'
? 'hhhpdkekipnbloiiiiaokibebpdpakdp'
: 'a0dd2b80-9ba1-224b-b5fe-3ae14f12d85d');
if (mode === 'prod') {
config.plugins = config.plugins.concat([
new MinifyPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
'SAKA_DEBUG': JSON.stringify(false),
'SAKA_VERSION': JSON.stringify(version),
'SAKA_BENCHMARK': JSON.stringify(true),
'SAKA_PLATFORM': JSON.stringify(platform),
EXTENSION_ID
})
]);
} else {
config.plugins = config.plugins.concat([
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development'),
'SAKA_DEBUG': JSON.stringify(true),
'SAKA_VERSION': JSON.stringify(version + ' dev'),
'SAKA_BENCHMARK': JSON.stringify(benchmark === 'benchmark'),
'SAKA_PLATFORM': JSON.stringify(platform),
EXTENSION_ID
})
]);
}
return config;
};