0

У меня есть web pack конфиг такого типа:

module.exports = {
  mode: 'production',
  // mode: 'development',
  cache: true,
  entry: './src/main.js',
  resolve: {
    extensions: ['.js', '.json', '.vue']
  },
  output: {
    filename: '[name].bundle.js',
    chunkFilename: '[name].bundle.js',
    library: 'asset',
    path: path.resolve(__dirname, 'dist')
  },

...

new HtmlWebpackPlugin({
  // filename: config.build.index,
  title: process.env.npm_package_description,
  template: 'index.html',
  inject: true,
  minify: {
    removeComments: true,
    collapseWhitespace: true,
    removeAttributeQuotes: true
  },
  chunksSortMode: 'dependency',
  serviceWorkerLoader: ''
})
 new CopyWebpackPlugin([
  {
    from: path.resolve(__dirname, './static'),
    to: 'static',
    ignore: ['.*']
  }
]),
....

При формировании файлов получается следующий вид проекта.

/static (статические файлы)
index.html (подключает <script src ='main.bundle.js'>...)
main.bundle.js
vendors.bundle.js
sw.js

Подскажите пожалуйста, как мне изменить конфиг WebPack что бы файлы сборки изменились на такую структуру ?

/static (статические файлы)
/static/main.bundle.js
/static/vendors.bundle.js
/static/sw.js 
index.html (подключает <script src ='/static/main.bundle.js'>...)

Заранее спасибо.

1 ответ 1

0
      entry: './src/main.js',
      resolve: {
        extensions: ['.js', '.json', '.vue']
      },
      output: {
        filename: '[name].bundle.js',
        chunkFilename: '[name].bundle.js',
        library: 'Vue',
        path: path.resolve(__dirname, 'dist/static/')
      },

    new HtmlWebpackPlugin({
      // filename: config.build.index,
      title: process.env.npm_package_description,
      template: 'index.html',
      filename: '../index.html',
      inject: true,
      minify: {
        removeComments: true,
        collapseWhitespace: true,
        removeAttributeQuotes: true
      },
      chunksSortMode: 'dependency',
      serviceWorkerLoader: ''
    })

   new CopyWebpackPlugin([
      {
        from: path.resolve(__dirname, './static'),
        to: '',
        ignore: ['.*']
      }
    ]),

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.