-
-
Notifications
You must be signed in to change notification settings - Fork 393
/
webpack.config.js
188 lines (184 loc) · 6.1 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
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
const path = require('path');
const ROOT = path.resolve(__dirname, 'src');
const SRC = path.resolve(ROOT, 'js');
// this value is tightly coupled with src/js/index.jsx::__webpack_public_path__
const WEBPACK_OUTPUT = path.resolve(ROOT, 'main/webapp/webpack');
const TEMPLATES = path.resolve(ROOT, 'assets');
const GRAILS_VIEWS = path.resolve(__dirname, 'grails-app/views');
const COMMON_VIEW = path.resolve(GRAILS_VIEWS, 'common');
const RECEIVING_VIEW = path.resolve(GRAILS_VIEWS, 'partialReceiving');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const FileManagerPlugin = require('filemanager-webpack-plugin');
module.exports = {
cache: true,
entry: {
app: `${SRC}/index.jsx`,
},
output: {
path: WEBPACK_OUTPUT,
/*
* Don't set publicPath here, because it's hard to know the
* application context at bundle time. Instead, we rely on
* __webpack_public_path__, specified in src/js/index.jsx, q.v.
*/
filename: 'bundle.[hash].js',
chunkFilename: 'bundle.[hash].[name].js',
},
stats: {
colors: false,
},
plugins: [
new ESLintPlugin({}),
new FileManagerPlugin({
events: {
onStart: {
delete: [
WEBPACK_OUTPUT,
],
},
},
}),
new MiniCssExtractPlugin({
filename: 'bundle.[hash].css',
chunkFilename: 'bundle.[hash].[name].css',
}),
/*
* We use the HtmlWebpackPlugin to render templates to .gsp pages. In
* the templateParameters field, ${x} is a JavaScript variable expansion,
* while \${y} is exported literally as ${y} for Grails to later parse
* as a GString. Of particular note, the calls to resource() below depend
* on Grails' Resources plugin and can bypass the asset-pipeline entirely
* (OGBM-404); see the following document's advice beginning with
* "if you do not want to use the asset-pipeline plugin ..."
*
* https://gsp.grails.org/latest/guide/resources.html
*/
new HtmlWebpackPlugin({
filename: `${COMMON_VIEW}/react.gsp`,
template: `${TEMPLATES}/grails-template.html`,
inject: false,
templateParameters: (compilation) => ({
// eslint-disable-next-line no-template-curly-in-string,no-useless-escape
contextPath: '\${util.ConfigHelper.contextPath}',
jsSource: `\${resource(dir: '${path.basename(WEBPACK_OUTPUT)}', file: 'bundle.${compilation.hash}.js')}`,
cssSource: `\${resource(dir: '${path.basename(WEBPACK_OUTPUT)}', file: 'bundle.${compilation.hash}.css')}`,
receivingIfStatement: '',
}),
}),
new HtmlWebpackPlugin({
filename: `${RECEIVING_VIEW}/create.gsp`,
template: `${TEMPLATES}/grails-template.html`,
inject: false,
templateParameters: (compilation) => ({
// eslint-disable-next-line no-template-curly-in-string,no-useless-escape
contextPath: '\${util.ConfigHelper.contextPath}',
jsSource: `\${resource(dir: '${path.basename(WEBPACK_OUTPUT)}', file: 'bundle.${compilation.hash}.js')}`,
cssSource: `\${resource(dir: '${path.basename(WEBPACK_OUTPUT)}', file: 'bundle.${compilation.hash}.css')}`,
receivingIfStatement:
// eslint-disable-next-line no-template-curly-in-string
'<g:if test="${!params.id}">' +
'You can access the Partial Receiving feature through the details page for an inbound shipment.' +
'</g:if>',
}),
}),
],
module: {
rules: [
{
test: /\.jsx?$/,
use: {
loader: 'babel-loader',
options: {
presets: [
'@babel/preset-env',
'@babel/react',
]
},
},
include: SRC,
exclude: /node_modules/,
},
{
test: /\.(sa|sc|c)ss$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
},
{
test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
loader: 'file-loader',
options: {
name: './[hash].[ext]',
postTransformPublicPath: (p) => `__webpack_public_path__ + ${p}`,
},
},
{
test: /\.(woff|woff2)$/,
loader: 'url-loader',
options: {
limit: 5000,
name: './[hash].[ext]',
postTransformPublicPath: (p) => `__webpack_public_path__ + ${p}`,
prefix: 'font/'
},
},
{
test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url-loader',
options: {
limit: 10000,
mimetype: 'application/octet-stream',
name: './[hash].[ext]',
postTransformPublicPath: (p) => `__webpack_public_path__ + ${p}`,
},
},
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url-loader',
options: {
limit: 10000,
mimetype: 'image/svg+xml',
name: './[hash].[ext]',
postTransformPublicPath: (p) => `__webpack_public_path__ + ${p}`,
},
},
{
test: /\.(png|jpg|gif)$/i,
use: [
{
loader: 'url-loader',
options: {
limit: 8192,
},
},
],
},
],
},
optimization: {
minimizer: [
`...`,
new CssMinimizerPlugin(),
],
},
resolve: {
alias: {
root: ROOT,
src: SRC,
components: path.resolve(SRC, 'components'),
hooks: path.resolve(SRC, 'hooks'),
reducers: path.resolve(SRC, 'reducers'),
actions: path.resolve(SRC, 'actions'),
consts: path.resolve(SRC, 'consts'),
tests: path.resolve(SRC, 'tests'),
utils: path.resolve(SRC, 'utils'),
templates: path.resolve(SRC, 'templates'),
store: path.resolve(SRC, 'store'),
css: path.resolve(ROOT, 'css'),
api: path.resolve(SRC, 'api'),
wrappers: path.resolve(SRC, 'wrappers'),
},
extensions: ['.js', '.jsx'],
},
};