facilmap/leaflet/webpack.config.ts

99 wiersze
2.0 KiB
TypeScript
Czysty Zwykły widok Historia

2021-01-23 11:38:26 +00:00
import { Configuration } from "webpack";
2021-02-28 22:17:26 +00:00
import nodeExternals from "webpack-node-externals";
2021-01-23 11:38:26 +00:00
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
2021-02-28 22:17:26 +00:00
function makeExternals(externals: Record<string, string | string[]>): Configuration['externals'] {
const result: Configuration['externals'] = {};
for (const name of Object.keys(externals)) {
result[name] = {
commonjs: name,
commonjs2: name,
amd: name,
root: externals[name]
};
}
return result;
}
module.exports = (env: any, argv: any): Configuration[] => {
2021-01-23 11:38:26 +00:00
const isDev = argv.mode == "development";
2021-02-28 22:17:26 +00:00
const path = __dirname + "/dist/";
2021-01-23 11:38:26 +00:00
2021-02-28 22:17:26 +00:00
const base: Configuration = {
2021-01-23 11:38:26 +00:00
entry: `${__dirname}/src/index.ts`,
resolve: {
extensions: [ ".js", ".ts" ]
},
mode: isDev ? "development" : "production",
devtool: isDev ? "eval-cheap-source-map" : "source-map",
module: {
rules: [
{
2021-02-28 22:17:26 +00:00
resource: /\.ts/,
2021-01-23 11:38:26 +00:00
loader: "ts-loader"
},
2021-01-31 07:59:12 +00:00
{ test: /\.css$/, use: [ "style-loader", "css-loader" ] },
2021-01-23 11:38:26 +00:00
{ test: /\.scss$/, use: [
"style-loader",
{
loader: "css-loader",
options: {
modules: "global"
}
},
"sass-loader"
]},
{
test: /\.svg$/,
type: 'asset/source'
}
]
},
plugins: [
//new BundleAnalyzerPlugin()
],
devServer: {
publicPath: "/dist",
2021-02-28 22:17:26 +00:00
//hotOnly: true,
disableHostCheck: true,
injectClient: false // https://github.com/webpack/webpack-dev-server/issues/2484
2021-01-23 11:38:26 +00:00
}
};
2021-02-28 22:17:26 +00:00
return [
{
...base,
name: "module",
output: {
filename: "facilmap-leaflet.js",
path,
libraryTarget: "commonjs2"
},
optimization: {
minimize: false
},
externalsType: "commonjs2",
externals: nodeExternals({
additionalModuleDirs: [
`${__dirname}/../node_modules`
]
})
},
{
...base,
name: "full",
output: {
filename: "facilmap-leaflet.full.js",
path,
library: ["L", "FacilMap"],
libraryTarget: "umd"
},
externals: makeExternals({
"facilmap-client": "FacilMap.Client",
"leaflet": "L"
})
}
]
2021-01-23 11:38:26 +00:00
};