Skip to content

Commit 22b7786

Browse files
committed
Prep for publishing package
This works on client side: `import { Comical, Bubble, BubbleSpec } from "comicaljs";`
1 parent 9f3f724 commit 22b7786

8 files changed

+2103
-42
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
node_modules
2-
storybook-static
2+
storybook-static
3+
dist
4+
build
5+
yarn-error.log

package.json

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
2-
"name": "comical-js",
2+
"name": "comicaljs",
33
"version": "0.1.0",
44
"description": "Edit cartoon bubble frames around an HTML element",
55
"main": "index.js",
6+
"types": "index.d.ts",
67
"repository": "https://github.com/BloomBooks/comical-js.git",
7-
"author": "John Thomson <[email protected]>",
8+
"author": "SIL Bloom Team & Contributors",
89
"license": "MIT",
910
"private": false,
1011
"devDependencies": {
@@ -14,20 +15,24 @@
1415
"@types/svg.js": "^2.3.1",
1516
"awesome-typescript-loader": "^5.2.1",
1617
"babel-loader": "^8.0.6",
18+
"babel-preset-env": "^1.7.0",
19+
"copy-webpack-plugin": "^5.0.4",
20+
"globule": "^1.2.1",
1721
"npx": "^10.2.0",
1822
"shx": "^0.3.2",
23+
"ts-loader": "^6.2.0",
1924
"typescript": "^3.5.3",
2025
"webpack": "^4.39.2",
21-
"webpack-cli": "^3.3.6"
26+
"webpack-cli": "^3.3.6",
27+
"webpack-merge": "^4.2.2"
2228
},
2329
"dependencies": {
30+
"babel-preset-react": "^6.24.1",
2431
"paper": "^0.12.3"
2532
},
2633
"scripts": {
2734
"storybook": "start-storybook -s ./storyStatic -p 6006",
2835
"build-storybook": "build-storybook",
29-
"makebloomdesktopdir": "shx mkdir ..\\BloomDesktop\\src\\BloomBrowserUI\\node_modules\\comical-js",
30-
"cleanbloomdesktopdir": "shx rm ..\\BloomDesktop\\src\\BloomBrowserUI\\node_modules\\comical-js\\*",
31-
"tobloomdesktop": "shx cp src\\*.ts ..\\BloomDesktop\\src\\BloomBrowserUI\\node_modules\\comical-js"
36+
"build": "shx rm -r dist/ && webpack --config webpack.config-prod.js"
3237
}
3338
}

src/index.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// This file exists to import everything else (and define the module exports).
2+
// It is the root for building the bundle.
3+
4+
import Comical from "./comical";
5+
import Bubble from "./bubble";
6+
import { BubbleSpec, BubbleSpecPattern, TailSpec } from "./bubbleSpec";
7+
8+
export { Comical, Bubble, BubbleSpec, BubbleSpecPattern, TailSpec };

tsconfig.json

+26-26
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
{
2-
"compilerOptions": {
3-
"outDir": "build/lib",
4-
"module": "commonjs",
5-
"target": "es5",
6-
"lib": ["es5", "es6", "es7", "es2017", "dom"],
7-
"sourceMap": true,
8-
"allowJs": false,
9-
"jsx": "react",
10-
"moduleResolution": "node",
11-
"rootDirs": ["src", "stories"],
12-
"baseUrl": "src",
13-
"forceConsistentCasingInFileNames": true,
14-
"noImplicitReturns": true,
15-
"noImplicitThis": true,
16-
"noImplicitAny": true,
17-
"strictNullChecks": true,
18-
"suppressImplicitAnyIndexErrors": true,
19-
"noUnusedLocals": true,
20-
"declaration": true,
21-
"allowSyntheticDefaultImports": true,
22-
"experimentalDecorators": true,
23-
"emitDecoratorMetadata": true
24-
},
25-
"include": ["src/**/*"],
26-
"exclude": ["node_modules", "build", "scripts"]
27-
}
2+
"compilerOptions": {
3+
"outDir": "dist",
4+
"module": "commonjs",
5+
"target": "es5",
6+
"lib": ["es5", "es6", "es7", "es2017", "dom"],
7+
"sourceMap": true,
8+
"allowJs": false,
9+
"jsx": "react",
10+
"moduleResolution": "node",
11+
"rootDirs": ["src", "stories"],
12+
"baseUrl": "src",
13+
"forceConsistentCasingInFileNames": true,
14+
"noImplicitReturns": true,
15+
"noImplicitThis": true,
16+
"noImplicitAny": true,
17+
"strictNullChecks": true,
18+
"suppressImplicitAnyIndexErrors": true,
19+
"noUnusedLocals": true,
20+
"declaration": true,
21+
"allowSyntheticDefaultImports": true,
22+
"experimentalDecorators": true,
23+
"emitDecoratorMetadata": true
24+
},
25+
"include": ["src/**/*"],
26+
"exclude": ["node_modules", "build", "scripts"]
27+
}

