forked from italia/publiccode-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.prod.js
95 lines (91 loc) · 2.51 KB
/
webpack.config.prod.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
const path = require("path");
const fs = require("fs");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const devMode = process.env.NODE_ENV !== 'production'
const autoprefixer = require("autoprefixer");
const webpack = require("webpack");
const paths = {
DIST: path.resolve(__dirname, "dist"),
SRC: path.resolve(__dirname, "src"),
JS: path.resolve(__dirname, "src/app")
};
module.exports = env => {
let stage = "production";
let env_file = "./.env";
if (fs.existsSync(env_file)) {
require("dotenv").config({ path: env_file });
}
return {
mode: stage,
entry: path.join(paths.JS, "app.js"),
output: {
path: paths.DIST,
filename: "app.bundle.js"
},
plugins: [
new webpack.DefinePlugin({
"process.env": {
REPOSITORY: JSON.stringify(process.env.REPOSITORY),
ELASTIC_URL: JSON.stringify(process.env.ELASTIC_URL),
VALIDATOR_URL: JSON.stringify(process.env.VALIDATOR_URL),
VALIDATOR_REMOTE_URL: JSON.stringify(process.env.VALIDATOR_REMOTE_URL)
}
}),
new HtmlWebpackPlugin({
template: path.join(paths.SRC, "index.html"),
minify: {
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true,
removeComments: true,
useShortDoctype: true
},
favicon: './src/asset/img/favicon-32x32.png'
}),
new MiniCssExtractPlugin({
filename: devMode ? '[name].css' : '[name].[hash].css',
chunkFilename: devMode ? '[id].css': '[id].[hash].css',
})
],
module: {
rules: [
{
enforce: "pre",
test: /\.s(c)ss/,
loader: "import-glob-loader"
},
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ["babel-loader"] //
},
{
test: /\.(sa|sc|c)ss$/,
use: [
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
'sass-loader',
],
},
{
test: /\.(png|jpg|gif)$/,
use: ["url-loader"]
},
{
test: /\.(woff|woff2|eot|ttf|otf|svg)$/,
use: ["file-loader"]
}
]
},
resolve: {
modules: [path.resolve(__dirname, "src"), "node_modules"],
extensions: [".js", ".jsx", ".json", ".yml"],
alias: {
'cldr$': 'cldrjs',
'cldr': 'cldrjs/dist/cldr'
}
}
};
};