simple-keyboard/webpack.config.js

102 lines
2.3 KiB
JavaScript
Raw Permalink Normal View History

2023-07-23 01:55:41 +08:00
// Configuration
2021-03-07 15:52:17 +08:00
const path = require('path');
const webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
const getPackageJson = require('./scripts/getPackageJson');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
2022-08-01 07:51:35 +08:00
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
2021-03-07 15:52:17 +08:00
const {
version,
name,
license,
repository,
2022-09-24 14:49:01 +08:00
author
2021-03-07 15:52:17 +08:00
} = getPackageJson('version', 'name', 'license', 'repository', 'author');
const banner = `
${name} v${version}
${repository.url}
Copyright (c) ${author.replace(/ *<[^)]*> */g, " ")} and project contributors.
This source code is licensed under the ${license} license found in the
LICENSE file in the root directory of this source tree.
`;
module.exports = {
mode: "production",
entry: './src/lib/index.ts',
2021-03-26 23:01:40 +08:00
target: 'es5',
2021-03-07 15:52:17 +08:00
output: {
filename: 'index.js',
path: path.resolve(__dirname, 'build'),
library: "SimpleKeyboard",
libraryTarget: 'umd',
2021-03-16 12:41:42 +08:00
clean: true,
globalObject: 'this',
2023-05-26 08:47:11 +08:00
hashFunction: 'xxhash64',
chunkFormat: 'module',
2021-03-16 12:41:42 +08:00
environment: {
arrowFunction: false
}
2021-03-07 15:52:17 +08:00
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({ extractComments: false }),
2022-08-01 07:51:35 +08:00
new CssMinimizerPlugin()
2021-03-07 15:52:17 +08:00
],
},
devServer: {
open: true,
hot: true,
host: "localhost",
static: path.join(__dirname, 'demo'),
port: 9000
},
module: {
rules: [
{
2021-03-16 12:41:42 +08:00
test: /\.m?(j|t)s$/,
2021-03-07 15:52:17 +08:00
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.(sa|sc|c)ss$/,
use: [
MiniCssExtractPlugin.loader,
2021-03-16 12:41:42 +08:00
{ loader: "css-loader" },
{
loader: "postcss-loader",
options: {
postcssOptions: {
plugins: [
[
"autoprefixer"
],
],
},
},
},
2021-03-07 15:52:17 +08:00
],
},
{
test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)$/,
use: ['url-loader'],
}
]
},
plugins: [
new MiniCssExtractPlugin({
filename: 'css/index.css'
}),
new webpack.BannerPlugin(banner)
],
resolve: {
extensions: ['.ts', '.js', '.json']
}
2022-09-24 14:49:01 +08:00
};