Skip to content

Commit 2de60e7

Browse files
authored
feat: update scaffold (#4)
* chore: update prettierc * chore: add rimraf * chore: remove useless fields * chore: remove lerna clean script * feat: build umd, umd:min * feat: add sourcemap * feat: add devServer open * feat: use yarn workspaces run command * feat: omit rootPath in path.resolve * feat: update babel-loader cacheDirectory * feat: remove webpack.definePlugin * feat: remove $schema for package.json and tsconfig.json * feat: remove ENV.LIBRARY_NAME * feat: use run-p exec build:* * feat: add fork-ts-checker-plugin in dev mode * feat: remove optimize-css-assets-webpack-plugin * feat: add postcss-preset-env * feat: add typed-css-modules-webpack-plugin * feat: use @mjolnir/prettier-config
1 parent 9119268 commit 2de60e7

35 files changed

+927
-212
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
dist/
2+
**/*.less.d.ts

.lintstagedrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "http://json.schemastore.org/lintstagedrc.schema",
3-
"**/*.{js, ts, jsx, tsx}": ["prettier --write", "eslint --fix", "git add"],
3+
"**/*.{js, ts, jsx, tsx}": ["eslint --fix", "git add"],
44
"**/*.{less, css}": ["prettier --write", "git add"],
55
"**/*.{json, html, md}": ["prettier --write", "git add"]
66
}

.postcssrc.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
plugins: {
3+
'postcss-preset-env': {},
4+
},
5+
};

.prettierrc

-6
This file was deleted.

.prettierrc.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'use strict';
2+
3+
module.exports = {
4+
...require("@mjolnir/prettier-config")
5+
// override edge case
6+
}

.vscode/settings.json

+19-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11
{
22
"eslint.validate": [
3-
{ "language": "javascript", "autoFix": true },
4-
{ "language": "javascriptreact", "autoFix": true },
5-
{ "language": "typescript", "autoFix": true },
6-
{ "language": "typescriptreact", "autoFix": true }
3+
{
4+
"language": "javascript",
5+
"autoFix": true
6+
},
7+
{
8+
"language": "javascriptreact",
9+
"autoFix": true
10+
},
11+
{
12+
"language": "typescript",
13+
"autoFix": true
14+
},
15+
{
16+
"language": "typescriptreact",
17+
"autoFix": true
18+
}
719
],
820
"cSpell.words": [
9-
"repo",
1021
"mjolnir",
11-
"mjolnirjs"
22+
"mjolnirjs",
23+
"repo",
24+
"unpkg"
1225
]
1326
}

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
# yab-dev-tools
22
TBD.
3+
4+
5+
## useage
6+
- `yarn`
7+
- `yarn start` or `yarn start:ui`

config/env.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
'use strict';
2+
const path = require('path');
23

34
const rootPath = process.cwd();
5+
const pkg = require(`${rootPath}/package.json`);
46

