I have a angular 2 project originally used to bundle works with systemjs.
now i want use webpack to bundle this project.
But the original code has a lot of such a string. such as
I want to replace all the strings with the absolute directory where the files are located.The original time, prod mode or dev mode, this string will be replaced with a path string.
Now I would like to use a webpack to replace this string before a .ts file is piled. What kind of plugin should I use?
for example: login.module.routing.ts
{ path: 'login', /app/src/login#LoginModule },
I want replace before use webpack pile.
such as : { path: 'login', /root/myproject/app/src/login#LoginModule },
thanks very much !
I have a angular 2 project originally used to bundle works with systemjs.
now i want use webpack to bundle this project.
But the original code has a lot of such a string. such as
I want to replace all the strings with the absolute directory where the files are located.The original time, prod mode or dev mode, this string will be replaced with a path string.
Now I would like to use a webpack to replace this string before a .ts file is piled. What kind of plugin should I use?
for example: login.module.routing.ts
{ path: 'login', /app/src/login#LoginModule },
I want replace before use webpack pile.
such as : { path: 'login', /root/myproject/app/src/login#LoginModule },
thanks very much !
Share Improve this question edited Jun 3, 2017 at 23:37 Jeff Puckett 41.1k19 gold badges124 silver badges174 bronze badges asked May 28, 2017 at 8:45 xuefeng Yangxuefeng Yang 212 silver badges8 bronze badges1 Answer
Reset to default 11For this requirement you can use string-replace-webpack-plugin.
Usage Example:
var StringReplacePlugin = require("string-replace-webpack-plugin");
module.exports = {
module: {
loaders: [
// configure replacements for file patterns
{
test: /index.html$/,
loader: StringReplacePlugin.replace({
replacements: [
{
pattern: /<!-- @secret (\w*?) -->/ig,
replacement: function (match, p1, offset, string) {
return secrets.web[p1];
}
}
]})
}
]
},
plugins: [
// an instance of the plugin must be present
new StringReplacePlugin()
]
}
I hope this helps to solve your problem.