-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwebpack.config.js
More file actions
77 lines (74 loc) · 2.45 KB
/
Copy pathwebpack.config.js
File metadata and controls
77 lines (74 loc) · 2.45 KB
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
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = function(webpackEnv, options) {
const isEnvProduction = options.mode === 'production';
const outputPath = isEnvProduction ? path.resolve(__dirname, 'dist') : path.resolve(__dirname, 'dev');
console.log(outputPath);
return {
// モードの設定
mode: isEnvProduction ? 'production' : 'development',
// エントリーポイントの設定
entry: {
popup: './src/popup.jsx', // React用にjsxに変更
contents: './src/contents.js',
background: './src/background.js',
},
output: {
filename: '[name].js',
path: outputPath,
clean: true, // 出力ディレクトリをビルド前にクリーンアップ
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', ['@babel/preset-react', { runtime: 'automatic' }]],
},
},
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader', 'postcss-loader'],
},
],
},
resolve: {
extensions: ['.js', '.jsx'], // .jsxファイルも解決できるように
},
plugins: [
new CopyWebpackPlugin({
patterns: [
{
from: './src/_locales',
to: '_locales',
},
{
from: './src/icon',
to: 'icon',
},
{
from: '**/*.html',
to: '[name][ext]',
context: 'src',
},
{
from: '**/manifest.json',
to: '[name][ext]',
context: 'src',
},
],
}),
],
devServer: {
static: {
directory: path.join(__dirname, 'dist'),
},
compress: true,
port: 3000,
},
};
};