laravel mix 6-npm脚本发布

ru9i0ody  于 2021-09-23  发布在  Java
关注(0)|答案(0)|浏览(157)

我已经从laravel mix 5升级到了6,但现在仅此而已 production 脚本正在运行。 developmentwatch 脚本工作不正常,后两个脚本在“public/build/dist/js”而不是“public/dist/js”中生成javascript输出,这与 production .
有人能检查我的webpack.mix.js并告诉我是否有任何问题或建议吗?
我代码中的一些注解是因为laravel混合了
谢谢你的帮助

const path = require('path')
const fs = require('fs-extra')
const mix = require('laravel-mix')
require('laravel-mix-versionhash')

mix
  .js('resources/js/app.js', 'public/dist/js').vue({ version: 2 })
  .sass('resources/sass/app.scss', 'public/dist/css')
  .disableNotifications()

if (mix.inProduction()) {
  mix
    .versionHash()
} else {
  mix.sourceMaps()
}

mix.webpackConfig({
  resolve: {
    extensions: ['.js', '.json', '.vue'],
    alias: {
      '~': path.join(__dirname, './resources/js')
    }
  },
  output: {
    chunkFilename: 'dist/js/[chunkhash].js',
    // path: mix.config.hmr ? '/' : path.resolve(__dirname, './public/build')
    path: path.resolve(__dirname, './public/build')
  }
})

mix.then(() => {
  // if (!mix.config.hmr) {
  //   process.nextTick(() => publishAseets())
  // }
  if (mix.inProduction()) {
    process.nextTick(() => publishAseets())
  }
})

function publishAseets () {
  const publicDir = path.resolve(__dirname, './public')

  if (mix.inProduction()) {
    fs.removeSync(path.join(publicDir, 'dist'))
  }

  fs.copySync(path.join(publicDir, 'build', 'dist'), path.join(publicDir, 'dist'))
  fs.removeSync(path.join(publicDir, 'build'))
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题