简体   繁体   English

如何使用带有 angular-builder 的自定义 webpack 将整个目录复制到 dist/ 中?

[英]How do I copy an entire directory into dist/ using custom webpack with angular-builders?

I'm using Angular builders to add some additional files and folders in the dist/ directory generated.我正在使用 Angular 构建器在生成的dist/目录中添加一些额外的文件和文件夹。 In this case I want to have the directories src/assert/puppies and src/assert/kittens copied into a folder called animals/ .在这种情况下,我希望将目录src/assert/puppiessrc/assert/kittens复制到名为animals/的文件夹中。

In other words, I want this换句话说,我想要这个

src/
 |--- assets/
        |----puppies/
                |--- *.jpg
                |--- ....
        |----kittens/
                |--- *.jpg
                |--- ....

to become this成为这个

dist/
 | main.js
 | vendor.js
 | ...
 |--- animals/
         |--- images...

angular.json angular.json

This is the relevant portion of my angular.json file:这是我的 angular.json 文件的相关部分:

"build": {
          "builder": "@angular-builders/custom-webpack:browser",
          "options": {
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": true,
            "assets": [
              "src/favicon.ico",
              "src/assets",
              "src/manifest.json",
              {
                "input": "node_modules/jquery/dist",
                "glob": "jquery.js",
                "output": "./vendor"
              }
            ],
            "styles": ["src/styles.scss"],
            "scripts": [],
            "customWebpackConfig": {
              "path": "./custom-webpack.config.js"
            }
          }, 

This is my custom-webpack.config.js .这是我的custom-webpack.config.js I already have this content in there because I want these scripts to be compiled and copied over.我已经在那里有了这些内容,因为我希望编译和复制这些脚本。

module.exports = {
  entry: {
    "special-scripts/login":
      "src/custom/login/login.ts",
    "special-scripts/logout":
      "src/custom/logout/logout.ts"
  }
};

What do I add to custom-webpack.config.js to get it to copy over those asset folders into dist/ in the way I described above?我要向custom-webpack.config.js添加什么以使其以上述方式将这些资产文件夹复制到dist/中?

You can use the CopyWebpackPlugin .您可以使用CopyWebpackPlugin

Import it into your custom-webpack.config.js:将其导入您的 custom-webpack.config.js:

const CopyPlugin = require('copy-webpack-plugin');

Then add it to your plugins:然后将其添加到您的插件中:

plugins: [
  new CopyPlugin([
    { from: './src/assets/*', to: 'dist/animals/' },
  ]),
  ...
]

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

相关问题 Angular 项目在 scss 文件上使用 @angular-builders/custom-webpack 编译失败 - Angular Project fails compilation with @angular-builders/custom-webpack on scss files 如何使用Angular-CLI配置/构建dist目录并在Angular2中包含图像 - How do I configure/structure the dist directory and include images in Angular2 using the Angular-CLI 找不到 builder @angular-builders/jest:run 的实现 - Could not find the implementation for builder @angular-builders/jest:run 使用多个自定义 angular 构建器 - Using multiple custom angular builders 如何获得angular 2 cli将css和其他必要文件复制到dist文件夹 - How do I get angular 2 cli to copy css and other necessary files to dist folder 如何解决“包“@angular-devkit/build-angular”没有定义构建器”错误 - How do I resolve 'Package “@angular-devkit/build-angular” has no builders defined' error 依次运行 angular 自定义构建器 - Run angular custom builders in sequence 我如何使用 angular-cli 复制“../node_modules/swagger-ui/dist” - How i can copy "../node_modules/swagger-ui/dist" with angular-cli 生成构建后如何将 Angular dist 内容复制到另一个位置? - How to copy Angular dist content to another location after generating the build? 使用ngrx时如何重新初始化Angular中的组件或整个应用程序? - How Do I reinitialize components or entire app in Angular when using ngrx?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM