-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
72 lines (65 loc) · 2.03 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
const webpack = require('webpack');
const path = require('path');
const CopyPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const LiveReloadPlugin = require('webpack-livereload-plugin');
const isEnvDevelopment = process.env.NODE_ENV === 'development';
const babelLoader = {
loader: require.resolve('babel-loader'),
options: { presets: ['react-app'] },
};
const styleLoader = require.resolve('style-loader');
const cssLoader = {
loader: require.resolve('css-loader'),
options: {
importLoaders: 1,
modules: { getLocalIdent: require('react-dev-utils/getCSSModuleLocalIdent') },
},
};
const sassLoader = require.resolve('sass-loader');
module.exports = {
mode: isEnvDevelopment ? 'development' : 'production',
entry: {
content_scripts: path.resolve(__dirname, 'src', 'content_scripts'),
background: path.resolve(__dirname, 'src', 'background'),
slide_iframe: path.resolve(__dirname, 'src', 'content_scripts', 'slide'),
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: (chunkData) => {
return chunkData.chunk.name === 'slide_iframe' ? 'content_scripts/slide.js' : '[name]/index.js';
},
},
devtool: isEnvDevelopment ? 'cheap-module-source-map' : 'source-map',
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
module: {
rules: [
{
test: /\.(js|jsx|ts|tsx)$/,
exclude: /node_modules/,
use: [babelLoader],
},
{
test: /\.(css|scss)$/,
use: [styleLoader, { ...cssLoader, options: { importLoaders: 1 } }, sassLoader],
},
],
},
plugins: [
new webpack.DefinePlugin({
__isEnvDevelopment: isEnvDevelopment,
}),
new CopyPlugin([
{ from: 'manifest.json', context: 'src/' },
{ from: '*', to: 'icons', context: 'src/icons' },
]),
new HtmlWebpackPlugin({
chunks: ['slide_iframe'],
filename: 'content_scripts/slide.html',
minify: false,
}),
isEnvDevelopment && new LiveReloadPlugin(),
].filter((e) => e),
};