|
1 | 1 | const CopyWebpackPlugin = require('copy-webpack-plugin'); |
2 | | -const defaultsDeep = require('lodash.defaultsdeep'); |
3 | 2 | const path = require('path'); |
| 3 | +const ScratchWebpackConfigBuilder = require('scratch-webpack-configuration'); |
4 | 4 |
|
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) |
30 | 8 | }; |
31 | 9 |
|
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 |
41 | 33 | }, |
42 | | - plugins: base.plugins.concat([ |
43 | | - new CopyWebpackPlugin([ |
44 | | - { |
45 | | - from: 'src/playground' |
46 | | - } |
47 | | - ]) |
48 | | - ]) |
49 | | - }), |
50 | | - defaultsDeep({}, base, { |
51 | 34 | 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: '/' |
66 | 37 | } |
67 | 38 | }) |
| 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 |
68 | 52 | ]; |
0 commit comments