-
Notifications
You must be signed in to change notification settings - Fork 10
/
webpack.lib-production.js
124 lines (121 loc) · 3.57 KB
/
webpack.lib-production.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
120
121
122
123
124
//@ts-ignore
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const HtmlWebPackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const path = require('path');
const webpack = require('webpack');
const PACKAGE = require('./package.json');
const Dotenv = require('dotenv-webpack');
module.exports = (env) => {
//Generate a public path that is pointing at WRI server appropriate folder corresponding to the folder name that reflects the version, this is done so various esri files
//like font files and others are loaded correctly due to dynamic pathing issues
const base = 'https://wri-sites.s3.amazonaws.com/gfw-mapbuilder.org/library.gfw-mapbuilder.org/';
const publicPathURL = `${base}${PACKAGE.version}/`;
return {
mode: 'production',
devtool: 'source-map',
entry: {
'library-bundle': ['./src/js/lib.tsx'],
[`loader/${PACKAGE.version}`]: [`./src/lib/libLoader.js`],
},
output: {
filename: '[name].js',
publicPath: publicPathURL,
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
options: {},
},
{
test: /\.s[ac]ss$/i,
use: [
// Creates `style` nodes from JS strings
'style-loader',
// Translates CSS into CommonJS
'css-loader',
// Compiles Sass to CSS
'sass-loader',
],
},
{
test: /\.css$/i,
use: [
// Creates `style` nodes from JS strings
'style-loader',
// Translates CSS into CommonJS
'css-loader',
],
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: ['file-loader'],
},
{
test: /\.(png|jpg|gif)$/,
use: ['url-loader'],
},
{
test: /\.svg$/,
loader: 'file-loader',
},
{
test: /\.js$/,
include: /node_modules\/(@arcgis|@esri\/calcite-components|@zip.js)/,
use: [
{
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
plugins: [['@babel/plugin-proposal-decorators', { legacy: true }]],
compact: true,
sourceType: 'unambiguous',
},
},
],
},
],
},
plugins: [
new CleanWebpackPlugin(),
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 100,
}),
new Dotenv({
path: path.resolve(__dirname, './.env'),
systemvars: true,
}),
new HtmlWebPackPlugin({
title: 'ArcGIS Template Application',
template: './src/library.html',
filename: './index.html',
favicon: './src/assets/favicon.ico',
chunksSortMode: 'none',
inlineSource: '.(css)$',
}),
new MiniCssExtractPlugin({
filename: '[name].[chunkhash].css',
chunkFilename: '[id].css',
}),
],
resolve: {
alias: {
js: path.join(__dirname, 'src/js'),
css: path.join(__dirname, 'src/css'),
images: path.join(__dirname, 'src/images'),
},
modules: [
path.resolve(__dirname, '/src'),
path.resolve(__dirname, '/configs'),
path.resolve(__dirname, 'node_modules/'),
],
extensions: ['.ts', '.tsx', '.js', '.scss', '.css'],
fallback: {
stream: require.resolve('stream-browserify'),
buffer: require.resolve('buffer'),
},
},
};
};