webpack.common.js

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
var path = require("path");
2+
var webpack = require("webpack");
3+
var node_modules = path.resolve(__dirname, "node_modules");
4+
5+
var globule = require("globule");
6+
const CopyPlugin = require("copy-webpack-plugin");
7+
var outputDir = "dist";
8+
9+
// From Bloom's webpack, it seems this is needed
10+
// if ever our output directory does not have the same parent as our node_modules. We then
11+
// need to resolve the babel related presets (and plugins). This mapping function was
12+
// suggested at https://github.com/babel/babel-loader/issues/166.
13+
// Since our node_modules DOES have the same parent, maybe we could do without it?
14+
function localResolve(preset) {
15+
return Array.isArray(preset)
16+
? [require.resolve(preset[0]), preset[1]]
17+
: require.resolve(preset);
18+
}
19+
20+
module.exports = {
21+
// mode must be set to either "production" or "development" in webpack 4.
22+
// Webpack-common is intended to be 'required' by something that provides that.
23+
context: __dirname,
24+
entry: {
25+
index: "./src/index.ts"
26+
},
27+
28+
output: {
29+
path: path.join(__dirname, outputDir),
30+
filename: "[name].js",
31+
library: "Comical"
32+
},
33+
34+
resolve: {
35+
modules: [".", node_modules],
36+
extensions: [".js", ".jsx", ".ts", ".tsx"]
37+
},
38+
39+
optimization: {
40+
minimize: false,
41+
namedModules: true,
42+
splitChunks: {
43+
cacheGroups: {
44+
default: false
45+
}
46+
}
47+
},
48+
module: {
49+
rules: [
50+
{
51+
test: /\.ts(x?)$/,
52+
use: [{ loader: "ts-loader" }]
53+
},
54+
{
55+
test: /\.less$/i,
56+
use: [
57+
{
58+
loader: "style-loader" // creates style nodes from JS strings
59+
},
60+
{
61+
loader: "css-loader" // translates CSS into CommonJS
62+
},
63+
{
64+
loader: "less-loader" // compiles Less to CSS
65+
}
66+
]
67+
},
68+
{
69+
test: /\.css$/,
70+
loader: "style-loader!css-loader"
71+
},
72+
// WOFF Font--needed?
73+
{
74+
test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,
75+
use: {
76+
loader: "url-loader",
77+
options: {
78+
limit: 10000,
79+
mimetype: "application/font-woff"
80+
}
81+
}
82+
},
83+
{
84+
// this allows things like background-image: url("myComponentsButton.svg") and have the resulting path look for the svg in the stylesheet's folder
85+
// the last few seem to be needed for (at least) slick-carousel to build.
86+
test: /\.(svg|jpg|png|ttf|eot|gif)$/,
87+
use: {
88+
loader: "file-loader"
89+
}
90+
}
91+
]
92+
}
93+
};

webpack.config-prod.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const merge = require("webpack-merge");
2+
const common = require("./webpack.common.js");
3+
const TerserPlugin = require("terser-webpack-plugin");
4+
5+
module.exports = merge(common, {
6+
mode: "production",
7+
devtool: "source-map",
8+
output: {filename: "[name].min.js", sourceMapFilename: "[file].map" },
9+
10+
optimization: {
11+
minimize: true,
12+
minimizer: [new TerserPlugin({
13+
sourceMap: true
14+
})]
15+
}
16+
});

webpack.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const merge = require("webpack-merge");
2+
const common = require("./webpack.common.js");
3+
4+
module.exports = merge(common, {
5+
mode: "development",
6+
devtool: "source-map",
7+
devServer: {
8+
contentBase: "./dist"
9+
}
10+
});

0 commit comments

Comments
 (0)