bahmutov / ng9-tour-of-heroes

Angular9 Tour of Heroes Part 6
0 stars 0 forks source link

How to use Webpack to build Angular components? #1

Open bahmutov opened 4 years ago

bahmutov commented 4 years ago

Without redefining everything manually?

Seems like node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/test.js is a good candidate for grabbing the webpack configuration

bahmutov commented 4 years ago

Alternative: try to use custom webpack config

@Component({
  selector: 'app-hero-detail',
  // using template string works
  // template: '',
  // using templateUrl does not work
  templateUrl: './hero-detail.component.html',
  styleUrls: [ './hero-detail.component.css' ]
})
Screen Shot 2020-05-12 at 8 57 30 AM

The webpack config

const webpackOptions = {
  resolve: {
    extensions: ['.ts', '.js']
  },
  module: {
    rules: [
      {
        test: /\.ts$/,
        use: [{
          loader: 'ts-loader',
          options: {
            transpileOnly: true
          }
        }, {
          loader: 'angular2-template-loader?keepUrl=true'
        }],
        exclude: [/node_modules/],
      },
      {
        test: /\.(css)$/,
        loaders: ['to-string-loader', 'css-loader']
      },
      {
        test: /\.(html)$/,
        loader: 'raw-loader'
      }
    ]
  }
}
LeJeanbono commented 4 years ago

Could do the job ? https://medium.com/@BiigDigital/angular-et-la-configuration-webpack-1f9398313e43

LeJeanbono commented 4 years ago

https://www.twilio.com/blog/2018/03/building-an-app-from-scratch-with-angular-and-webpack.html With

new HtmlWebpackPlugin({
     template: __dirname + '/src/index.html',
     output: __dirname + '/dist',
     inject: 'head'
}),