57
module.exports = {
68
rootPath,
7-
srcPath: `${rootPath}/src`,
8-
distPath: `${rootPath}/dist`,
9-
publicPath: `${rootPath}/public`
9+
srcPath: path.resolve('src'),
10+
distPath: path.resolve('dist'),
11+
publicPath: path.resolve('public'),
12+
libraryName: pkg.name,
1013
};
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
4+
5+
const env = require('../../env');
6+
7+
module.exports = {
8+
entry: env.srcPath,
9+
resolve: {
10+
extensions: ['.ts', '.tsx', '.js', '.json'],
11+
},
12+
module: {
13+
rules: [
14+
{
15+
test: /\.tsx?$/,
16+
exclude: /node_modules/,
17+
use: [
18+
{
19+
loader: 'babel-loader',
20+
options: {
21+
cacheDirectory: true,
22+
},
23+
},
24+
],
25+
},
26+
],
27+
},
28+
plugins: [new CaseSensitivePathsPlugin()],
29+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
const path = require('path');
3+
const merge = require('webpack-merge');
4+
5+
const baseConfig = require('./webpack.config.base');
6+
const env = require('../../env');
7+
8+
const developmentConfig = merge(baseConfig, {
9+
mode: 'development',
10+
devtool: 'cheap-eval-source-map',
11+
output: {
12+
filename: `${env.libraryName}.development.js`,
13+
path: path.resolve(env.distPath, 'umd'),
14+
library: env.libraryName,
15+
libraryTarget: 'umd',
16+
},
17+
});
18+
19+
module.exports = developmentConfig;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
const path = require('path');
3+
const merge = require('webpack-merge');
4+
const TerserPlugin = require('terser-webpack-plugin');
5+
6+
const baseConfig = require('./webpack.config.base');
7+
const env = require('../../env');
8+
9+
const productionConfig = merge(baseConfig, {
10+
mode: 'production',
11+
output: {
12+
filename: `${env.libraryName}.production.js`,
13+
path: path.resolve(env.distPath, 'umd'),
14+
library: env.libraryName,
15+
libraryTarget: 'umd',
16+
},
17+
optimization: {
18+
minimizer: [new TerserPlugin()],
19+
},
20+
});
21+
22+
module.exports = productionConfig;
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
'use strict';
2+
const path = require('path');
23
const webpack = require('webpack');
34
const WebpackBar = require('webpackbar');
45
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
56
const HtmlWebpackPlugin = require('html-webpack-plugin');
67
const CopyWebpackPlugin = require('copy-webpack-plugin');
7-
const env = require('../env');
8+
const env = require('../../env');
89

910
module.exports = {
1011
context: env.rootPath,
1112
entry: {
12-
index: ['./src']
13+
index: ['./src'],
1314
},
1415
output: {
1516
path: env.distPath,
1617
filename: '[name].[hash:8].js',
1718
publicPath: '/',
18-
chunkFilename: '[name].[hash:8].chunk.js'
19+
chunkFilename: '[name].[hash:8].chunk.js',
1920
},
20-
externals: {},
2121
resolve: {
2222
extensions: ['.js', '.jsx', '.ts', '.tsx', '.less', '.json'],
2323
alias: {
24-
'@': env.srcPath
25-
}
24+
'@': env.srcPath,
25+
},
2626
},
2727
module: {
2828
rules: [
@@ -33,10 +33,11 @@ module.exports = {
3333
{
3434
loader: 'babel-loader',
3535
options: {
36-
rootMode: 'upward'
37-
}
38-
}
39-
]
36+
rootMode: 'upward',
37+
cacheDirectory: true,
38+
},
39+
},
40+
],
4041
},
4142
{
4243
test: /\.(png|jpg|gif)$/,
@@ -45,10 +46,10 @@ module.exports = {
4546
loader: 'url-loader',
4647
options: {
4748
limit: 10000,
48-
name: 'static/[name].[hash:8].[ext]'
49-
}
50-
}
51-
]
49+
name: 'static/[name].[hash:8].[ext]',
50+
},
51+
},
52+
],
5253
},
5354
{
5455
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
@@ -57,47 +58,47 @@ module.exports = {
5758
loader: 'file-loader',
5859
options: {
5960
limit: 8192,
60-
name: 'fonts/[name].[hash:8].[ext]'
61-
}
62-
}
63-
]
64-
}
65-
]
61+
name: 'fonts/[name].[hash:8].[ext]',
62+
},
63+
},
64+
],
65+
},
66+
],
6667
},
6768
optimization: {
6869
runtimeChunk: {
69-
name: (entrypoint) => `runtime.${entrypoint.name}`
70+
name: entrypoint => `runtime.${entrypoint.name}`,
7071
},
7172
splitChunks: {
7273
cacheGroups: {
7374
vendors: {
7475
name: 'vendors',
7576
chunks: 'initial',
7677
test: /[\\/]node_modules[\\/]/,
77-
priority: 30
78+
priority: 30,
7879
},
7980
asyncVendors: {
8081
name: 'async-vendors',
8182
chunks: 'async',
8283
test: /[\\/]node_modules[\\/]/,
83-
priority: 20
84+
priority: 20,
8485
},
8586
asyncCommon: {
8687
name: 'async-common',
8788
chunks: 'async',
8889
minChunks: 2,
8990
priority: 10,
90-
reuseExistingChunk: true
91+
reuseExistingChunk: true,
9192
},
9293
default: {
9394
name: 'common',
9495
chunks: 'all',
9596
minChunks: 2,
9697
priority: -20,
97-
reuseExistingChunk: true
98-
}
99-
}
100-
}
98+
reuseExistingChunk: true,
99+
},
100+
},
101+
},
101102
},
102103
plugins: [
103104
new WebpackBar(),
@@ -107,13 +108,13 @@ module.exports = {
107108
[
108109
{
109110
from: env.publicPath,
110-
to: env.distPath
111-
}
111+
to: env.distPath,
112+
},
112113
],
113-
{ ignore: ['**/.*'] }
114+
{ ignore: ['**/.*'] },
114115
),
115116
new HtmlWebpackPlugin({
116-
template: `${env.publicPath}/index.html`
117-
})
118-
]
117+
template: path.resolve(env.publicPath, 'index.html'),
118+
}),
119+
],
119120
};

0 commit comments

Comments
 (0)