-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
executable file
·132 lines (115 loc) · 4.58 KB
/
webpack.config.js
File metadata and controls
executable file
·132 lines (115 loc) · 4.58 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
const path = require('path');
const webpack = require('webpack');
// load the web server settings from package.json
const { devServer } = require('./package.json');
// used to copy content from the src folder to the dist folder
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
// configure the environment object for development mode
const ENV = process.env.ENV = process.env.NODE_ENV = 'development';
// const ENV = process.env.ENV = process.env.NODE_ENV = 'production';
// configure source and distribution folder paths
const srcFolder = 'src';
const destFolder = 'dist';
const srcFolderPath = path.join(__dirname, srcFolder);
const jsFolderPath = path.join(srcFolderPath, 'js');
// export webpack configuration
const webpackConfig = {
// root folder for entry point files
context: jsFolderPath,
// entry points for the three bundles, order does not matter
entry: {
'app': ['whatwg-fetch', './app.js'],
},
// allows us to require modules using
// import { someExport } from './my-module';
// instead of
// import { someExport } from './my-module.ts';
// with the extensions in the list, it can be omitted from the import
// root is an absolute path to the folder containing our application modules
resolve: {
extensions: ['.js', '.jsx', '.json'], // order matters, resolves left to right
modules: [ jsFolderPath, path.join(__dirname, 'node_modules') ]
},
module: {
rules: [
// process all JavaScript files through the Babel preprocessor
// this enables support for ES2017 and earlier including modules
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: [{
loader: 'babel-loader',
options: {
presets: [ 'react' ],
plugins: [ 'transform-class-properties' ],
},
}],
},
// transpiles global SASS stylesheets
// loader order is executed right to left
{
test: /\.scss$/,
use: [
'style-loader',
'css-loader',
{
loader: 'postcss-loader',
// configuration for the postcss loader which modifies CSS after
// processing
options: {
// autoprefixer plugin for postcss adds vendor specific prefixing for
// non-standard or experimental css properties
plugins: [ require('autoprefixer') ]
}
},
'sass-loader',
],
},
],
},
plugins: [
// copy image files, and the index.html file directly when they are changed
new CopyWebpackPlugin([
{
from: path.join(srcFolderPath, 'images'),
to: 'images',
},
]),
// configure the file to have the bundle script elements injected
// this is almost always the main html for the initial loading of
// the site
new HtmlWebpackPlugin({
template: path.join(srcFolderPath, 'index.html')
}),
// setup environment variables
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify(ENV),
},
}),
],
// out file settings
// path points to web server content folder where the web server will serve the files from
// publicPath is the path to the files from the perspective of the web browser requesting
// the files from the web server, this is used to insert the script elements into the index.html
// file
// file name is the name of the files, where [name] is the name of each entry point
output: {
path: path.join(__dirname, destFolder),
publicPath: '/',
filename: '[name].js'
},
// use the webpack dev server to serve up the web application
devServer,
// use full source maps
// this specific setting value is required to set breakpoints in the TypeScript
// in the web browser for development
// other source map settings do not allow debugging in browser and vscode
devtool: 'source-map',
};
// only minify code when in production
if (ENV === 'production') {
webpackConfig.plugins.push(new webpack.optimize.UglifyJsPlugin());
}
module.exports = webpackConfig;