-
Notifications
You must be signed in to change notification settings - Fork 6
/
webpack.config.js
90 lines (86 loc) · 2.87 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
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const {CheckerPlugin} = require('awesome-typescript-loader');
const ChromeExtensionReloader = require('webpack-chrome-extension-reloader');
const sourceRootPath = path.join(__dirname, 'src');
const distRootPath = path.join(__dirname, 'dist');
const nodeEnv = process.env.NODE_ENV ? process.env.NODE_ENV : 'development';
const webBrowser = process.env.WEB_BROWSER ? process.env.WEB_BROWSER : 'chrome';
const pkgJson = require('./package.json');
module.exports = {
entry: {
background: path.join(sourceRootPath, 'ts', 'background', 'index.ts'),
popup: path.join(sourceRootPath, 'ts', 'popup', 'index.tsx'),
speckle: path.join(sourceRootPath, 'ts', 'page', 'index.ts'),
content: path.join(sourceRootPath, 'ts', 'content', 'index.tsx'),
injection: path.join(sourceRootPath, 'ts', 'injection', 'index.ts')
},
output: {
path: distRootPath,
filename: '[name].js',
},
resolve: {
extensions: ['.js', '.ts', '.tsx', '.json'],
},
module: {
rules: [
{test: /\.(js|ts|tsx)?$/, loader: "awesome-typescript-loader", exclude: /node_modules/},
{test: /\.css$/, use: ['style-loader', 'css-loader', 'resolve-url-loader']},
{test: /\.(jpg|png|gif|jpeg|woff|woff2|eot|ttf|svg)$/, loader: 'url-loader?limit=100000'}
]
},
plugins: [
new CheckerPlugin(),
new HtmlWebpackPlugin({
template: path.join(sourceRootPath, 'html', 'popup.html'),
inject: 'body',
filename: 'popup.html',
title: 'Speckle - Popup Page',
chunks: ['popup'],
}),
new CopyWebpackPlugin([
{
from: path.join(sourceRootPath, 'assets'),
to: path.join(distRootPath, 'assets'),
test: /\.(jpg|jpeg|png|gif|svg)?$/,
},
{
from: path.join(sourceRootPath, 'manifest.json'),
to: path.join(distRootPath, 'manifest.json'),
toType: 'file',
},
{
from: path.join(sourceRootPath, '_locales'),
to: path.join(distRootPath, '_locales'),
}
]),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(nodeEnv),
WEB_BROWSER: JSON.stringify(webBrowser),
PKG_NAME: JSON.stringify(pkgJson.name),
PKG_VERSION: JSON.stringify(pkgJson.version),
}
}),
],
}
if (nodeEnv === 'watch') {
module.exports.watch = true;
module.exports.plugins.push(
new ChromeExtensionReloader({
port: 9128,
reloadPage: true,
entries: {
background: 'background',
popup: 'popup',
contentScript: ['content', 'injection'],
}
})
);
}
if (nodeEnv === 'production') {
module.exports.plugins.push(new CleanWebpackPlugin({verbose: true, dry: false}));
}