Webpack 配置 - 如何在不同路径中编译文件

问题描述 投票:0回答:0

那里。

我正在开始学习 typescript 和 webpack 构建器,我对 webpack 有疑问。

我有

  • ./src
    - 这是我的源文件(index.html、index.ts、style.scss)
  • ./public
    - 我的网站和编译器文件(index.html、bundle.js、style.css)

我想将我的

./src
文件
index.html
构建到
./public/
中,将我的
index.ts
构建到
./public/success/script/index.js
中,将
style.scss
构建到
./public/success/style/style.css
中,例如

我该怎么做?

感谢您的回答。

我的 webpack.config.js

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
    entry: path.resolve(__dirname, './src/scripts/index.ts'),
    mode: "development",
    output: {
        path: path.resolve(__dirname, './public/'),
        filename: 'app.min.js',
    },
    devServer: {
        static:{
            directory: path.join(__dirname,  './public')
        },
        port: 3000,
        open: true,
        hot: true
    },
    module: {
        rules: [
            {
                test: /\.ts|.js$/,
                use: ["ts-loader"],
                exclude: /node_modules/,
            },
            {
                test: /\.scss$/,
                use:[
                    "sass-loader",
                    "style-loader",
                    "css-loader"
                ]
            }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: path.resolve(__dirname, './src/index.html'),
            filename: path.resolve(__dirname, "./public/index.html"),
            inject: "body"
        }),
    ],
};
webpack webpack-dev-server
© www.soinside.com 2019 - 2024. All rights reserved.