-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.cfg
88 lines (85 loc) · 2.91 KB
/
webpack.cfg
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
///////////////////////////
// webpack config file //
///////////////////////////
//NOTE: this is a Javascript file, named as config to reflect purpose
//helpful info:
//https://webpack.js.org/guides/getting-started/
//https://webpack.js.org/loaders/
const Path = require('path');
//TODO? const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
//TODO? const TerserJSPlugin = require('terser-webpack-plugin');
//TODO? const MiniCssExtractPlugin = require('mini-css-extract-plugin');
//TODO? const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
//TODO? media-query-plugin
const isProd = true? ".[hash]": ""; //more efficient cache busting for prod
console.log(`webpack cfg: ${isProd? "PROD": "DEV"}`);
module.exports =
{
mode: "none", //isProd? "production": "development", //avoid warning message
entry: './js/jsNotebook.js',
output:
{
filename: 'jsNotebook.js', //"bundle.js", "[name].js",
path: Path.resolve(__dirname, 'dist'),
},
plugins:
[
new CleanWebpackPlugin(),
//TODO? new HtmlWebpackPlugin({ title: 'Output Management', }),
//TODO? new MiniCssExtractPlugin(
// {
// filename: `[name]${isProd}.css`,
// chunkFilename: `[id]${isProd}.css`,
// }),
],
module:
{
rules:
[
//?? { test: /\.css$/i, use: [ 'style-loader', 'css-loader', ], },
{ test: /\.css$/i, use: [/*isProd? MiniCssExtractPlugin.loader:*/ 'style-loader', 'css-loader'], },
// { test: /\.(png|svg|jpe?g|gif)$/i, use: [ 'file-loader', ], },
{ test: /\.(png|svg|jpe?g|gif)$/i, loader: 'url-loader', options: {limit: 10e3, }, }, //embed images < 10K using base64
//??loaders: [
// { test: /\.(html)$/i, loader: "file?name=[path][name].[ext]&context=./app/static", },
//!needed { test: /\.(html)$/i, loader: "file-loader?name=[name].[ext]", }, //[path][name].[ext]", }, //kludge: copy parent HTML file to output as-is
{
test: /\.s(a|c)ss$/i,
// exclude: /\.module\.s(a|c)ss$/i,
loader:
[
/*isProd? MiniCssExtractPlugin.loader:*/ 'style-loader',
{
loader: 'css-loader',
options: { /*modules: true,*/ sourceMap: !isProd, },
},
{
loader: 'sass-loader',
options: { sourceMap: !isProd, },
},
],
},
/*
//not using modules
{
test: /\.module\.s(a|c)ss$/i,
loader:
[
isProd? MiniCssExtractPlugin.loader: 'style-loader',
{
loader: 'css-loader',
options: { modules: true, sourceMap: !isProd, },
},
{
loader: 'sass-loader',
options: { sourceMap: !isProd, },
},
],
},
*/
],
},
resolve: { extensions: ['.js', '.jsx', '.scss'], },
//TODO? optimization: { minimizer: [new TerserJSPlugin({}), new OptimizeCSSAssetsPlugin({})], },
};