2021-01-05 20:55:09 -08:00
|
|
|
// @ts-check
|
|
|
|
|
2024-11-28 20:36:44 -08:00
|
|
|
import { createRequire } from "node:module";
|
|
|
|
const require = createRequire(import.meta.url);
|
|
|
|
import webpack from "webpack";
|
|
|
|
import TerserPlugin from "terser-webpack-plugin";
|
|
|
|
import { __dirname, importWithTypeJson } from "../test/esm-helpers.mjs";
|
|
|
|
const libraryPackageJson = await importWithTypeJson(import.meta, "../package.json");
|
2022-08-16 04:01:53 +00:00
|
|
|
const nodeModulePrefixRe = /^node:/u;
|
2021-01-05 20:55:09 -08:00
|
|
|
|
2024-11-28 20:36:44 -08:00
|
|
|
// eslint-disable-next-line jsdoc/require-jsdoc
|
2021-01-05 20:55:09 -08:00
|
|
|
function config(options) {
|
2022-08-20 16:24:53 -07:00
|
|
|
const { entry, filename, mode, optimization, packageJson } = options;
|
2021-01-05 20:55:09 -08:00
|
|
|
const { name, version, homepage, license } = packageJson;
|
|
|
|
return {
|
|
|
|
"devtool": false,
|
|
|
|
"entry": entry,
|
|
|
|
"externals": {
|
2024-11-28 20:36:44 -08:00
|
|
|
"markdown-it": "markdownit"
|
2021-01-05 20:55:09 -08:00
|
|
|
},
|
|
|
|
"mode": mode,
|
2021-01-06 19:45:15 -08:00
|
|
|
"module": {
|
|
|
|
"rules": [
|
|
|
|
{
|
2023-01-17 04:19:40 +00:00
|
|
|
"test": /\.[cm]?js$/,
|
2024-02-17 15:46:13 -08:00
|
|
|
"exclude": /node_modules/
|
2021-01-06 19:45:15 -08:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2021-01-05 20:55:09 -08:00
|
|
|
"name": name,
|
2022-08-20 16:24:53 -07:00
|
|
|
"optimization": optimization,
|
2021-01-05 20:55:09 -08:00
|
|
|
"output": {
|
|
|
|
"filename": filename,
|
2023-02-08 20:50:28 -08:00
|
|
|
"library": {
|
|
|
|
"name": name.replace(/(-\w)/g, (m) => m.slice(1).toUpperCase()),
|
|
|
|
"type": "var"
|
|
|
|
},
|
2024-11-28 20:36:44 -08:00
|
|
|
"path": __dirname(import.meta)
|
2021-01-05 20:55:09 -08:00
|
|
|
},
|
|
|
|
"plugins": [
|
2022-08-16 04:01:53 +00:00
|
|
|
new webpack.NormalModuleReplacementPlugin(
|
|
|
|
nodeModulePrefixRe,
|
|
|
|
(resource) => {
|
|
|
|
const module = resource.request.replace(nodeModulePrefixRe, "");
|
|
|
|
resource.request = module;
|
|
|
|
}
|
|
|
|
),
|
2021-01-05 20:55:09 -08:00
|
|
|
new webpack.BannerPlugin({
|
|
|
|
"banner": `${name} ${version} ${homepage} @license ${license}`
|
|
|
|
})
|
|
|
|
],
|
|
|
|
"resolve": {
|
|
|
|
"fallback": {
|
|
|
|
"fs": false,
|
2022-05-06 21:04:34 -07:00
|
|
|
"os": false,
|
2021-01-05 20:55:09 -08:00
|
|
|
"path": false,
|
2024-11-28 20:36:44 -08:00
|
|
|
"util": false,
|
|
|
|
"module": require.resolve("./module-stub.cjs")
|
2021-01-05 20:55:09 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-08-20 16:24:53 -07:00
|
|
|
const modeDevelopment = {
|
|
|
|
"mode": "development"
|
|
|
|
};
|
|
|
|
const modeProduction = {
|
|
|
|
"mode": "production",
|
|
|
|
"optimization": {
|
|
|
|
"minimizer": [
|
|
|
|
new TerserPlugin({
|
|
|
|
"extractComments": false,
|
|
|
|
"terserOptions": {
|
|
|
|
"compress": {
|
|
|
|
"passes": 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const entryLibrary = {
|
2024-11-28 20:36:44 -08:00
|
|
|
"entry": "./browser-exports.mjs",
|
|
|
|
"packageJson": libraryPackageJson
|
2022-08-20 16:24:53 -07:00
|
|
|
};
|
2024-11-28 20:36:44 -08:00
|
|
|
export default [
|
2021-01-05 20:55:09 -08:00
|
|
|
config({
|
2022-08-20 16:24:53 -07:00
|
|
|
...entryLibrary,
|
|
|
|
...modeDevelopment,
|
|
|
|
"filename": "markdownlint-browser.js"
|
2021-01-05 20:55:09 -08:00
|
|
|
}),
|
|
|
|
config({
|
2022-08-20 16:24:53 -07:00
|
|
|
...entryLibrary,
|
|
|
|
...modeProduction,
|
|
|
|
"filename": "markdownlint-browser.min.js"
|
2021-01-05 20:55:09 -08:00
|
|
|
})
|
|
|
|
];
|