express
+ webpack3
+ ejs
+ TypeScript
を使用します
ビルドすると、stdout
出力で警告が表示されます。
WARNING in ./node_modules/ejs/lib/ejs.js
require.extensions is not supported by webpack. Use a loader instead.
@ ./src/environment.ts 4:10-24
@ ./src/server.ts
WARNING in ./node_modules/ejs/lib/ejs.js
require.extensions is not supported by webpack. Use a loader instead.
@ ./src/environment.ts 4:10-24
@ ./src/server.ts
WARNING in ./node_modules/express/lib/view.js
80:29-41 Critical dependency: the request of a dependency is an expression
ここにwebpack.config.ts
の一部があります:
import * as webpack from 'webpack';
import * as path from 'path';
import * as CopyWebpackPlugin from 'copy-webpack-plugin';
const config: webpack.Configuration = {
target: 'node',
devtool: 'source-map',
entry: {
server: path.resolve(__dirname, './src/server.ts')
},
output: {
path: path.resolve(__dirname, 'build'),
filename: 'server.js'
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
loader: 'ts-loader'
}
]
},
resolve: {
extensions: ['.ts', '.tsx', '.js']
},
plugins: [
new CopyWebpackPlugin([
{ from: './src/views', to: 'views' },
{ from: './src/public', to: 'public' }
])
]
};
export default config;
およびtsconfig.json
の一部:
"include": [
"src/server.ts",
"src/typings"
],
"exclude": [
"node_modules",
"src/public",
"src/views"
]
この設定ではejs
を使用し、ejs
固有の解決策はwebpack設定でこれを設定することです。
resolve: {
alias: {
'ejs': 'ejs.min.js'
}
}
同じ問題が発生し、webpack.config.jsファイルに次のコードを追加して解決しました。
resolve: {
alias: {
'express-handlebars': 'handlebars/dist/handlebars.js'
}
}