gpt4 book ai didi

webpack - 强制 Snowpack 构建到一个文件中

转载 作者:行者123 更新时间:2023-12-04 13:54:13 27 4
gpt4 key购买 nike

Snowpack dev 非常酷 - 但为了我的需要,我需要所有的 js/css/images
准确包装 bundle.js文件。没有大块或其他任何东西。
我尝试在 snowpack.config.js 中使用以下 webpack 插件配置的plugins :

    [
"@snowpack/plugin-webpack",
{
outputPattern: {
js: "bundle.js",
css: "bundle.css",
},
extendConfig: (config) => {
delete config.optimization.splitChunks;
delete config.optimization.runtimeChunk;
return config;
},
},
],
这导致创建这两个文件: bundle.jsbundle.css有没有简单的方法:
  • 只打包所有东西到 build.js没有css文件?
  • 自动删除仍留在构建中的所有其他文件
    文件夹( __snowpack__web_modules ,源文件)?
  • 最佳答案

    修改 snowpack.config.js如下:

    const path = require('path');

    module.exports = {
    ...
    [
    '@snowpack/plugin-webpack',
    {
    outputPattern: {
    js: "index.js",
    css: "index.css",
    },
    extendConfig: config => {
    delete config.optimization.splitChunks;
    delete config.optimization.runtimeChunk;
    config.module.rules[0] = {
    test: /\.js$/,
    exclude: /node_modules/,
    use: [
    {
    loader: 'babel-loader',
    options: { presets: ['@babel/preset-env'] }
    },
    {
    loader: path.resolve(__dirname, './node_modules/@snowpack/plugin-webpack/plugins/import-meta-fix.js')
    }
    ]
    }
    return config;
    }
    }
    ],
    ...
    npm run build 的输出:
    > build
    > snowpack build

    [snowpack] ! building source files...
    [snowpack] ✔ build complete [0.39s]
    [snowpack] ! building dependencies...
    [snowpack] ✔ dependencies ready! [0.27s]
    [snowpack] ! verifying build...
    [snowpack] ✔ verification complete [0.00s]
    [snowpack] ! writing build to disk...
    [snowpack] ! optimizing build...
    Asset Size Chunks Chunk Names
    index.js 9.88 KiB 0 [emitted] index
    [snowpack] ✔ optimize complete [1.47s]
    [snowpack] ▶ Build Complete!

    关于webpack - 强制 Snowpack 构建到一个文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65514771/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com