This repository has been archived by the owner on Apr 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathwebpack.config.js
162 lines (157 loc) · 4.78 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
const webpack = require('webpack');
const BabiliPlugin = require('babili-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const GenerateJsonPlugin = require('generate-json-webpack-plugin');
const marked = require('marked');
const path = require('path');
const merge = require('webpack-merge');
const { version } = require('./manifest/common.json'); // mode controls:
const renderer = new marked.Renderer();
// process.traceDeprecation = true;
// markdown convert to html
module.exports = function webpackConfig(env) {
const [mode, platform, benchmark] = env.split(':');
const config = {
resolve: {
alias: {
react: 'preact-compat',
'react-dom': 'preact-compat',
src: path.join(__dirname, 'src'),
msg: path.join(__dirname, 'src/msg'),
suggestion_engine: path.join(__dirname, 'src/suggestion_engine'),
suggestion_utils: path.join(__dirname, 'src/suggestion_utils'),
lib: path.join(__dirname, 'src/lib'),
scss: path.join(__dirname, 'src/scss')
},
modules: ['./src', './node_modules']
},
entry: {
background_page: 'src/background_page/index.js',
toggle_saka: 'src/content_script/toggle_saka.js',
// 'extensions': './src/pages/extensions/index.js',
// 'info': './src/pages/info/index.js',
// 'options': './src/pages/options/index.js',
saka: 'src/saka/index.jsx',
'saka-options': 'src/options/saka-options.jsx'
},
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
chunks: 'all'
}
}
}
},
output: {
path: `${__dirname}/dist`,
filename: '[name].js'
// sourceMapFilename: '[name].js.map'
},
module: {
rules: [
{
test: /\.(jsx|js)$/,
exclude: /node_modules/,
loaders: ['babel-loader']
},
{
test: /\.(sc|c)ss$/,
loaders: [
'style-loader',
'css-loader',
{
loader: 'sass-loader',
options: {
importer(url, prev) {
if (url.indexOf('@material') === 0) {
const filePath = url.split('@material')[1];
const nodeModulePath = `./node_modules/@material/${filePath}`;
return { file: path.resolve(nodeModulePath) };
}
return { file: url };
}
}
}
]
},
{
test: /\.md$/,
loaders: [
'html-loader',
{
loader: 'markdown-loader',
options: {
renderer
}
}
]
}
]
},
plugins: [
new webpack.optimize.ModuleConcatenationPlugin(),
new CopyWebpackPlugin([
{
from: 'static'
},
{
context: 'src/modes',
from: '**/default.json',
to: 'default_[folder].json'
},
{
context: 'src/modes',
from: '**/config.json',
to: 'config_[folder].json'
}
]),
new GenerateJsonPlugin(
'manifest.json',
merge(
require('./manifest/common.json'),
require(`./manifest/${platform}.json`),
{ version }
),
null,
2
)
]
};
// 1. SAKA_DEBUG: boolean(true | false)
// * true for development builds
// * false for production build
// If you want something to run only in testing/development, use
// if (SAKA_DEBUG) { console.log(variable); }.
// All code within will be removed at build time in production builds.
// platform controls:
// 1. SAKA_PLATFORM: string('chrome' | 'firefox' | 'edge')
// Use this to provide platform specific features, e.g. use shadow DOM
// on chrome but css selectors on firefox and edge for link hint styling
if (mode === 'prod') {
config.plugins = config.plugins.concat([
new BabiliPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
SAKA_DEBUG: JSON.stringify(false),
SAKA_VERSION: JSON.stringify(version),
SAKA_PLATFORM: JSON.stringify(platform),
SAKA_BENCHMARK: JSON.stringify(true)
})
]);
} else {
config.devtool = 'source-map';
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_PLATFORM: JSON.stringify(platform),
SAKA_BENCHMARK: JSON.stringify(benchmark === 'benchmark')
})
]);
}
return config;
};