-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
86 lines (82 loc) · 2.08 KB
/
webpack.config.js
File metadata and controls
86 lines (82 loc) · 2.08 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
const path = require('path')
const os = require('os')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const CopyPlugin = require('copy-webpack-plugin')
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
const { ESBuildMinifyPlugin } = require('esbuild-loader')
const buildStart = new Date().toLocaleString()
console.log(`run on ${os.cpus().length} CPUs`)
const webpackConfig = {
entry: {
app: './src/scripts/index.ts',
normalize: 'normalize.css',
style: './src/styles/style.scss',
},
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist'),
libraryTarget: 'umd',
},
devtool: 'source-map',
devServer: {
static: path.resolve(__dirname, 'src/assets'),
hot: true,
},
mode: 'development',
cache: {
type: 'filesystem',
},
plugins: [
new HtmlWebpackPlugin({
template: 'src/assets/template.ejs',
buildTime: buildStart,
env: process.env.NODE_ENV,
}),
],
resolve: {
alias: {
vue: 'vue/dist/vue.esm.js',
},
extensions: ['.tsx', '.ts', '.js'],
},
module: {
rules: [
{
test: /\.ts$/,
loader: 'esbuild-loader',
options: {
loader: 'ts',
target: 'es6',
},
},
{
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'postcss-loader', 'sass-loader'],
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
],
},
}
if (process.env.NODE_ENV === 'demo') {
webpackConfig.optimization = {
minimize: true,
minimizer: [
new ESBuildMinifyPlugin({
target: 'es6',
}),
],
}
webpackConfig.mode = 'production'
webpackConfig.cache = false
delete webpackConfig.devtool
webpackConfig.plugins.unshift(
new CopyPlugin({ patterns: [{ from: 'src/assets/sample_docs', to: '../dist/sample_docs' }] }),
)
webpackConfig.plugins.unshift(new CleanWebpackPlugin())
// webpackConfig.plugins.unshift(new BundleAnalyzerPlugin())
}
module.exports = webpackConfig