-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
115 lines (111 loc) · 3.48 KB
/
webpack.config.js
File metadata and controls
115 lines (111 loc) · 3.48 KB
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
/* eslint-disable import/no-extraneous-dependencies */
const HtmlWebpackPlugin = require('html-webpack-plugin');
const autoprefixer = require('autoprefixer');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const cssnano = require('cssnano');
const browsers = [
'last 2 chrome versions',
'last 2 firefox versions',
'last 2 safari versions',
'last 2 edge versions',
'last 2 ios versions',
'last 2 chromeandroid versions',
];
const isDevelopment = process.env.NODE_ENV === 'development';
const plugins = [];
let additionalOptions = {};
if (isDevelopment) {
plugins.push(
new HtmlWebpackPlugin({
inject: 'head',
template: 'index.html',
}),
new BundleAnalyzerPlugin({
analyzerMode: 'static',
openAnalyzer: false,
}),
);
additionalOptions = {
serve: {
port: 3000,
hot: {
port: 3001,
},
},
};
}
module.exports = {
mode: process.env.NODE_ENV,
entry: './src/index.js',
output: {
path: `${__dirname}/dist`,
filename: isDevelopment ? 'post-editor.js' : 'post-editor.min.js',
library: 'postEditor',
libraryTarget: 'umd',
},
module: {
rules: [
{
test: /\.js$/,
include: `${__dirname}/src`,
use: 'babel-loader',
},
{
test: /\.s?css$/,
use: [
{
loader: 'style-loader',
options: {
sourceMap: isDevelopment,
hmr: isDevelopment,
},
},
{
loader: 'css-loader',
options: {
sourceMap: isDevelopment,
},
},
{
loader: 'postcss-loader',
options: {
sourceMap: isDevelopment,
plugins: () => [
autoprefixer({
cascade: false,
browsers: browsers.join(', '),
}),
cssnano({
preset: 'default',
}),
],
},
},
{
loader: 'sass-loader',
options: {
sourceMap: isDevelopment,
},
},
{
loader: 'sass-resources-loader',
options: {
resources: [
'./node_modules/design-system/dist/scss/wds-variables/index.scss',
'./node_modules/design-system/dist/scss/wds-mixins/index.scss',
'./src/styles/variables.scss',
],
},
},
],
},
{
test: /\.svg$/,
use: 'preact-svg-loader',
},
],
},
plugins,
devtool: isDevelopment ? 'inline-source-map' : 'source-map',
...additionalOptions,
};