-
-
Notifications
You must be signed in to change notification settings - Fork 58
/
wpackio.project.js
228 lines (226 loc) Β· 5.49 KB
/
wpackio.project.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
// include a few node-js APIs
const {
getFileLoaderOptions,
issuerForNonStyleFiles,
issuerForStyleFiles,
getBabelPresets,
getDefaultBabelPresetOptions,
issuerForJsTsFiles,
issuerForNonJsTsFiles,
// eslint-disable-next-line import/no-extraneous-dependencies
} = require('@wpackio/scripts');
module.exports = {
// Project Identity
appName: 'wpackplugin', // Unique name of your project
type: 'plugin', // Plugin or theme
slug: 'wpackio-plugin', // Plugin or Theme slug, basically the directory name under `wp-content/<themes|plugins>`
// Used to generate banners on top of compiled stuff
bannerConfig: {
name: 'WordPress WebPack Bundler',
author: 'Swashata Ghosh',
license: 'GPL-3.0',
link: 'https://wpack.io',
version: '1.0.0',
copyrightText:
'This software is released under the GPL-3.0 License\nhttps://opensource.org/licenses/GPL-3.0',
credit: true,
},
// Files we need to compile, and where to put
files: [
// If this has length === 1, then single compiler
{
name: 'app',
entry: {
main: ['./src/app/index.js'],
mobile: ['./src/app/mobile.js'],
},
// hasTypeScript: false,
// Extra webpack config to be passed directly
webpackConfig: (config, merge, appDir, isDev) => {
const svgoLoader = {
loader: 'svgo-loader',
options: {
plugins: [
{ removeTitle: true },
{ convertColors: { shorthex: false } },
{ convertPathData: false },
],
},
};
// create module rules
const configWithSvg = {
module: {
rules: [
// SVGO Loader
// https://github.com/rpominov/svgo-loader
// This rule handles SVG for javascript files
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: 'file-loader',
options: getFileLoaderOptions(
appDir,
isDev,
false
),
},
svgoLoader,
],
issuer: issuerForNonStyleFiles,
},
// This rule handles SVG for style files
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: 'file-loader',
options: getFileLoaderOptions(
appDir,
isDev,
true
),
},
svgoLoader,
],
issuer: issuerForStyleFiles,
},
],
},
};
// merge the new module.rules with webpack-merge api
return merge(config, configWithSvg);
},
},
// If has more length, then multi-compiler
{
name: 'foo',
entry: {
main: ['./src/foo/foo.js'],
},
// hasTypeScript: false,
// Extra webpack config to be passed directly
webpackConfig: undefined,
},
// Another app just for showing react
// This also uses svgr-loader
{
name: 'reactapp',
entry: {
main: ['./src/reactapp/index.jsx'],
},
// hasTypeScript: false,
webpackConfig: (config, merge, appDir, isDev) => {
const customRules = {
module: {
rules: [
// Config for SVGR in javascript/typescript files
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
issuer: issuerForJsTsFiles,
use: [
{
loader: 'babel-loader',
options: {
presets: getBabelPresets(
getDefaultBabelPresetOptions(
true,
isDev
),
undefined
),
},
},
{
loader: '@svgr/webpack',
options: { babel: false },
},
{
loader: 'file-loader',
options: getFileLoaderOptions(
appDir,
isDev,
false
),
},
],
},
// For everything else, we use file-loader only
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
issuer: issuerForNonJsTsFiles,
use: [
{
loader: 'file-loader',
options: getFileLoaderOptions(
appDir,
isDev,
true
),
},
],
},
],
},
};
// merge and return
return merge(config, customRules);
},
},
{
name: 'tsapp',
// hasTypeScript: true,
typeWatchFiles: ['src/ts/*.{ts,tsx}', 'src/ts/**/*.{ts,tsx}'],
entry: {
main: ['./src/ts/main.ts'],
},
},
],
// Output path relative to the context directory
// We need relative path here, else, we can not map to publicPath
outputPath: 'dist',
// Project specific config
// Needs react?
hasReact: true,
// Needs sass?
hasSass: true,
// Needs less?
hasLess: true,
// Externals
externals: {
jquery: 'jQuery',
},
// Webpack Aliases
alias: undefined,
// Show overlay on development
errorOverlay: true,
// Auto optimization by webpack
// Split all common chunks with default config
// <https://webpack.js.org/plugins/split-chunks-plugin/#optimization-splitchunks>
// Won't hurt because we use PHP to automate loading
optimizeSplitChunks: true,
// Usually PHP and other files to watch and reload when changed
watch: 'inc/**/*.php',
// Hook into babeloverride so that we can add react-hot-loader plugin
jsBabelOverride: defaults => ({
...defaults,
plugins: ['react-hot-loader/babel'],
}),
// Files that you want to copy to your ultimate theme/plugin package
// Supports glob matching from minimatch
// @link <https://github.com/isaacs/minimatch#usage>
packageFiles: [
'inc/**',
'vendor/**',
'dist/**',
'*.php',
'*.md',
'readme.txt',
'languages/**',
'layouts/**',
'LICENSE',
'*.css',
],
// Path to package directory, relative to the root
packageDirPath: 'package',
};