[Vuejs]-Extracting strings from source files during webpack bundling

0👍

if $t() is an invocation of a function, u can write a webpack plugin that will hook the parser and trace all of the invocations, then write them to file using emit hook to write the collected data to file.

compiler.hooks.normalModuleFactory.tap('MyPlugin', factory => {
  factory.hooks.parser.for('javascript/auto').tap('MyPlugin', (parser, options) => {
    parser.hooks.expression.for('$t').tap("MyPlugin", expr => {
       console.log(expr);
    });
  });
});

Good blog post about starting with webpack plugins: https://medium.com/webpack/the-contributors-guide-to-webpack-part-2-9fd5e658e08c

You can check the source code of providePlugin as a reference, read here what it does.

Leave a comment