Gradle运行webpack任务,但没有效果

时间:2018-09-19 05:12:12

标签: gradle

我有以下gradle构建设置:

node {
    version = '8.9.1'
    // If true, it will download node using above parameters.
    // If false, it will try to use globally installed node.
    download = true
    //the work directory for npm
    npmWorkDir = file('src/main/ui')
    //the directory for node_modules
    nodeModulesDir = file('src/main/ui')
}

task webpack(type: YarnTask, dependsOn: 'npmInstall') {
    args = ['build']
    // the same name as the script in package.json
}

task copyTask(type: Copy, dependsOn: 'webpack') {
    from 'src/main/ui/bundle.js'
    into 'src/main/resources/public/static/js/'
}

processResources.dependsOn 'copyTask'

以及package.json中的以下脚本:

"scripts": {
  "start": "npx webpack-dev-server",
  "build": "npx webpack",
  "test": "echo \"Error: no test specified\" && exit 1"
},

这是webpack.config.js

module.exports = {
  entry: './src/index.js',
  output: {
    path: __dirname,
    publicPath: '/',
    filename: 'bundle.js'
  },
  module: {
    rules: [{
      test: /\.js$/,
      exclude: /node_modules/,
      loader: 'babel-loader'
    }]
  },
  mode: 'development',
  devServer: {
    historyApiFallback: true,
    contentBase: './'
  }
};

Gradle运行构建脚本(我可以在gradle日志中看到npx webpack),但是看不到build.js。当我在终端中运行npx webpack时,我看到它生成了。我想知道为什么gradle运行时没有生成它。

0 个答案:

没有答案