Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declaration files not generated #711

Closed
JonWallsten opened this issue Jan 17, 2018 · 2 comments
Closed

Declaration files not generated #711

JonWallsten opened this issue Jan 17, 2018 · 2 comments

Comments

@JonWallsten
Copy link
Contributor

JonWallsten commented Jan 17, 2018

Expected Behaviour

When declaration is set to true in tsconfig.json d.ts files should be generated, either as files in the dist-folder, in a tmp folder or via DeclarationBundlerPlugin.

Actual Behaviour

No d.ts files are generated. When debugging the DeclarationBundlerPlugin no d.ts file are emitted. compilation.assets doesn't include any d.ts files.
When running "npm run tsc" files are generated.
No error messages appear.

Steps to Reproduce the Problem

npm run webpack -- --config config/webpack.prod.js --progress --profile --bail --display-entrypoints

Location of a Minimal Repository that Demonstrates the Issue.

Private repo which can't be shared. Please see config files instead:

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "noUnusedLocals": true,
    "noEmitHelpers": true,
    "noEmitOnError": true,
    "importHelpers": true,
    "strictNullChecks": false,
    "pretty": true,
    "sourceMap": true,
    "declaration": true,
    "outDir": ".tmp/code",
    "lib": [
      "dom",
      "es6"
    ],
    "typeRoots": [
      "node_modules/@types"
    ]
  },
  "include": [
    "src/**/*.ts",
    "typings/global.d.ts",
  ],
  "exclude": [
    "node_modules",
    "dist"
  ],
  "compileOnSave": false,
  "buildOnSave": false
}

config/webpack.base.js

const helpers = require('./helpers');

/**
 * Webpack Plugins
 */
