【发布时间】:2017-03-03 02:37:11
【问题描述】:
我将 Webpack 与 Angular 2 应用程序一起使用。 My Webpack 配置文件中的加载器如下所示。我删除了插件和导入以避免冗长的示例代码。 Webpack 正在用散列名称而不是 html 文件替换 css 文件中的图像。不知道我错过了什么。将不胜感激任何指针。
module.exports = function (options) {
const DATAS = {
VERSION: JSON.stringify(require("../package.json").version),
DEBUG_INFO_ENABLED: options.env === 'dev'
};
return {
entry: {
'polyfills': './src/main/webapp/app/polyfills',
'global': './src/main/webapp/content/css/global.css',
'main': './src/main/webapp/app/app.main'
},
resolve: {
extensions: ['.ts', '.js'],
modules: ['node_modules']
},
module: {
rules: [
{ test: /bootstrap\/dist\/js\/umd\//, loader: 'imports-loader?jQuery=jquery' },
{
test: /\.ts$/,
loaders: [
'angular2-template-loader',
'awesome-typescript-loader'
],
exclude: ['node_modules/generator-jhipster']
},
{
test: /\.html$/,
loader: 'raw-loader',
exclude: ['./src/main/webapp/index.html']
},
{
test: /\.css$/,
loaders: ['to-string-loader', 'css-loader'],
exclude: /(vendor\.css|global\.css)/
},
{
test: /(vendor\.css|global\.css)/,
loaders: ['style-loader', 'css-loader']
},
{
test: /\.(jpe?g|png|gif|svg|woff|woff2|ttf|eot)$/i,
loaders: [
'file-loader?hash=sha512&digest=hex&name=[hash].[ext]',
'image-webpack-loader?bypassOnDebug&optimizationLevel=7&interlaced=false'
]
},
{
test: /app.constants.ts$/,
loader: StringReplacePlugin.replace({
replacements: [{
pattern: /\/\* @toreplace (\w*?) \*\//ig,
replacement: function (match, p1, offset, string) {
return `_${p1} = ${DATAS[p1]};`;
}
}]
})
}
]
}
【问题讨论】:
标签: webpack