-
Notifications
You must be signed in to change notification settings - Fork 41
/
webpack.config.js
executable file
·164 lines (162 loc) · 4.5 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
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: ["./src/SparnaturalElement.ts" ],
output: {
path: path.resolve(__dirname, "./dist"),
filename: "sparnatural.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 WriteFilePlugin(),
new HtmlWebpackPlugin({
filename: 'dev-page/index.html',
template: __dirname + "/dev-page/index.html",
// inject: 'body',
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: "sparnatural.css",
chunkFilename: "[id].css"
}),
new CopyPlugin({
patterns: [
{
from:__dirname +'/dev-page',
to:'dev-page',
globOptions: {
ignore: ["**/index.html"],
}
},
// Copy the themes CSS directly as static files in a themes subfolder
{
from:__dirname +'/src/assets/stylesheets/themes',
to:'themes'
},
// Copy the bindings file in the dist directory
]
}),
new DashboardPlugin(),
// so that JQuery is automatically inserted
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"
}