-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
166 lines (157 loc) · 5.08 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
/**
* ! Note: Required dependency in package.json to have webpack successfully built:
* "ajv": "^8.8.2"
* Still an open issue, whether there is a "cleaner" fix
*
* Links:
* - https://stackoverflow.com/questions/70020046/quasar-error-cannot-find-module-ajv-dist-compile-codegen
* - PR, that introduced webpack5 (comment): https://github.com/PrimeDAO/prime-deals-dapp/pull/138#discussion_r806202525
*/
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const Dotenv = require('dotenv-webpack');
const webpack = require("webpack");
const CopyWebpackPlugin = require('copy-webpack-plugin');
console.log("environment: ", `${process.env.DOTENV_CONFIG_PATH}`)
const baseUrl = '/';
const cssLoader = {
loader: 'css-loader',
options: {
modules: false,
// https://github.com/webpack-contrib/css-loader#importloaders
importLoaders: 2
}
};
const sassLoader = {
loader: 'sass-loader',
options: {
sassOptions: {
includePaths: ['node_modules']
}
}
};
const postcssLoader = {
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: ['autoprefixer']
}
}
};
const ensureArray = (config) => config && (Array.isArray(config) ? config : [config]) || []
const when = (condition, config, negativeConfig) =>
condition ? ensureArray(config) : ensureArray(negativeConfig)
module.exports = function (env, _webpackOptions) {
const { analyze, tests, development } = env;
const production = env.production || process.env.NODE_ENV === 'production';
return {
target: 'web',
mode: production ? 'production' : 'development',
devtool: production ? undefined : 'inline-source-map', // TODO make sourcemaps work
entry: {
entry: './src/main.ts'
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: production ? '[name].[contenthash].bundle.js' : '[name].bundle.js'
},
resolve: {
extensions: ['.ts', '.js'],
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
alias: production ? {
// add your production aliasing here
process: 'process/browser',
} : {
...[
'fetch-client',
'kernel',
'metadata',
'platform',
'platform-browser',
'plugin-conventions',
'route-recognizer',
'router',
'router-lite',
'runtime',
'runtime-html',
'testing',
'webpack-loader',
].reduce((map, pkg) => {
const name = `@aurelia/${pkg}`;
map[name] = path.resolve(__dirname, 'node_modules', name, 'dist/esm/index.dev.mjs');
return map;
}, {
'aurelia': path.resolve(__dirname, 'node_modules/aurelia/dist/esm/index.dev.mjs'),
// add your development aliasing here
})
},
fallback: { // this is needed for packages that use native nodejs modules like 'fs', 'os', etc.
"fs": false,
"tls": false,
"os": false,
"assert": false,
"url": false,
"net": false,
"path": false,
"zlib": false,
"http": false,
"https": false,
"stream": false,
"crypto": false,
"crypto-browserify": require.resolve('crypto-browserify'), //if you want to use this module also don't forget npm i crypto-browserify
}
},
devServer: {
historyApiFallback: true,
// open: !process.env.CI,
static: {
directory: path.join(__dirname, '/static'),
},
compress: true,
port: 3340,
hot: true
},
module: {
rules: [
{ test: /\.(png|svg|jpg|jpeg|gif)$/i, type: 'asset' },
{ test: /\.(woff|woff2|ttf|eot|svg|otf)(\?v=[0-9]\.[0-9]\.[0-9])?$/i, type: 'asset' },
{ test: /\.css$/i, use: ['style-loader', cssLoader, postcssLoader] },
{ test: /\.scss$/i, use: ['style-loader', cssLoader, postcssLoader, sassLoader] },
{ test: /\.ts$/i, use: ['ts-loader', '@aurelia/webpack-loader'], exclude: /node_modules/ },
{
test: /[/\\]src[/\\].+\.html$/i,
use: '@aurelia/webpack-loader',
exclude: /node_modules/
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: 'index.html',
metadata: {
// available in index.html //
baseUrl
}
}),
new Dotenv({
// path: `./.env${production ? '' : '.' + (process.env.NODE_ENV || 'development')}`,
path: process.env.DOTENV_CONFIG_PATH,
}),
analyze && new BundleAnalyzerPlugin(),
// Work around for Buffer is undefined:
// https://github.com/webpack/changelog-v5/issues/10
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
process: 'process/browser',
}),
...when(!tests, new CopyWebpackPlugin({
patterns: [
{ from: 'static', to: './', globOptions: { ignore: ['.*'] } }
]
})),
new webpack.EnvironmentPlugin(process.env)
].filter(p => p),
}
}