Erro ao rodar o electron-vue
npm run dev error
Html Webpack Plugin:
Como resolver ReferenceError: process is not defined
No arquivo ..src\main\index.js adicione nodeIntegration
mainWindow = new BrowserWindow({ height: 563, useContentSize: true, width: 1000, title: 'TBFE', webPreferences: { nodeIntegration: true // add this } })
Nos arquivos:
…electron-vue\webpack.renderer.config.js
…electron-vue\webpack.web.config.js
Adicione o código abaixo:
templateParameters(compilation, assets, options) { return { compilation: compilation, webpack: compilation.getStats().toJson(), webpackConfig: compilation.options, htmlWebpackPlugin: { files: assets, options: options }, process, }; }
Ficando assim então no seu arquivo …electron-vue\webpack.renderer.config.js
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.resolve(__dirname, '../src/index.ejs'),
templateParameters(compilation, assets, options) {
return {
compilation: compilation,
webpack: compilation.getStats().toJson(),
webpackConfig: compilation.options,
htmlWebpackPlugin: {
files: assets,
options: options
},
process,
};
},
minify: {
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true
},
nodeModules: false
}),
E no arquivo ..electron-vue\webpack.web.config.js
if (process.env.NODE_ENV === 'production') {
webConfig.devtool = ''webConfig.plugins.push(
templateParameters(compilation, assets, options) {
return {
compilation: compilation,
webpack: compilation.getStats().toJson(),
webpackConfig: compilation.options,
htmlWebpackPlugin: {
files: assets,
options: options
},
process,
};
},
new MinifyPlugin(),
new CopyWebpackPlugin([
{
from: path.join(__dirname, '../static'),
to: path.join(__dirname, '../dist/web/static'),
ignore: ['.*']
}
]),
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"'
}),
new webpack.LoaderOptionsPlugin({
minimize: true
})
)}
Deixe um comentário