This repository has been archived by the owner on Apr 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
139 lines (132 loc) · 4.27 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
* This file is the Webpack config file for your project. Webpack is a build
* tool that bundles up projects files into runnable code. We've set this
* up for you, and you usually should not need to touch it.
*/
'use strict';
const webpack = require('webpack');
const path = require('path');
const fs = require('fs');
const { CheckerPlugin } = require('awesome-typescript-loader');
const { MixerPlugin } = require('@mixer/cdk-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const CleanPlugin = require('clean-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
/**
* isProduction is from an environment variable. It's automatically set
* when you run `miix build.`
*/
//const isProduction = process.env.ENV === 'production';
const isProduction = true;
const plugins = [
// The CopyPlugin copies your static assets into the build directory.
new CopyPlugin([
{
context: 'src/static',
from: '**/*',
to: path.resolve(__dirname, 'build/static'),
},
]),
// TypeScript checking, needed for `miix serve`.
new CheckerPlugin(),
// Mixer dev server, handles standard library injection and locale building.
new MixerPlugin({
homepage: 'src/index.html',
locales: 'locales/*.json',
}),
];
if (isProduction) {
plugins.push(
// CleanPlugin wipes the "build" directory before bundling to make sure
// there aren't unnecessary files lying around and using up your quota.
new CleanPlugin('build'),
// Uglify compresses JavaScript code to make download sizes smaller.
new UglifyJsPlugin({
warningsFilter: () => false,
sourceMap: false,
uglifyOptions: {
comments: false,
mangle: {
keep_fnames: true,
},
},
}),
);
}
module.exports = {
// When you run your controls your browser provides debugging tools. Source
// maps let it map from the ugly bundle code back into your 'real' code,
// which makes debugging a whole lot easier. These are enabled in development
// but turned off in production: they're large and also contain your raw
// source which you may want to keep private.
devtool: isProduction ? false : 'source-map',
// Entry file that webpack will start looking at:
entry: ['./src/index'],
// Tell webpack that we want to output our bundle to the `build` directory.
output: {
path: path.resolve(__dirname, 'build'),
publicPath: '',
filename: `index.js`,
},
// Tell webpack that these file extensions are source code that we can load:
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
// The build mode so that Webpack knows whether to compress
// our assets for faster loading.
mode: isProduction ? 'production' : 'development',
module: {
rules: [
// Load TypeScript files using the awesome-typescript-loader, to
// transform them into plain JavaScript.
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: ['awesome-typescript-loader'],
},
// Compile `scss` files using the sass loader, then pipe it through the
// css-loader and style-loader to have it injected automatically into the
// page when you `require('some-style-sheet.scss');`
{
test: /\.scss$/,
use: [
'style-loader',
{
loader: 'css-loader',
query: { minimize: isProduction, url: false },
},
'sass-loader',
],
},
{
test: /\.css$/,
use: [
'style-loader',
{
loader: 'css-loader',
query: { minimize: isProduction, url: false },
},
],
},
// Allow importing html and svg files directly, for the HtmlControl.
// See the docs and examples in the HtmlControl for more info!
{
test: /\.(html|svg)$/,
use: ['file-loader'],
},
],
},
externals: {
// Indicate to webpack that the Mixer standard library is "external" and
// will be injected later, so Webpack shouldn't try to throw it into the
// bundle with everything else.
'@mixer/cdk-std': 'mixer',
},
// Plugins we defined above.
plugins,
// Dev server settings, needed for `miix serve` to work properly.
devServer: {
historyApiFallback: true,
disableHostCheck: true,
},
};