4

Snowpack dev is very cool - but for my needs I will need all js/css/images packed into exactly one bundle.js file. No chunks or anything else.

I have tried using the following webpack plugin config in snowpack.config.js's plugins:

    [
      "@snowpack/plugin-webpack",
      {
        outputPattern: {
          js: "bundle.js",
          css: "bundle.css",
        },
        extendConfig: (config) => {
          delete config.optimization.splitChunks;
          delete config.optimization.runtimeChunk;
          return config;
        },
      },
    ],

Which results in creating these two files: bundle.js and bundle.css

Is there a simple way to:

  1. Pack everything only into build.jswithout the css file?
  2. Automatically get rid of all the other files still left in the build folder (__snowpack__, web_modules, source files)?
Esteban Borai
  • 2,311
  • 1
  • 21
  • 27
Udi
  • 29,222
  • 9
  • 96
  • 129

1 Answers1

1

Modify snowpack.config.js as follows:

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;
        }
      }
    ],
...

Output of 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!
phaleth
  • 569
  • 5
  • 7