Ich versuche eine eckige + Typoskript + Webpack-Anwendung zu erstellen. Ich benutzte this als Quelle und änderte wie pro meine Anforderung.Webpack: Unerwartetes Token: in webpack.config.ts
Das ist mein webpack.config.ts:
const {
optimize: {
CommonsChunkPlugin,
DedupePlugin
}
} = require('webpack');
const { ConcatSource } = require('webpack-sources');
const { TsConfigPathsPlugin } = require('awesome-typescript-loader');
const AssetsPlugin = require('assets-webpack-plugin');
const path = require('path');
const fs = require('fs');
function root(__path = '.') {
return path.join(__dirname, __path);
}
// type definition for WebpackConfig is defined in webpack.d.ts
function webpackConfig(options: EnvOptions = {}): WebpackConfig {
const CONSTANTS = {
ENV: JSON.stringify(options.ENV),
PORT: 3000,
HOST: 'localhost',
HTTPS: false
};
const isProd = options.ENV.indexOf('prod') !== -1;
return {
cache: true,
devtool: 'source-map',
entry: {
main: './src/index'
},
output: {
path: root('dist'),
filename: '[name].bundle.js',
sourceMapFilename: '[name].map',
},
module: {
loaders: [
{
test: /\.ts$/,
loader: 'awesome-typescript-loader',
exclude: [/\.(spec|e2e|d)\.ts$/],
include: [root('../src')]
},
{ test: /\.json$/, loader: 'json-loader', include: [root('../src')] }
]
},
plugins: [
new AssetsPlugin({
path: root('dist'),
filename: 'webpack-assets.json',
prettyPrint: true
}),
new TsConfigPathsPlugin(/* { tsconfig, compiler } */)
],
resolve: {
extensions: ['.ts', '.js', '.json']
},
node: {
global: true,
process: true,
Buffer: false,
crypto: 'empty',
module: false,
clearImmediate: false,
setImmediate: false,
clearTimeout: true,
setTimeout: true
}
};
}
// Export
module.exports = webpackConfig;
wenn ich $> webpack --config webpack.config.ts
laufen ich erhalte den folgenden Fehler.
$ webpack --config ./configs/webpack.config.ts
PathToProject\WebStorageManager\configs\webpack.config.ts:19
function webpackConfig(options: EnvOptions = {}): WebpackConfig {
^
SyntaxError: Unexpected token :
at Object.exports.runInThisContext (vm.js:76:16)
Vermisse ich einige Webpack-Konfiguration?
Wenn das der Fall ist, dann wie könnte ich [this] (https://github.com/AngarClass/angular2-seed) -Projekt mit 'webpack.config.ts' Datei – Thaadikkaaran
erstellen Eine Möglichkeit ist, nur TSC ausführen manuell und laden Sie die resultierende .js-Datei. Ich habe meine Antwort aktualisiert, um einen weiteren möglichen Weg mit ts-node einzuschließen. Diese Option ist wahrscheinlich das, wonach Sie suchen. – dtabuenc
Das hat funktioniert! Gibt es ein Dokument, in dem über Ihre aktualisierte Antwort gesprochen wird? – Thaadikkaaran