const webpack = require('webpack');
const glob = require('glob');
const DefinePlugin = require('webpack/lib/DefinePlugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HappyPack = require('happypack');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const DtsBundlePlugin = require('./plugins/dts-bundle');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const DeclarationBundlerPlugin = require('declaration-bundler-webpack-plugin');
const dtsBuilder = require('dts-builder');

/**
 * Webpack configuration
 *
 * See: http://webpack.github.io/docs/configuration.html#cli
 */
module.exports = function (options) {
  //const isProd = options.env === 'production';

  return {
    output: {
      libraryTarget: 'umd'
    },
    /**
     * The entry point for the bundle
     * Our Angular.js app
     *
     * See: http://webpack.github.io/docs/configuration.html#entry
     */
    entry: [
      './src/index.ts',
      './src/legacy.js'
    ],

    /**
     * Options affecting the resolving of modules.
     *
     * See: http://webpack.github.io/docs/configuration.html#resolve
     */
    resolve: {
      /**
       * An array of extensions that should be used to resolve modules.
       *
       * See: http://webpack.github.io/docs/configuration.html#resolve-extensions
       */
      extensions: ['.ts', '.js', '.json', '.css', '.less'],

      /**
       * An array of directory names to be resolved to the current directory
       */
      modules: [helpers.root('src'), helpers.root('node_modules')],
    },

    /**
     * Options affecting the normal modules.
     *
     * See: http://webpack.github.io/docs/configuration.html#module
     */
    module: {

      rules: [

        {
          test: /\.ts?$/,
          loader: 'happypack/loader?id=ts',
          exclude: [helpers.exclude]
        },

        /**
         * Raw loader support for *.html
         * Returns file content as string
         *
         * See: https://github.com/webpack/raw-loader
         */
        {
          test: /\.html$/,
          use: 'html-loader',
          exclude: [helpers.exclude]
        },

        /**
         * File loader for supporting images, for example, in CSS files.
         */
        {
          test: /\.(jpg|png|gif)$/,
          use: 'file-loader',
        },

        /* File loader for supporting fonts, for example, in CSS files.
        */
        {
          test: /\.(eot|woff2?|svg|ttf)([\?]?.*)$/,
          use: 'file-loader',
        }

      ],

    },

    /**
     * Add additional plugins to the compiler.
     *
     * See: http://webpack.github.io/docs/configuration.html#plugins
     */
    plugins: [
      /**
       * Plugin: DefinePlugin
       * Description: Define free variables.
       * Useful for having development builds with debug logging or adding global constants.
       *
       * Environment helpers
       *
       * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
       */
      // NOTE: when adding more properties make sure you include them in custom-typings.d.ts
      new DefinePlugin({}),

      new webpack.optimize.UglifyJsPlugin({
        warning: false,
        mangle: false,
        comments: true
      }),

      new HappyPack({
        id: 'ts',
        threads: 2,
        loaders: [{
          path: 'ts-loader',
          query: {
            happyPackMode: true
          }
        }]
      }),

      new ForkTsCheckerWebpackPlugin({ checkSyntacticErrors: true }),

      new DeclarationBundlerPlugin({
        moduleName:'module',
        out:'index.d.ts',
      })


    ],

    /**
     * Include polyfills or mocks for various node stuff
     * Description: Node configuration
     *
     * See: https://webpack.github.io/docs/configuration.html#node
     */
    node: {
      global: true,
      crypto: 'empty',
      process: true,
      module: false,
      clearImmediate: false,
      setImmediate: false
    }

  };
}

config/webpack.prod.js

/**
 * @author: @AngularClass
 */
const helpers = require('./helpers');
const webpack = require('webpack');
const webpackMerge = require('webpack-merge');
const commonConfig = require('./webpack.base.js');

/**
 * Webpack Plugins
 */
const SourceMapDevToolPlugin = require('webpack/lib/SourceMapDevToolPlugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');


module.exports = function (env) {
  const ENV = process.env.NODE_ENV = process.env.ENV = 'production';

  return webpackMerge(commonConfig({ env: ENV }), {

    /**
     * Options affecting the output of the compilation.
     *
     * See: http://webpack.github.io/docs/configuration.html#output
     */
    output: {

      /**
       * The output directory as absolute path (required).
       *
       * See: http://webpack.github.io/docs/configuration.html#output-path
       */
      path: helpers.root('dist'),

      /**
       * Specifies the name of each output file on disk.
       * IMPORTANT: You must not specify an absolute path here!
       *
       * See: http://webpack.github.io/docs/configuration.html#output-filename
       */
      filename: '[name].[chunkhash].js',
    },

    module: {

      rules: [
        {
          test: /\.css$/,
          use: ExtractTextPlugin.extract({
            fallback: "style-loader",
            use: ["css-loader", "postcss-loader"]
          }),
          exclude: helpers.exclude
        },
        {
          test: /\.less$/,
          use: ExtractTextPlugin.extract({
            use: ["css-loader", "postcss-loader", "less-loader",]
          }),
          exclude: helpers.exclude
        }
      ]

    },

    /**
     * Add additional plugins to the compiler.
     *
     * See: http://webpack.github.io/docs/configuration.html#plugins
     */
    plugins: [
      /**
       * Plugin: ExtractTextPlugin
       * Description: Extracts imported CSS files into external stylesheet
       *
       * See: https://github.com/webpack/extract-text-webpack-plugin
       */
      new ExtractTextPlugin({
        disable: false,
        filename: 'index.css',
        allChunks: true
      }),

      /**
       * Plugin: UglifyJsPlugin
       * Description: Minimize all JavaScript output of chunks.
       * Loaders are switched into minimizing mode.
       *
       * See: https://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin
       *
       * NOTE: To debug prod builds uncomment //debug lines and comment //prod lines
       */
      new UglifyJsPlugin({
        sourceMap: false,
        uglifyOptions: {
          ecma: 6,
          warnings: false,
          ie8: false,
          mangle: false,
          compress: true,
          output: {
            ascii_only: true,
            comments: false
          }
        }
      })
    ]
  });
}

@JonWallsten
Copy link
Contributor Author

Seems like it's because I'm using HappyPack. Would that be a bug or a feature?

@johnnyreilly
Copy link
Member

If you're using happypack then you're running in transpileOnly mode. Declaration files aren't generated by the Typescript compiler in this mode - I think there are workarounds which have been discussed on one of the issues here. Have a little explore and you should find it.

Closing for now as intended behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants