rxaviers / globalize-webpack-plugin

Globalize.js webpack plugin
Other
33 stars 27 forks source link

bower + AMD support #40

Open nishantkagrawal opened 7 years ago

nishantkagrawal commented 7 years ago

@rxaviers I am having issues with bower-resolve-webpack-plugin and globalize-plugin to work together.

If I install gloablize in node_modules it works fine. But globalize-webpack-plugin doesn't pickup the globalize module from bower_components.

Note that all my other modules are loaded from bower_components using bower-resolve-webpack-plugin.

bower-resolve-plugin is using existing-directory plugin to process all the stuff. When webpack hits globalize, it ignores that plugin somehow.

The following is my configuration.

resolve: {
plugins: [
new BowerResolvePlugin(),

        new webpack.optimize.CommonsChunkPlugin({
            name: ['app', 'vendor']
        }),
    ],
    extensions: ['.js'],
    modules: ['node_modules', 'bower_components'],
    descriptionFiles: ['package.json', 'bower.json', '.bower.json'],
    mainFields: ['main', 'browser']
},

plugins: [
    new globalizePlugin({
        production: true, // true: production, false: development
        developmentLocale: 'en', // locale to be used for development.
        supportedLocales: ['en'], // locales that should be built support for.
        messages: 'messages/[locale].json', // messages (optional)
        output: 'globalize-compiled-data-[locale].[hash].js', // build output.                
    }),
],

The following is the error:

ERROR in ./generated/typescript/webpack-vendor.js Module parse failed: \generated\typescript\webpack-vendor.js Cannot find module 'globalize' You may need an appropriate loader to handle this file type. Error: Cannot find module 'globalize' at Function.Module._resolveFilename (module.js:469:15) at Function.Module._load (module.js:417:25) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at Object.compileExtracts (some_path\node_modules\globalize-compiler\lib\compile-extracts.js:9:18) at GlobalizeCompilerHelper.compile (some_path\node_modules\globalize-webpack-plugin\GlobalizeCompilerHelper.js:63:33) at GlobalizeCompilerHelper.createCompiledDataModule (some_path\node_modules\globalize-webpack-plugin\GlobalizeCompilerHelper.js:37:35) at Parser.<anonymous> (some_path\node_modules\globalize-webpack-plugin\ProductionModePlugin.js:89:60) at Parser.applyPluginsBailResult (some_path\node_modules\tapable\lib\Tapable.js:109:27) at Parser.parser.plugin (some_path\node_modules\webpack\lib\dependencies\CommonJsRequireDependencyParserPlugin.js:59:27) at Parser.applyPluginsBailResult1 (some_path\node_modules\tapable\lib\Tapable.js:120:27) at Parser.walkCallExpression (some_path\node_modules\webpack\lib\Parser.js:896:18) at Parser.walkExpression (some_path\node_modules\webpack\lib\Parser.js:693:40) at Parser.walkExpressionStatement (some_path\node_modules\webpack\lib\Parser.js:443:7) at Parser.walkStatement (some_path\node_modules\webpack\lib\Parser.js:434:32) at Parser.<anonymous> (some_path\node_modules\webpack\lib\Parser.js:417:9) at Array.forEach (native) at Parser.walkStatements (some_path\node_modules\webpack\lib\Parser.js:415:13) at Parser.parse (some_path\node_modules\webpack\lib\Parser.js:1145:8) at some_path\node_modules\webpack\lib\NormalModule.js:200:17 at some_path\node_modules\webpack\lib\NormalModule.js:162:10 at some_path\node_modules\loader-runner\lib\LoaderRunner.js:370:3 at iterateNormalLoaders (some_path\node_modules\loader-runner\lib\LoaderRunner.js:211:10) at Array.<anonymous> (some_path\node_modules\loader-runner\lib\LoaderRunner.js:202:4) at Storage.finished (some_path\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:38:15) at some_path\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:69:9 at some_path\node_modules\graceful-fs\graceful-fs.js:78:16 at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:445:3) @ multi ./generated/typescript/webpack-vendor.js

Am I missing a sequence in which the plugins should be setup or anything else?

The basic repo to reproduce this problem is here

nishantkagrawal commented 7 years ago

Do you have any temporary workaround for this?

rxaviers commented 7 years ago

Hi @nishantkagrawal, sorry but I haven't used myself this plugin with bower. Are you using AMD?

nishantkagrawal commented 7 years ago

@rxaviers, Yes I am using AMD.

rxaviers commented 7 years ago

Yes I am using AMD.

Interesting...

Globalize itself indeed supports either CommonJS or AMD, but this webpack plugin only supports CommonJS (for history/context, please see https://github.com/globalizejs/globalize/issues/441). Therefore, this plugin deliberatively disables the AMD portion of Globalize UMD wrapper (dev code prod code).

If you have a better idea to make this plugin work smoothly by CJS and AMD users, feel free to submit your thoughts and a PR.

Thank you