Repository navigation
Expand file tree
/
Copy pathwebpack.config.library.js
More file actions
164 lines (160 loc) · 4.57 KB
/
Copy pathwebpack.config.library.js
File metadata and controls
164 lines (160 loc) · 4.57 KB
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 path = require("path"),
webpack = require("webpack"),
CopyWebpackPlugin = require("copy-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const ESLintPlugin = require("eslint-webpack-plugin");
module.exports = (env) => {
config = {
devtool: "source-map",
entry: {
hyphyvision: ["./src/library-entry.js"],
},
devServer: {
contentBase: ".",
historyApiFallback: true,
disableHostCheck: true,
},
output: {
// Not dist/: the app build (webpack.config.js) owns dist/ and cleans it.
path: path.resolve(__dirname, "lib/"),
filename: "[name].js",
library: "hyphyVision",
libraryTarget: "umd",
hashFunction: "xxhash64",
},
externals: [/^@spond\/[a-zA-Z0-9.\-]+$/, /^@?[a-z\.\-0-9]+$/],
module: {
rules: [
{
test: /\.(sass|scss|css)$/,
use: [
"style-loader",
"css-loader",
{
loader: "sass-loader",
options: { implementation: require("sass") },
},
],
},
{
test: /\.(js|jsx)?$/,
include: [path.resolve(__dirname, "src")],
use: {
loader: "babel-loader",
},
},
{
test: /\.js$/,
loader: require.resolve("@open-wc/webpack-import-meta-loader"),
},
{
test: require.resolve("jquery"),
loader: "expose-loader",
options: {
exposes: {
globalName: ["jQuery", "$"],
override: false,
},
},
},
{
test: require.resolve("d3"),
loader: "expose-loader",
options: {
exposes: {
globalName: "d3",
override: true,
},
},
},
{
test: require.resolve("underscore"),
loader: "expose-loader",
options: {
exposes: {
globalName: "_",
override: true,
},
},
},
// Fonts and images use webpack 5 asset modules instead of
// url-loader/file-loader. Those loaders hash file names with MD4 via
// node's crypto, which OpenSSL 3 rejects unless node runs with
// --openssl-legacy-provider (a flag older nodes refuse). Asset modules
// hash with output.hashFunction, so the build needs no flag.
{
test: /\.woff(2)?(\?\S*)?$/,
type: "asset",
parser: {
dataUrlCondition: {
maxSize: 10000,
},
},
},
{
test: /\.(eot|ttf|svg|png|jpg|gif)(\?\S*)?$/,
type: "asset/resource",
},
],
},
plugins: [
new ESLintPlugin({
files: "src/**/*.js",
exclude: ["/node_modules/"],
}),
new webpack.ProvidePlugin({
process: "process/browser",
// Free `$` / `d3` references resolve through the (external) packages,
// as in the app build, so the host need not define these globals.
$: "jquery",
jQuery: "jquery",
d3: "d3",
_: "underscore",
}),
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: "[name].css",
chunkFilename: "[id].css",
}),
new webpack.LoaderOptionsPlugin({ debug: true }),
new webpack.IgnorePlugin({
resourceRegExp: /jsdom$/,
}),
new CopyWebpackPlugin(
{
patterns: [
// {output}/file.txt
{ from: "src/application.scss" },
{ from: "src/variables.scss" },
//{ from: "public/hyphyvision.css" }
],
},
{
// By default, we only copy modified files during
// a watch or webpack-dev-server build. Setting this
// to `true` copies all files.
copyUnmodified: true,
},
),
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1,
}),
],
resolve: {
fallback: {
path: require.resolve("path-browserify"),
zlib: require.resolve("browserify-zlib"),
util: require.resolve("util/"),
process: require.resolve("process/"),
stream: require.resolve("stream-browserify"),
},
alias: {
"phylotree.css": __dirname + "/node_modules/phylotree/phylotree.css",
},
modules: ["src", "node_modules"],
extensions: [".json", ".js", ".jsx", ".scss"],
},
};
return config;
};