This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
92 lines (91 loc) · 1.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
91
92
const NODE_ENV = process.env.NODE_ENV || 'development';
const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );
const CopyPlugin = require( 'copy-webpack-plugin' );
const ESLintPlugin = require( 'eslint-webpack-plugin' );
const path = require( 'path' );
module.exports = {
mode: NODE_ENV,
context: path.resolve( __dirname ),
entry: {
admin: './admin/index.tsx',
},
output: {
path: __dirname,
filename: './build/[name].js',
},
module: {
rules: [
{
test: /.(js|ts|jsx|tsx)$/,
use: [
{
loader: 'babel-loader',
options: {
presets: [
'@babel/preset-env',
[
'@babel/preset-typescript',
{
jsxPragma: 'wp.element.createElement',
jsxPragmaFrag: 'wp.element.Fragment',
},
],
],
plugins: [
[
'@babel/plugin-transform-react-jsx',
{
pragma: 'wp.element.createElement',
pragmaFrag: 'wp.element.Fragment',
},
],
],
},
},
],
exclude: /node_modules/,
},
{
test: /\.(css|scss)$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
},
'css-loader',
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [ require( 'autoprefixer' ) ],
},
},
},
'sass-loader',
],
},
],
},
plugins: [
new MiniCssExtractPlugin( {
filename: './build/[name].css',
} ),
new ESLintPlugin( {
extensions: [ 'js', 'ts', 'jsx', 'tsx' ],
} ),
new CopyPlugin( {
patterns: [
{
from: path.resolve( __dirname, 'index.php' ),
to: path.resolve( __dirname, 'build' ),
},
],
} ),
],
resolve: {
alias: {
react: path.resolve( __dirname, 'stubs/react' ),
'react-dom': path.resolve( __dirname, 'stubs/react' ),
},
extensions: [ '.ts', '.js', '.tsx', '.jsx', '.json' ],
},
};