web-backset.cn/apps/server/webpack.config.js

89 lines
2.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const { join } = require('path')
const path = require('path')
const { readdirSync, statSync } = require('fs')
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CopyPlugin = require("copy-webpack-plugin");
const isDev = process.env.RUNNING_ENV === 'dev'
const isProd = process.env.RUNNING_ENV === 'prod'
const webpack = require('webpack')
/**
* 引入 src/view/pages下的页面文件排除 _ 开头的文件夹
*/
const importEntry = () => {
const entries = {}
const rootDir = join(process.cwd(), 'src/view/page')
readdirSync(rootDir).filter(i => !i.startsWith('_')).forEach(file => {
if (statSync(join(rootDir, file)).isDirectory())
entries[file] = `./src/view/page/${file}/index.ts`
})
console.log(entries)
return entries
}
module.exports = {
entry: importEntry(),
output: {
path: path.resolve(__dirname, 'public'),
publicPath: '',
filename: '[name].js',
chunkFilename: '[id].chunk.js?[hash:8]'
},
mode: isDev ? 'development' : 'production',
module: {
rules: [
{
test: /\.ts?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
{
test: /\.less$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'less-loader',
],
},
{
test: /\.(png|jpg|gif)$/i,
use: [
{
loader: 'url-loader',
options: {
limit: 8192,
},
},
],
},
]
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css?[hash:8]',
}),
new CopyPlugin([{ from: join(process.cwd(), 'src/view/assets'), to: "assets" }]),
new webpack.ProvidePlugin({
process: 'process/browser',
Buffer: ['buffer', 'Buffer']
})].filter(Boolean),
resolve: {
extensions: ['.ts', '.js', '.ejs'],
fallback: {
"crypto": require.resolve("crypto-browserify"),
"stream": require.resolve("stream-browserify"),
"assert": require.resolve("assert"),
}
},
};