123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- const path = require('path');
- const MiniCssExtractPlugin = require('mini-css-extract-plugin');
- const HtmlWebpackPlugin = require('html-webpack-plugin');
- const {
- CleanWebpackPlugin
- } = require('clean-webpack-plugin');
- const CopyWebpackPlugin = require('copy-webpack-plugin');
- let entry = { index: './src/index.ts' },
- plugins = [
- new CleanWebpackPlugin(),
- new CopyWebpackPlugin([{
- from: path.join(__dirname, './src/assets'),
- to: path.join(__dirname, './dist/assets')
- }]),
- new MiniCssExtractPlugin({
- filename: './assets/styles/index.[hash:8].css'
- }),
- new HtmlWebpackPlugin({
-
- title: '磁铁布局',
- template: './src/index.html',
- filename: 'index.html',
- minify: {
-
- removeComments: true,
- collapseWhitespace: true,
- removeAttributeQuotes: true
- },
- chunks: ['index']
- })
- ];
- if (process.env.NODE_ENV !== 'production') {
- entry.login = './src/login.ts';
- plugins.push(
- new HtmlWebpackPlugin({
- title: '登陆',
- template: './src/login.html',
- filename: 'login.html',
- minify: {
- removeComments: true,
- collapseWhitespace: true,
- removeAttributeQuotes: true
- },
- chunks: ['login']
- })
- );
- }
- module.exports = {
- mode: process.env.NODE_ENV,
- entry,
- devtool: process.env.NODE_ENV === 'production' ? 'cheap-module-source-map' : 'cheap-module-eval-source-map',
- output: {
- publicPath: '',
- path: path.resolve(__dirname, 'dist'),
- filename: './assets/js/[name].[hash:8].js'
- },
- resolve: {
- extensions: ['.js', '.ts', '.scss'],
- alias: {
-
- imgs: path.resolve(__dirname, './src/assets/imgs')
- }
- },
- module: {
- rules: [{
- test: /\.ts$/,
- exclude: path.resolve(__dirname, 'node_modules'),
- include: path.resolve(__dirname, 'src'),
- loader: ['babel-loader', 'ts-loader']
- },
- {
- test: /\.scss$/,
- use: [
-
- {
- loader: MiniCssExtractPlugin.loader
- },
- {
- loader: 'css-loader',
- options: {
- url: false
-
- }
- },
- {
-
- loader: 'postcss-loader',
- options: {
- plugins: [require('autoprefixer')]
- }
- },
- {
- loader: 'sass-loader'
- }
- ]
- },
- {
- test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
- loader: 'url-loader',
- options: {
- limit: 100,
- name: './imgs/[name].[hash:7].[ext]'
- }
- }
- ]
- },
- plugins,
- devServer: {
- host: '0.0.0.0',
- port: 8083,
- open: true,
- proxy: {
- '/api': {
- target: 'http://192.168.100.254:10000/',
- pathRewrite: {
- '^/api': ''
- },
- changeOrigin: true
- }
- }
- }
- };
|