Skip to content

Commit 607d675

Browse files
committed
build!: use scratch-webpack-configuration
1 parent 5ad1d41 commit 607d675

File tree

3 files changed

+74
-66
lines changed

3 files changed

+74
-66
lines changed

package-lock.json

Lines changed: 25 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,24 @@
4646
"husky": "8.0.3",
4747
"jsdom": "13.2.0",
4848
"json": "9.0.6",
49-
"lodash.defaultsdeep": "4.6.1",
5049
"mkdirp": "2.1.6",
5150
"rimraf": "3.0.2",
5251
"scratch-render-fonts": "1.0.20",
5352
"scratch-semantic-release-config": "1.0.14",
53+
"scratch-webpack-configuration": "1.0.0",
5454
"semantic-release": "19.0.5",
5555
"tap": "11.1.5",
5656
"webpack": "5.90.3",
5757
"webpack-cli": "5.1.4",
5858
"webpack-dev-server": "3.11.3",
5959
"xmldom": "0.1.31"
6060
},
61+
"browserslist": [
62+
"Chrome >= 63",
63+
"Edge >= 15",
64+
"Firefox >= 57",
65+
"Safari >= 11"
66+
],
6167
"config": {
6268
"commitizen": {
6369
"path": "cz-conventional-changelog"

webpack.config.js

Lines changed: 42 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,52 @@
11
const CopyWebpackPlugin = require('copy-webpack-plugin');
2-
const defaultsDeep = require('lodash.defaultsdeep');
32
const path = require('path');
3+
const ScratchWebpackConfigBuilder = require('scratch-webpack-configuration');
44

5-
const base = {
6-
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
7-
devServer: {
8-
contentBase: false,
9-
host: '0.0.0.0',
10-
port: process.env.PORT || 8576
11-
},
12-
devtool: 'cheap-module-source-map',
13-
entry: {
14-
'scratch-svg-renderer': './src/index.js'
15-
},
16-
module: {
17-
rules: [{
18-
include: [
19-
path.resolve('src'),
20-
path.resolve('node_modules', 'scratch-render-fonts')
21-
],
22-
test: /\.js$/,
23-
loader: 'babel-loader',
24-
options: {
25-
presets: [['@babel/preset-env', {targets: {}}]]
26-
}
27-
}]
28-
},
29-
plugins: []
5+
const common = {
6+
libraryName: 'ScratchSVGRenderer',
7+
rootPath: path.resolve(__dirname)
308
};
319

32-
module.exports = [
33-
defaultsDeep({}, base, {
34-
target: 'web',
35-
output: {
36-
library: 'ScratchSVGRenderer',
37-
libraryTarget: 'umd',
38-
path: path.resolve('playground'),
39-
publicPath: '/',
40-
filename: '[name].js'
10+
/**
11+
* @type {import('webpack').Configuration}
12+
*/
13+
const nodeConfig = new ScratchWebpackConfigBuilder(common)
14+
.setTarget('node')
15+
.get();
16+
17+
/**
18+
* @type {import('webpack').Configuration}
19+
*/
20+
const webConfig = new ScratchWebpackConfigBuilder(common)
21+
.setTarget('browserslist')
22+
.get();
23+
24+
/**
25+
* @type {import('webpack').Configuration}
26+
*/
27+
const playgroundConfig = new ScratchWebpackConfigBuilder(common)
28+
.setTarget('browserslist')
29+
.merge({
30+
devServer: {
31+
contentBase: false,
32+
port: process.env.PORT || 8576
4133
},
42-
plugins: base.plugins.concat([
43-
new CopyWebpackPlugin([
44-
{
45-
from: 'src/playground'
46-
}
47-
])
48-
])
49-
}),
50-
defaultsDeep({}, base, {
5134
output: {
52-
library: 'ScratchSVGRenderer',
53-
libraryTarget: 'umd',
54-
path: path.resolve('dist', 'web'),
55-
filename: '[name].js'
56-
},
57-
module: {
58-
rules: [{
59-
options: {
60-
presets: [['env', {targets: {browsers: ['last 3 versions', 'Safari >= 8', 'iOS >= 8']}}]]
61-
}
62-
}]
63-
},
64-
optimization: {
65-
minimize: process.env.NODE_ENV === 'production'
35+
path: path.resolve(__dirname, 'playground'),
36+
publicPath: '/'
6637
}
6738
})
39+
.addPlugin(
40+
new CopyWebpackPlugin([
41+
{
42+
from: 'src/playground'
43+
}
44+
])
45+
)
46+
.get();
47+
48+
module.exports = [
49+
nodeConfig,
50+
webConfig,
51+
playgroundConfig
6852
];

0 commit comments

Comments
 (0)