<commit_before>/*
 * Copyright (C) 2017 TypeFox and others.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
 */

import * as paths from 'path';
import { AbstractGenerator } from './abstract-generator';

export class WebpackGenerator extends AbstractGenerator {

    generate(): void {
        this.write(this.model.path('webpack.config.js'), this.compileWebpackConfig());
    }

    protected resolve(moduleName: string, path: string): string {
        return this.model.relative(paths.resolve(require.resolve(moduleName + '/package.json'), '../' + path)).split(paths.sep).join('/');
    }

    protected compileWebpackConfig(): string {
        return `// @ts-check
const path = require('path');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const CircularDependencyPlugin = require('circular-dependency-plugin');

const outputPath = path.resolve(__dirname, 'lib');

const development = process.env.NODE_ENV === 'development';

const monacoEditorPath = development ? '${this.resolve('monaco-editor-core', 'dev/vs')}' : '${this.resolve('monaco-editor-core', 'min/vs')}';
const monacoLanguagesPath = '${this.resolve('monaco-languages', 'release')}';
const monacoCssLanguagePath = development ? '${this.resolve('monaco-css', 'release/dev')}' : '${this.resolve('monaco-css', 'release/min')}';
const monacoJsonLanguagePath = development ? '${this.resolve('monaco-json', 'release/dev')}' : '${this.resolve('monaco-json', 'release/min')}';
const monacoHtmlLanguagePath = development ? '${this.resolve('monaco-html', 'release/dev')}' : '${this.resolve('monaco-html', 'release/min')}';${this.ifBrowser(`
const requirePath = '${this.resolve('requirejs', 'require.js')}';`)}

module.exports = {
    entry: path.resolve(__dirname, 'src-gen/frontend/index.js'),
    output: {
        filename: 'bundle.js',
        path: outputPath
    },
    target: '${this.ifBrowser('web', 'electron-renderer')}',
    node: {${this.ifElectron(`
        __dirname: false,
        __filename: false`, `
        fs: 'empty',
        child_process: 'empty',
        net: 'empty',
        crypto: 'empty'`)}
    },
    module: {
        rules: [
            {
                test: /\\.css$/,
                loader: 'style-loader!css-loader'
            },
            {
                test: /\\.(ttf|eot|svg)(\\?v=\\d+\\.\\d+\\.\\d+)?$/,
                loader: 'url-loader?limit=10000&mimetype=image/svg+xml'
            },
            {
                test: /node_modules.+xterm.+\.map$/,
                loader: 'ignore-loader'
            },
            {
                test: /\\.js$/,
                enforce: 'pre',
                loader: 'source-map-loader'
            },
            {
                test: /\\.woff(2)?(\\?v=[0-9]\\.[0-9]\\.[0-9])?$/,
                loader: "url-loader?limit=10000&mimetype=application/font-woff"
            }
        ],
        noParse: /vscode-languageserver-types|vscode-uri/
    },
    resolve: {<commit_msg>[webpack] added ignore warning for source-map-support (fixes #556)<commit_after>/*
 * Copyright (C) 2017 TypeFox and others.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
 */

import * as paths from 'path';
import { AbstractGenerator } from './abstract-generator';

export class WebpackGenerator extends AbstractGenerator {

    generate(): void {
        this.write(this.model.path('webpack.config.js'), this.compileWebpackConfig());
    }

    protected resolve(moduleName: string, path: string): string {
        return this.model.relative(paths.resolve(require.resolve(moduleName + '/package.json'), '../' + path)).split(paths.sep).join('/');
    }

    protected compileWebpackConfig(): string {
        return `// @ts-check
const path = require('path');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const CircularDependencyPlugin = require('circular-dependency-plugin');

const outputPath = path.resolve(__dirname, 'lib');

const development = process.env.NODE_ENV === 'development';

const monacoEditorPath = development ? '${this.resolve('monaco-editor-core', 'dev/vs')}' : '${this.resolve('monaco-editor-core', 'min/vs')}';
const monacoLanguagesPath = '${this.resolve('monaco-languages', 'release')}';
const monacoCssLanguagePath = development ? '${this.resolve('monaco-css', 'release/dev')}' : '${this.resolve('monaco-css', 'release/min')}';
const monacoJsonLanguagePath = development ? '${this.resolve('monaco-json', 'release/dev')}' : '${this.resolve('monaco-json', 'release/min')}';
const monacoHtmlLanguagePath = development ? '${this.resolve('monaco-html', 'release/dev')}' : '${this.resolve('monaco-html', 'release/min')}';${this.ifBrowser(`
const requirePath = '${this.resolve('requirejs', 'require.js')}';`)}

module.exports = {
    entry: path.resolve(__dirname, 'src-gen/frontend/index.js'),
    output: {
        filename: 'bundle.js',
        path: outputPath
    },
    target: '${this.ifBrowser('web', 'electron-renderer')}',
    node: {${this.ifElectron(`
        __dirname: false,
        __filename: false`, `
        fs: 'empty',
        child_process: 'empty',
        net: 'empty',
        crypto: 'empty'`)}
    },
    module: {
        rules: [
            {
                test: /\\.css$/,
                loader: 'style-loader!css-loader'
            },
            {
                test: /\\.(ttf|eot|svg)(\\?v=\\d+\\.\\d+\\.\\d+)?$/,
                loader: 'url-loader?limit=10000&mimetype=image/svg+xml'
            },
            {
                test: /node_modules.+xterm.+\.map$/,
                loader: 'ignore-loader'
            },
            {
                // see https://github.com/theia-ide/theia/issues/556
                test: /source-map-support/,
                loader: 'ignore-loader'
            },
            {
                test: /\\.js$/,
                enforce: 'pre',
                loader: 'source-map-loader'
            },
            {
                test: /\\.woff(2)?(\\?v=[0-9]\\.[0-9]\\.[0-9])?$/,
                loader: "url-loader?limit=10000&mimetype=application/font-woff"
            }
        ],
        noParse: /vscode-languageserver-types|vscode-uri/
    },
    resolve: {
{'fraction_non_alphanumeric': 0.18080391257832798, 'fraction_numerical': 0.00855876509246523, 'mean_word_length': 2.5488069414316703, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7552648', 'n_tokens_mistral': 2038, 'n_tokens_neox': 1964, 'n_words': 373}