2021-03-05 19:29:28 -05:00
|
|
|
const { merge } = require('webpack-merge')
|
|
|
|
const common = require('./webpack.common.js')
|
2021-10-26 04:21:28 -04:00
|
|
|
const CopyPlugin = require('copy-webpack-plugin')
|
|
|
|
const fs = require('fs')
|
2021-03-05 19:29:28 -05:00
|
|
|
const path = require('path')
|
|
|
|
|
2021-10-26 04:21:28 -04:00
|
|
|
class SymlinkPlugin {
|
|
|
|
constructor (options) {
|
|
|
|
this.directories = options.directories ?? []
|
|
|
|
}
|
|
|
|
|
|
|
|
apply (compiler) {
|
|
|
|
compiler.hooks.afterEmit.tap(SymlinkPlugin.name, this.afterEmitHook.bind(this))
|
|
|
|
}
|
|
|
|
|
|
|
|
afterEmitHook (compilation) {
|
|
|
|
const dir = compilation.options.context
|
|
|
|
const output = compilation.outputOptions.path
|
|
|
|
for (const { from: _from, to: _to } of this.directories) {
|
|
|
|
const to = path.resolve(output, _to)
|
|
|
|
if (fs.existsSync(to)) {
|
|
|
|
try {
|
|
|
|
fs.unlinkSync(to)
|
|
|
|
} catch (e) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const from = path.resolve(dir, _from)
|
|
|
|
fs.symlinkSync(from, to, 'junction')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-05 19:29:28 -05:00
|
|
|
module.exports = merge(common, {
|
|
|
|
mode: 'development',
|
|
|
|
devtool: 'inline-source-map',
|
|
|
|
cache: true,
|
|
|
|
devServer: {
|
|
|
|
contentBase: path.resolve(__dirname, './public'),
|
|
|
|
compress: true,
|
|
|
|
inline: true,
|
|
|
|
// open: true,
|
2021-03-13 15:44:00 -05:00
|
|
|
hot: true
|
2021-10-26 04:21:28 -04:00
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new CopyPlugin({ patterns: common[Symbol.for('webpack_files')] }),
|
|
|
|
new SymlinkPlugin({ directories: common[Symbol.for('webpack_directories')] })
|
|
|
|
]
|
2021-03-05 19:29:28 -05:00
|
|
|
})
|