Skip to content

Instantly share code, notes, and snippets.

@ushironoko
Created May 1, 2020 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ushironoko/b6991b5427f4dba5860969ba3e67b614 to your computer and use it in GitHub Desktop.
Save ushironoko/b6991b5427f4dba5860969ba3e67b614 to your computer and use it in GitHub Desktop.
vue3 webpack conf
/* eslint-disable @typescript-eslint/no-var-requires */
const { resolve } = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const { VueLoaderPlugin } = require('vue-loader')
const webpack = require('webpack')
const outputPath = resolve(__dirname, 'dist')
/** @type {import('webpack').ConfigurationFactory} */
const config = (env = {}) => ({
mode: env.prod ? 'production' : 'development',
devtool: env.prod ? 'source-map' : 'inline-source-map',
devServer: {
contentBase: outputPath,
historyApiFallback: true,
hot: true,
stats: 'minimal',
},
output: {
path: outputPath,
publicPath: '/',
filename: 'bundle.js',
},
entry: [resolve(__dirname, 'src/main.ts')],
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules|vue\/src/,
use: [
{
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.vue$/],
transpileOnly: true,
},
},
],
},
{
test: /\.vue$/,
use: 'vue-loader',
},
],
},
resolve: {
alias: {
vue: '@vue/runtime-dom',
'~': resolve('src'),
},
extensions: ['.ts', 'd.ts', '.tsx', '.js', '.vue'],
},
plugins: [
new VueLoaderPlugin(),
new HtmlWebpackPlugin({
template: resolve(__dirname, 'src/index.html'),
}),
new CleanWebpackPlugin(),
],
})
module.exports = config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment