Skip to content

Commit

Permalink
📄 ライセンス文の埋め込みとsourcemapフォーマットの修正
Browse files Browse the repository at this point in the history
  • Loading branch information
ci7lus committed Nov 9, 2021
1 parent e10ff68 commit 4bc8fd2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
20 changes: 20 additions & 0 deletions embedLicenseInBundle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { promises as fs } from "fs"
import path from "path"

const main = async () => {
const root = "./dist"
for await (const f of await fs.opendir(root)) {
const licensePath = path.join(root, f.name)
if (!licensePath.endsWith(".licenses.txt")) {
continue
}
const bundlePath = licensePath.replace(".licenses.txt", ".js")
console.info(`${licensePath} -> ${bundlePath}`)
const bundle = await fs.readFile(bundlePath, "utf8")
const license = await fs.readFile(licensePath, "utf8")
const newBundle = `/*\n${license}\n*/\n${bundle}`
await fs.writeFile(bundlePath, newBundle)
await fs.unlink(licensePath)
}
}
main()
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"scripts": {
"dev": "webpack --color -w",
"build": "webpack --color",
"build": "webpack --color && ts-node ./embedLicenseInBundle.ts",
"lint:prettier": "prettier --check './src/**/*.{js,ts,tsx}'",
"format:prettier": "prettier --write './src/**/*.{js,ts,tsx}'",
"lint:eslint": "eslint --max-warnings 0 --cache './src/**/*.{js,ts,tsx}'",
Expand Down
7 changes: 6 additions & 1 deletion tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"extends": "./tsconfig.json",
"include": ["src", "./webpack.config.ts", "./tailwind.config.js"],
"include": [
"src",
"./webpack.config.ts",
"./tailwind.config.js",
"./embedLicenseInBundle.ts"
],
"exclude": ["node_modules"]
}
8 changes: 1 addition & 7 deletions webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const config: (
library: `P${hash}`,
libraryTarget: "var",
},
devtool: "cheap-source-map",
devtool: "cheap-eval-source-map",
module: {
rules: [
{
Expand Down Expand Up @@ -122,12 +122,6 @@ const config: (
plugins: [
new esm(),
new LicenseWebpackPlugin({
addBanner: true,
renderBanner: (_, modules) => {
return `/* ${name}\n${modules.map(
(module) => `\n${module.name}\n${module.licenseText}\n`
)} */\n`
},
licenseTextOverrides: {
"@zenza/components": "MIT License 2021 segabito",
ZenzaWatch: "MIT License 2021 segabito",
Expand Down

0 comments on commit 4bc8fd2

Please sign in to comment.