File size: 5,177 Bytes
4d70170 |
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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
const webpack = require('webpack')
const { mergeWithRules } = require('webpack-merge')
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
const { VueLoaderPlugin } = require('vue-loader')
const MonacoEditorPlugin = require('monaco-editor-webpack-plugin')
exports.createConfig = (config, target = { chrome: 52, firefox: 48 }) => {
const mode = process.env.NODE_ENV === 'production' ? 'production' : 'development'
// const workspace = path.basename(process.cwd())
const baseConfig = {
mode,
resolve: {
extensions: ['.js', '.ts', '.vue'],
alias: {
'@front': '@vue-devtools/app-frontend/src',
'@back': '@vue-devtools/app-backend-core/lib',
'vue': require.resolve('vue/dist/vue.esm-bundler.js'),
},
// symlinks: false,
fallback: {
path: require.resolve('path-browserify'),
},
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules|vue\/dist|vuex\/dist/,
loader: 'babel-loader',
},
{
test: /\.ts$/,
loader: 'esbuild-loader',
options: {
loader: 'ts',
target: 'es2015',
},
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
compilerOptions: {
preserveWhitespace: false,
},
isServerBuild: false,
transpileOptions: {
target,
objectAssign: 'Object.assign',
transforms: {
modules: false,
},
},
},
},
{
test: /\.(css|postcss|pcss)$/,
use: [
'vue-style-loader',
'css-loader',
'postcss-loader',
],
},
{
test: /\.styl(us)?$/,
use: [
'vue-style-loader',
'css-loader',
'postcss-loader',
'stylus-loader',
{
loader: 'style-resources-loader',
options: {
patterns: [
require.resolve('@vue-devtools/app-frontend/src/assets/style/imports.styl'),
],
},
},
],
},
{
test: /\.svg$/,
loader: 'svg-inline-loader',
exclude: /assets/,
},
{
test: /\.(png|woff2|ttf|svg)$/,
type: 'asset/inline',
exclude: /@akryum\/md-icons-svg\/svg/,
},
],
},
performance: {
hints: false,
},
plugins: [
new VueLoaderPlugin(),
...(process.env.VUE_DEVTOOL_TEST ? [] : [new FriendlyErrorsPlugin()]),
new webpack.DefinePlugin({
'process.env.RELEASE_CHANNEL': JSON.stringify(process.env.RELEASE_CHANNEL || 'stable'),
'__VUE_OPTIONS_API__': true,
'__VUE_PROD_DEVTOOLS__': true,
}),
new MonacoEditorPlugin({
// https://github.com/Microsoft/monaco-editor-webpack-plugin#options
languages: ['javascript'],
}),
],
devtool: 'eval-source-map',
devServer: {
port: process.env.PORT,
},
stats: {
colors: true,
},
// cache: {
// type: 'filesystem',
// cacheDirectory: path.resolve(process.cwd(), 'node_modules/.cache/webpack'),
// name: `${workspace}-${mode}`
// },
snapshot: {
managedPaths: [],
},
}
if (process.env.NODE_ENV === 'production') {
const TerserPlugin = require('terser-webpack-plugin')
baseConfig.plugins.push(
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"',
}),
)
baseConfig.optimization = {
minimizer: [
new TerserPlugin({
exclude: /backend/,
terserOptions: {
compress: {
// turn off flags with small gains to speed up minification
arrows: false,
collapse_vars: false,
comparisons: false,
computed_props: false,
hoist_funs: false,
hoist_props: false,
hoist_vars: false,
inline: false,
loops: false,
negate_iife: false,
properties: false,
reduce_funcs: false,
reduce_vars: false,
switches: false,
toplevel: false,
typeofs: false,
// a few flags with noticable gains/speed ratio
// numbers based on out of the box vendor bundle
booleans: true,
if_return: true,
sequences: true,
unused: true,
// required features to drop conditional branches
conditionals: true,
dead_code: true,
evaluate: true,
},
mangle: {
safari10: true,
},
},
parallel: false,
}),
],
}
}
return mergeWithRules({
module: {
rules: {
test: 'match',
loader: 'replace',
options: 'merge',
},
},
})(baseConfig, config)
}
|