-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.babel.js
137 lines (128 loc) · 3.35 KB
/
webpack.config.babel.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
const path = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const TerserJSPlugin = require('terser-webpack-plugin')
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const entries = {
index: ['regenerator-runtime', path.join(__dirname, '/src/index.tsx')],
}
const minifiedEntries = {
'index.min': ['regenerator-runtime', path.join(__dirname, '/src/index.tsx')],
}
export default ({ NODE_ENV: env }) => ({
mode: env,
entry: {
...entries,
...(env === 'production' ? minifiedEntries : {}), // Generate additional entries in prod only
},
output: {
path: path.resolve(__dirname, './dist'),
filename: '[name].js',
libraryTarget: 'umd',
globalObject: 'this',
libraryExport: 'default',
library: 'WPLFReactComponent',
},
resolve: {
extensions: ['.mjs', '.ts', '.tsx', '.js'],
// uncomment if enabling webpack-dev-server
// alias:
// env === "development"
// ? {
// "react-dom": "@hot-loader/react-dom",
// }
// : {},
},
externals: {
// Any libraries provided by WordPress should be excluded from the bundle.
// react: 'React',
// 'react-dom': 'ReactDOM',
react: {
commonjs: 'react',
commonjs2: 'react',
amd: 'React',
root: 'React',
},
'react-dom': {
commonjs: 'react-dom',
commonjs2: 'react-dom',
amd: 'ReactDOM',
root: 'ReactDOM',
},
'@libreform/libreform': {
commonjs: '@libreform/libreform',
commonjs2: '@libreform/libreform',
amd: 'WPLF',
root: 'WPLF',
},
},
optimization:
env === 'production'
? {
minimizer: [
new TerserJSPlugin({
test: /\.min\.m?js(\?.*)?$/i,
}),
new OptimizeCSSAssetsPlugin({
assetNameRegExp: /\.min\.css$/g,
}),
],
}
: {},
plugins: [
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: '[name].css',
chunkFilename: '[id].css',
}),
],
// stats: 'errors-warnings',
devtool: env !== 'production' ? 'inline-source-map' : false,
module: {
rules: [
{
test: /\.(png|jpe?g|gif|svg)$/i,
use: [
{
loader: 'file-loader',
},
],
},
{
test: /\.(js)x?$/,
exclude: /(node_modules)/,
use: 'babel-loader',
},
{
test: /\.(ts)x?$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
},
{
loader: 'ts-loader',
},
],
},
{ test: /\.(woff|woff2|eot|ttf)$/, loader: 'url-loader' },
{
test: /\.(scss|css)$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
// you can specify a publicPath here
// by default it uses publicPath in webpackOptions.output
publicPath: '../',
hmr: process.env.NODE_ENV === 'development',
},
},
'css-loader', // translates CSS into CommonJS
'postcss-loader', // autoprefixer etc
'sass-loader', // compiles Sass to CSS, using Node Sass by default
],
},
],
},
})