forked from mozilla/protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.package.build.config.js
105 lines (100 loc) · 3.09 KB
/
webpack.package.build.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
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
/* eslint-env node, commonjs, es2017 */
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const RemoveEmptyScriptsPlugin = require('webpack-remove-empty-scripts');
const path = require('path');
const jsEntryPoints = require('./webpack.entrypoints.js');
// Create UMD formatted scripts from ES source modules.
const jsConfig = {
devtool: false,
entry: jsEntryPoints,
output: {
path: path.resolve(__dirname, 'package/protocol/js'),
filename: '[name].js'
},
performance: {
hints: 'warning'
},
optimization: {
minimize: false
},
module: {
rules: [
{
test: /\.js$/,
include: path.resolve(__dirname, 'assets/js/protocol'),
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env',
{
targets: {
ie: '10'
}
}
]
]
}
}
},
]
}
};
// Create both uncompressed and minified CSS assets for standard Protocol libraries.
const cssConfig = {
entry: {
'protocol': path.resolve(__dirname, 'assets/sass/protocol/protocol.scss'),
'protocol-components': path.resolve(__dirname, 'assets/sass/protocol/protocol-components.scss'),
},
output: {
filename: 'temp/[name].js',
path: path.resolve(__dirname, 'package/protocol/css'),
},
devtool: 'source-map',
optimization: {
minimizer: [
new CssMinimizerPlugin(),
],
},
module: {
rules: [
{
test: /\.scss$/,
include: path.resolve(__dirname, 'assets/sass/protocol'),
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
url: false,
sourceMap: true
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
},
},
]
}
]
},
performance: {
hints: 'warning'
},
plugins: [
// Remove empty JS files that are left over once CSS has been extracted.
new RemoveEmptyScriptsPlugin(),
new MiniCssExtractPlugin()
]
};
module.exports = [cssConfig, jsConfig];