-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathwebpack.config.js
executable file
·228 lines (225 loc) · 6.31 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
const webpack = require("webpack");
const path = require("path");
const WriteFilePlugin = require("write-file-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const DashboardPlugin = require("webpack-dashboard/plugin");
const CopyPlugin = require("copy-webpack-plugin");
const FileManagerPlugin = require("filemanager-webpack-plugin");
module.exports = {
entry: {
sparnatural: "./src/SparnaturalElement.ts",
"sparnatural-form": "./src/SparnaturalFormElement.ts",
},
output: {
path: path.resolve(__dirname, "./dist"),
filename: "[name].js",
clean: true,
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: { loader: "babel-loader" },
},
{
test: /\.ts$/,
use: "ts-loader",
exclude: /node_modules/,
},
{
test: /\.(sass|scss)$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
},
{
loader: "css-loader", // translates CSS into CommonJS
options: {
sourceMap: true,
},
},
{
loader: "sass-loader", // compiles Sass to CSS
},
],
},
{
test: /\.css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
},
{
loader: "css-loader", // translates CSS into CommonJS
},
],
},
{
test: /\.(png|jp(e*)g|svg|gif)$/,
use: [
{
loader: "url-loader",
options: {
limit: 8000,
// Convert images < 8kb to base64 strings
// in case larger images are processed by file-loader
name: "images/[hash]-[name].[ext]",
},
},
],
},
],
},
resolve: {
fallback: {
util: require.resolve("util/"),
buffer: require.resolve("buffer/"),
stream: require.resolve("stream-browserify"),
querystring: require.resolve("querystring-es3"),
url: require.resolve("url/"),
},
extensions: [".tsx", ".ts", ".js"],
},
plugins: [
new HtmlWebpackPlugin({
filename: "dev-page/index.html", // Pour la page principale
template: __dirname + "/dev-page/index.html",
inject: false,
templateParameters: (compilation, assets) => {
const css = assets.css
.map((filePath) => `<link rel="stylesheet" href="${filePath}" />`)
.join("\n");
const js = assets.js
.map((filePath) => `<script src="${filePath}"></script>`)
.join("\n");
return { css, js };
},
}),
new HtmlWebpackPlugin({
filename: "dev-page/form-page.html", // Utiliser un nom différent pour la nouvelle page
template: __dirname + "/dev-page/form-page.html",
inject: false,
templateParameters: (compilation, assets) => {
const css = assets.css
.map((filePath) => `<link rel="stylesheet" href="${filePath}" />`)
.join("\n");
const js = assets.js
.map((filePath) => `<script src="${filePath}"></script>`)
.join("\n");
return { css, js };
},
}),
new MiniCssExtractPlugin({
filename: "[name].css",
chunkFilename: "[id].css",
}),
new CopyPlugin({
patterns: [
{
from: __dirname + "/dev-page",
to: "dev-page",
globOptions: {
ignore: ["**/index.html", "**/form-page.html"], // Assure-toi de ne pas copier ces fichiers déjà générés
},
},
// Copy the themes CSS directly as static files in a themes subfolder
{
from: __dirname + "/src/assets/stylesheets/themes",
to: "themes",
},
],
}),
new DashboardPlugin(),
// so that JQuery is automatically inserted
// see https://stackoverflow.com/a/28989476
// this will automatically add a "require("jquery")" everytime the jQuery or & symbol are encountered
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
}),
// so that stream works properly, necessary for RDFSpec provider
// see https://stackoverflow.com/questions/68542553/webpack-5process-is-not-defined-triggered-by-stream-browserify
new webpack.ProvidePlugin({
process: "process/browser",
}),
new FileManagerPlugin({
events: {
onEnd: [
{
copy: [
{
source: "./hello-sparnatural/**",
destination: "./dist/hello-sparnatural",
options: { overwrite: true },
},
],
},
{
copy: [
{
source: "./dist/sparnatural.js",
destination: "./dist/hello-sparnatural/",
options: { overwrite: true },
},
],
},
{
copy: [
{
source: "./dist/sparnatural.css",
destination: "./dist/hello-sparnatural/",
options: { overwrite: true },
},
],
},
{
copy: [
{
source: "./dist/sparnatural.js.map",
destination: "./dist/hello-sparnatural/",
options: { overwrite: true },
},
],
},
{
copy: [
{
source: "./dist/sparnatural.css.map",
destination: "./dist/hello-sparnatural/",
options: { overwrite: true },
},
],
},
{
archive: [
{
source: "./dist/hello-sparnatural",
destination: "./dist/hello-sparnatural.zip",
},
],
},
{
copy: [
{
source: "./src/sparnatural-bindings.js",
destination: "./dist/",
options: { overwrite: true },
},
],
},
],
},
}),
],
devServer: {
static: {
directory: path.resolve(__dirname, "./dev-page"),
},
historyApiFallback: true,
hot: true,
open: ["/dev-page"],
},
devtool: "source-map",
};