forked from scratchfoundation/scratch-paint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
119 lines (115 loc) · 3.47 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
const defaultsDeep = require('lodash.defaultsdeep');
const path = require('path');
// Plugins
const HtmlWebpackPlugin = require('html-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
// PostCss
const autoprefixer = require('autoprefixer');
const postcssVars = require('postcss-simple-vars');
const postcssImport = require('postcss-import');
const base = {
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
devtool: 'cheap-module-source-map',
module: {
rules: [{
test: /\.jsx?$/,
loader: 'babel-loader',
include: path.resolve(__dirname, 'src'),
options: {
plugins: ['transform-object-rest-spread'],
presets: [['env', {browsers: ['last 3 versions', 'Safari >= 8', 'iOS >= 8']}], 'react']
}
},
{
test: /\.css$/,
use: [{
loader: 'style-loader'
}, {
loader: 'css-loader',
options: {
modules: {
localIdentName: '[name]_[local]_[hash:base64:5]'
},
importLoaders: 1,
localsConvention: 'camelCase'
}
}, {
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: function () {
return [
postcssImport,
postcssVars,
autoprefixer()
];
}
}
}]
},
{
test: /\.png$/i,
loader: 'url-loader'
},
{
test: /\.svg$/,
loader: 'svg-url-loader?noquotes'
}]
},
optimization: {
minimizer: [
new UglifyJsPlugin({
include: /\.min\.js$/
})
]
},
plugins: []
};
module.exports = [
// For the playground
defaultsDeep({}, base, {
devServer: {
contentBase: path.resolve(__dirname, 'playground'),
host: '0.0.0.0',
port: process.env.PORT || 8078
},
entry: {
playground: './src/playground/playground.jsx'
},
output: {
path: path.resolve(__dirname, 'playground'),
filename: '[name].js'
},
plugins: base.plugins.concat([
new HtmlWebpackPlugin({
template: 'src/playground/index.ejs',
title: 'Scratch 3.0 Paint Editor Playground'
})
])
}),
// For use as a library
defaultsDeep({}, base, {
externals: {
'minilog': 'minilog',
'prop-types': 'prop-types',
'react': 'react',
'react-dom': 'react-dom',
'react-intl': 'react-intl',
'react-intl-redux': 'react-intl-redux',
'react-popover': 'react-popover',
'react-redux': 'react-redux',
'react-responsive': 'react-responsive',
'react-style-proptype': 'react-style-proptype',
'react-tooltip': 'react-tooltip',
'redux': 'redux'
},
entry: {
'scratch-paint': './src/index.js'
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
libraryTarget: 'commonjs2'
}
})
];