forked from energiacte/visorepbd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
263 lines (254 loc) · 8.07 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
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
"use strict";
const autoprefixer = require("autoprefixer");
const path = require("path");
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const eslintFormatter = require("react-dev-utils/eslintFormatter");
const TerserJSPlugin = require("terser-webpack-plugin"); // JS minifier (webpack default)
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const ManifestPlugin = require("webpack-manifest-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const production = process.env.NODE_ENV === "production";
// Source maps are resource heavy and can cause out of memory issue for large source files.
const shouldUseSourceMap = production
? process.env.GENERATE_SOURCEMAP !== "false"
: true;
// Permitirmos usar la variable de entorno EPBDURLPREFIX para añadir prefijo
// a las direcciones estáticas y la url del servicio que llamamos con ajax
const epbdurlprefix = process.env.EPBDURLPREFIX || "";
const PATHS = {
app: path.resolve(path.join(__dirname, "app")),
wasm: path.resolve(path.join(__dirname, "wasm")),
build: path.resolve(path.join(__dirname, "build")),
nodedir: "node_modules",
node: path.resolve(path.join(__dirname, "node_modules")),
styles: path.resolve(path.join(__dirname, "app", "css")),
images: path.resolve(path.join(__dirname, "app", "img")),
components: path.resolve(path.join(__dirname, "app", "components")),
actions: path.resolve(path.join(__dirname, "app", "actions")),
reducers: path.resolve(path.join(__dirname, "app", "reducers")),
store: path.resolve(path.join(__dirname, "app", "store"))
};
var plugins = [
// This pulls out webpack module IDs that changes every build to help with caching
new webpack.HashedModuleIdsPlugin(),
// Inject the build date as an environment variable
new webpack.DefinePlugin({
"process.env": {
BUILD_DATE: JSON.stringify(new Date())
}
}),
new webpack.HotModuleReplacementPlugin(),
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: production ? "[name].[hash].css" : "[name].css",
chunkFilename: production ? "[id].[hash].css" : "[id].css"
}),
new HtmlWebpackPlugin({
// https://github.com/jaketrent/html-webpack-template
template: "app/index.template.html",
title: "VisorEPBD: implementación de la ISO 52000-1 para el CTE DB-HE",
inject: "head",
appMountId: "visorepbdapp",
favicon: 'app/img/favicon.ico',
filename: "./index.html", // relativo al output path
minify: {
collapseWhitespace: true,
collapseInlineTagWhitespace: true,
keepClosingSlash: true,
removeRedundantAttributes: true,
removeComments: true,
removeEmptyAttributes: true,
removeRedundantAttributes: true,
removeStyleLinkTypeAttributes: true,
useShortDoctype: true
}
})
];
if (production) {
// Production plugins go here
plugins = plugins.concat([
// Cleanup the builds/ folder before compiling final assets
new CleanWebpackPlugin(),
// Prevent Webpack from creating too small chunks
new webpack.optimize.MinChunkSizePlugin({ minChunkSize: 51200 }), // ~50kb
// Generate a manifest file which contains a mapping of all asset filenames
// to their corresponding output file so that tools can pick it up without
// having to parse `index.html`.
new ManifestPlugin({ fileName: "asset-manifest.json" }),
new webpack.optimize.AggressiveMergingPlugin()
]);
}
var config = {
mode: production ? "production" : "development",
cache: production ? false : true,
devtool: production
? shouldUseSourceMap
? "cheap-module-source-map"
: false
: "source-map",
entry: PATHS.app,
optimization: {
runtimeChunk: true,
splitChunks: {
chunks: "all"
},
minimizer: [
new TerserJSPlugin({
parallel: true,
sourceMap: production ? false : true,
terserOptions: {
warnings: false,
ie8: false
}
}),
new OptimizeCSSAssetsPlugin({
assetNameRegExp: /\.optimize\.css$/g,
cssProcessor: require("cssnano"),
cssProcessorPluginOptions: {
preset: ["default", { discardComments: { removeAll: true } }]
},
canPrint: true
})
]
},
output: {
path: PATHS.build,
pathinfo: production ? false : true, // /* filename */ comments to generated requires in otuput
filename: "[name].[hash:8].js",
chunkFilename: "[name].[chunkhash:8].js",
// publicPath: "http://localhost:8080/", // Development server
// publicPath: "http://example.com/", // Production
publicPath: production ? epbdurlprefix : "" // This is used to generate URLs to e.g. images,css
},
resolve: {
modules: [PATHS.app, PATHS.wasm, PATHS.node, PATHS.nodedir],
extensions: [".web.js", ".js", ".web.jsx", ".jsx", ".json", ".wasm"],
alias: {
// Para usar alias en imports
styles: PATHS.styles,
components: PATHS.components,
img: PATHS.images,
actions: PATHS.actions,
reducers: PATHS.reducers,
store: PATHS.store,
node: PATHS.node
}
},
module: {
strictExportPresence: true,
rules: [
// First, run the linter.
// It's important to do this before Babel processes the JS.
{
test: /\.(js|jsx)$/,
include: PATHS.app,
enforce: "pre",
use: [
{
options: {
formatter: eslintFormatter,
eslintPath: require.resolve("eslint")
},
loader: "eslint-loader"
}
]
},
{
// JS, JSX: BABEL
test: /\.(js|jsx)?$/,
include: PATHS.app,
loader: "babel-loader"
},
{
// CSS
test: /\.css$/,
include: [PATHS.app, PATHS.node],
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
importLoaders: 1,
sourceMap: production ? shouldUseSourceMap : false
}
},
{
loader: "postcss-loader",
options: {
postcssOptions: {
path: __dirname + "/postcss.config.js"
}
}
}
]
},
{
// SASS
test: /\.scss$/,
include: PATHS.app,
use: [
production ? MiniCssExtractPlugin.loader : "style-loader",
{
loader: "css-loader",
options: {
importLoaders: 1,
sourceMap: production ? shouldUseSourceMap : false
}
},
{
loader: "postcss-loader",
options: {
postcssOptions: {
path: __dirname + "/postcss.config.js"
}
}
},
{
loader: "sass-loader",
options: {
sourceMap: production ? shouldUseSourceMap : false,
// outputStyle: "expanded"
}
}
]
},
{
// IMG direct URLs for the rest
test: [/\.(gif|jpe?g|png)$/i],
include: PATHS.app,
loader: "img-loader"
},
{
// .ico files
test: /\.ico$/i,
include: PATHS.app,
loader: ["file-loader?name=[name].[ext]", "img-loader"]
},
// required for bootstrap icons
{
test: /\.(woff|woff2|eot|ttf|otf)(\?v=\d+\.\d+\.\d+)?$/,
loader: "file-loader?name=fonts/[name]-[hash:8].[ext]"
},
{
test: /\.(jpg|gif|png|svg)(\?v=\d+\.\d+\.\d+)?$/,
loader: "file-loader?name=img/[name]-[hash:8].[ext]"
},
// Bootstrap 3
{
test: /bootstrap-sass\/assets\/javascripts\//,
loader: "imports-loader?jQuery=jquery"
},
// Bootstrap 4
{
test: /bootstrap\/build\/js\/umd\//,
loader: "imports-loader?jQuery=jquery"
}
]
},
plugins: plugins,
performance: { hints: production ? "warning" : false }
};
module.exports = config;