简体   繁体   English

AngularClass/angular2-webpack-starter:从用于 PROD 构建的 webpack 配置中排除模拟文件

[英]AngularClass/angular2-webpack-starter : exclude mock files from webpack config for PROD builds

I'm using the AngularClass/angular2-webpack-starter and I've been struggling with its webpack configuration for a while, although what I want to achieve seems very simple.我正在使用AngularClass/angular2-webpack-starter并且我一直在努力使用它的webpack配置,尽管我想要实现的目标看起来很简单。

Basically, I have some mock files located in src\\assets\\mock\\data that I'd like to keep in the dev build, but that I want to exclude from the prod build.基本上,我在src\\assets\\mock\\data一些我想保留在开发版本中的模拟文件,但我想从生产版本中排除它们。 These mock files should be excluded from the prod build according to a regexp on their name (I tried several flavours of something like exclude: [/^mock\\.data\\..*\\.json$/] , or by folder, or at the very least by listing them all.这些模拟文件应该根据它们名称上的正则表达式从prod构建中排除(我尝试了几种类似exclude: [/^mock\\.data\\..*\\.json$/] ,或按文件夹,或至少通过列出所有这些。

The dev build using webpack.dev.js is fine, but I've been tinkering with the webpack.prod.js file to no avail until now.使用webpack.dev.js开发构建很好,但我一直在修改webpack.prod.js文件直到现在都无济于事。

Could someone point me in the right direction ?有人能指出我正确的方向吗? Thank you.谢谢你。

Context: angular2-webpack-starter上下文: angular2-webpack-starter

The assets folder recopy during the build task is handle by a webpack plugin aka CopyWebpackPlugin .在构建任务期间重新复制 assets 文件夹由 webpack 插件 aka CopyWebpackPlugin 处理 By default it is only setup in the webpack.common.js .默认情况下,它仅在webpack.common.js 中设置。 To achieve what you are trying to, you should put the same task in both of your environments.为了实现您的目标,您应该在两个环境中放置相同的任务。 That way you would be able to exclude the unwanted files.这样您就可以排除不需要的文件。

  1. webpack.common.js webpack.common.js

     new CopyWebpackPlugin([ { from: 'src/meta'} ])
  2. webpack.dev.js webpack.dev.js

     new CopyWebpackPlugin([ { from: 'src/assets', to: 'assets' } ])
  3. webpack.prod.js webpack.prod.js

     new CopyWebpackPlugin([ { from: 'src/assets', to: 'assets', ignore: ['mock/data/*'] } ])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM