1 | const path = require('path');
|
2 | const {ProvidePlugin} = require('webpack');
|
3 | const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
|
4 |
|
5 | const base = {
|
6 | mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
|
7 | devtool: 'cheap-module-source-map',
|
8 | module: {
|
9 | rules: [
|
10 | {
|
11 | include: [
|
12 | path.resolve('src')
|
13 | ],
|
14 | test: /\.js$/,
|
15 | loader: 'babel-loader',
|
16 | options: {
|
17 | presets: [
|
18 | ['@babel/preset-env', {targets: {browsers: ['last 3 versions', 'Safari >= 8', 'iOS >= 8']}}]
|
19 | ]
|
20 | }
|
21 | }
|
22 | ]
|
23 | },
|
24 | optimization: {
|
25 | minimizer: [
|
26 | new UglifyJsPlugin({
|
27 | include: /\.min\.js$/,
|
28 | sourceMap: true
|
29 | })
|
30 | ]
|
31 | },
|
32 | plugins: []
|
33 | };
|
34 |
|
35 | module.exports = [
|
36 |
|
37 | Object.assign({}, base, {
|
38 | target: 'web',
|
39 | entry: {
|
40 | 'scratch-storage': './src/index.js',
|
41 | 'scratch-storage.min': './src/index.js'
|
42 | },
|
43 | output: {
|
44 | library: 'ScratchStorage',
|
45 | libraryTarget: 'umd',
|
46 | path: path.resolve('dist', 'web'),
|
47 | filename: '[name].js'
|
48 | }
|
49 | }),
|
50 |
|
51 |
|
52 | Object.assign({}, base, {
|
53 | target: 'node',
|
54 | entry: {
|
55 | 'scratch-storage': './src/index.js'
|
56 | },
|
57 | output: {
|
58 | library: 'ScratchStorage',
|
59 | libraryTarget: 'commonjs2',
|
60 | path: path.resolve('dist', 'node'),
|
61 | filename: '[name].js'
|
62 | },
|
63 | externals: {
|
64 | 'base64-js': true,
|
65 | 'js-md5': true,
|
66 | 'localforage': true,
|
67 | 'text-encoding': true
|
68 | },
|
69 | plugins: [
|
70 | new ProvidePlugin({
|
71 | fetch: ['node-fetch', 'default']
|
72 | })
|
73 | ]
|
74 | })
|
75 | ];
|