After I installed jest, setup babel, eslint, jest-setup and etc then I checked jest works fine.
But when I npm run serve(vue-clie-service serve), It includes test folders(__test __/abc.spec.js).
I would like to exclude all files below __test
__ direcotry when npm run serve.
It occurs error now jest is not defined. describe is note defined...
#jest.config.js
module.exports = {
moduleFileExtensions: [
"js",
"json",
"vue",
],
transform: {
".*\\.(vue)$": "vue-jest",
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
".+\\.(css|styl|less|sass|scss)$": "jest-transform-css",
},
moduleNameMapper: {
"^#/(.*)$": "<rootDir>/src/$1",
"\\.(css|less|scss|sass)$": "identity-obj-proxy",
},
transformIgnorePatterns: ["<rootDir>/node_modules/"],
collectCoverage: false,
collectCoverageFrom: ["**/*.{js,vue}", "!**/node_modules/**"],
coverageReporters: ["html", "text-summary"],
testMatch: [
"<rootDir>/src/**/__tests__/**/*.{js,jsx,mjs}",
"<rootDir>/src/**/?(*.)(spec|test).{js,jsx,mjs}",
],
setupFilesAfterEnv: ["<rootDir>/jest-setup.js"],
preset: "#vue/cli-plugin-unit-jest",
};
# main.js
import Vue from "vue";
import "./plugins/axios";
import App from "./App";
import router from "./router";
import store from "./store";
import i18n from "./plugins/i18n";
import vuetify from "./plugins/vuetify";
import "#/assets/styles/_global.scss";
import "#babel/polyfill";
Vue.config.productionTip = false;
new Vue({
i18n,
router,
store,
vuetify,
render: h => h(App),
}).$mount("#app");
# vue.config.js
const path = require("path");
const ansiRegex = require("ansi-regex");
module.exports = {
devServer: {
proxy: {
"/api": {
target: process.env.VUE_APP_TARGET,
changeOrigin: true,
},
},
},
configureWebpack: {
resolve: {
alias: {
"#": path.join(__dirname, "src/"),
},
},
},
css: {
loaderOptions: {
scss: {
prependData: "#import \"#/assets/styles/_global.scss\";",
},
},
},
transpileDependencies: [
"vuetify",
ansiRegex,
],
};
i try to help you but could you share jest.config.js or another config file.
Could you try this code on config file.
Attention: You must edit your folder path and if you don't use Typescript, you delete ts and tsx.
#jest.config.js
module.exports = {
preset: 'ts-jest',
verbose: true,
collectCoverage: true,
collectCoverageFrom: [
'**/*.{ts,vue}',
'!**/node_modules/**',
'!**/vendor/**'
],
coverageReporters: [
'json', 'lcov', 'text'
],
moduleFileExtensions: [
'js',
'jsx',
'json',
'vue',
'ts',
'tsx'
],
transform: {
'^.+\\.vue$': 'vue-jest',
'.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub',
'^.+\\.tsx?$': 'ts-jest',
'^.+\\.ts?$': 'ts-jest',
'^.+\\.jsx?$': 'babel-jest',
'^.+\\.js?$': 'babel-jest'
},
moduleNameMapper: {
'^#/(.*)$': '<rootDir>/src/$1',
'^#/application/(.*)$': '<rootDir>/src/application/$1',
'^#/common/(.*)$': '<rootDir>/src/common/$1',
'^#/components/(.*)$': '<rootDir>/src/components/$1'
},
transformIgnorePatterns: [
'/node_modules/(?!(tiny-slider)/(.*)$)'
],
snapshotSerializers: [
'jest-serializer-vue'
],
testMatch: [
'**/src/**/*.spec.(js|jsx|ts|tsx)',
'**/src/application/**/*.spec.(js|jsx|ts|tsx)',
'**/src/common/**/*.spec.(js|jsx|ts|tsx)',
'**/src/components/**/*.spec.(js|jsx|ts|tsx)',
'**/tests/unit/**/*.spec.(js|jsx|ts|tsx)'
],
testURL: 'http://localhost:8080/'
}
Related
I've been working on using ModuleFederation and have ran into an issue where if the remote webpack configuration had optimize.splitChunks.chunk = "all" then the host application would throw a loadScript exception. This could be a complete fundamental knowledge gap on my part why that wouldn't work. I haven't seen any documentation on not using that option along with Module Federation.
Has anyone had similar experiences or can tell me why it's a conflicting setting?
Thanks for your help!
remote webpack.config.js
const path = require("path");
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { ModuleFederationPlugin } = webpack.container;
module.exports = {
entry: "./index.js",
mode: "development",
devServer: {
contentBase: path.join(__dirname, "dist"),
port: 1338,
},
output: {
publicPath: "auto",
},
optimization: {
splitChunks: {
chunk: "all"
}
},
module: {
rules: [
{
test: /\.jsx?$/,
loader: "babel-loader",
exclude: /node_modules/,
options: {
presets: ["#babel/preset-react"],
},
},
],
},
plugins: [
new ModuleFederationPlugin({
name: "comic",
filename: "remoteEntry.js",
exposes: {
"./XKCD": "./app.jsx",
},
shared: [
{
react: { singleton: true, eager: true },
"react-dom": { singleton: true, eager: true },
},
],
}),
new HtmlWebpackPlugin({
template: "./index.html",
}),
],
};
host webpack.config.js
const HtmlWebpackPlugin = require("html-webpack-plugin");
const ModuleFederationPlugin = require("webpack").container
.ModuleFederationPlugin;
const path = require("path");
module.exports = {
entry: "./index.js",
mode: "development",
devServer: {
contentBase: path.join(__dirname, "dist"),
port: 1337,
},
output: {
publicPath: "auto",
},
module: {
rules: [
{
test: /\.jsx?$/,
loader: "babel-loader",
exclude: /node_modules/,
options: {
presets: ["#babel/preset-react"],
},
},
],
},
plugins: [
new ModuleFederationPlugin({
name: "home",
filename: "remoteEntry.js",
remotes: {
comic: `comic#http://localhost:1338/remoteEntry.js)`,
},
shared: [
{
react: { singleton: true, eager: true },
"react-dom": { singleton: true, eager: true },
},
],
}),
new HtmlWebpackPlugin({
template: "./index.html",
}),
],
};
I have a similar problem.
I change the remote webpack.config.js optimization.splitChunks as
optimization: {
splitChunks: {
chunks: 'async'
}
}
This problem is fixed.
Maybe you can try it.
Sorry my pool english
After running npm run build, I get an error: Error: [VuetifyLoaderPlugin Error] No matching rule for vue-loader found.Make sure there is at least one root-level rule that uses vue-loader and VuetifyLoaderPlugin is applied after VueLoaderPlugin.
package.json
{
"name": "client",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate"
},
"dependencies": {
"#nuxtjs/axios": "^5.13.6",
"core-js": "^3.15.1",
"dotenv": "^10.0.0",
"nuxt": "^2.15.7",
"nuxt-i18n": "^6.27.3",
"nuxt-mail": "^3.0.10",
"vuetify": "^2.5.5"
},
"devDependencies": {
"#fortawesome/fontawesome-free": "^5.15.3",
"#fortawesome/fontawesome-svg-core": "^1.2.35",
"#fortawesome/free-brands-svg-icons": "^5.15.3",
"#fortawesome/free-solid-svg-icons": "^5.15.3",
"#fortawesome/vue-fontawesome": "^2.0.2",
"#mdi/font": "^5.9.55",
"#nuxtjs/fontawesome": "^1.1.2",
"#nuxtjs/vuetify": "^1.12.1",
"eslint-config-prettier": "^8.3.0",
"font-awesome": "^4.7.0",
"material-design-icons-iconfont": "^6.1.0",
"prettier": "^2.3.2"
}
}
Here is my config nuxt.config.js file:
import colors from 'vuetify/es5/util/colors'
import i18n from './config/i18n'
export default {
// Global page headers: https://go.nuxtjs.dev/config-head
head: {
titleTemplate: '%s - client',
title: 'client',
htmlAttrs: {
lang: 'en'
},
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ hid: 'description', name: 'description', content: '' },
{ name: 'format-detection', content: 'telephone=no' }
],
link: [
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
]
},
// Global CSS: https://go.nuxtjs.dev/config-css
css: [
],
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
plugins: [
],
// Auto import components: https://go.nuxtjs.dev/config-components
components: true,
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
buildModules: [
[
'nuxt-i18n',
{
vueI18nLoader: true,
defaultLocale: 'hr',
locales: [
{
code: 'en',
name: 'Eng'
},
{
code: 'hr',
name: 'Hrv'
}
],
vueI18n: i18n
}
],
'#nuxtjs/vuetify',
'#nuxtjs/fontawesome'
],
fontawesome: {
icons: {
solid: true,
brands: true
}
},
// Modules: https://go.nuxtjs.dev/config-modules
modules: [
// https://go.nuxtjs.dev/axios
'#nuxtjs/axios',
'#nuxtjs/vuetify',
'nuxt-i18n',
['nuxt-mail', {
message: {
to: 'mislav0508#hotmail.com',
},
smtp: {
host: "smtp-mail.outlook.com",
port: 587,
secure: false, // true for 465, false for other ports
auth: {
user: "mislav0508#hotmail.com",
pass: process.env.EMAIL_PASS,
},
tls: {
rejectUnauthorized:false
}
},
}],
],
// Axios module configuration: https://go.nuxtjs.dev/config-axios
axios: {},
i18n: {
i18n: {
locales: ['hr', 'en'],
defaultLocale: 'hr',
vueI18n: {
fallbackLocale: 'hr',
messages: {
hr: {
welcome: 'Dobrodošli'
},
en: {
welcome: 'Welcome'
}
}
}
}
},
// Vuetify module configuration: https://go.nuxtjs.dev/config-vuetify
vuetify: {
customVariables: ['~/assets/variables.scss'],
theme: {
dark: false,
themes: {
dark: {
primary: colors.blue.darken2,
accent: colors.grey.darken3,
secondary: colors.amber.darken3,
info: colors.teal.lighten1,
warning: colors.amber.base,
error: colors.deepOrange.accent4,
success: colors.green.accent3
}
}
}
},
// Build Configuration: https://go.nuxtjs.dev/config-build
build: {
}
}
I've tried installing vuetify-loader and vue-loader and adding them to the nuxt.config.js file. However after that I get another error:
TypeError: loaderContext.emitError is not a function
Please help.
I am getting this error when I run the app:
ERROR in ./node_modules/primereact/resources/themes/saga-blue/theme.css (./node_modules/css-loader!./node_modules/style-loader!./node_modules/css-loader!./node_modules/primereact/resources/themes/saga-blue/theme.css)
Module build failed (from ./node_modules/css-loader/index.js):
Unknown word (2:1)
1 |
> 2 | var content = require("!!../../../../css-loader/index.js!./theme.css");
| ^
3 |
4 | if(typeof content === 'string') content = [[module.id, content, '']];
5 |
# ./node_modules/primereact/resources/themes/saga-blue/theme.css 2:14-136 21:1-42:3 22:19-141
# ./src/index.js
I have not modified any of the common, dev and prod webpacks. I've read the other 2 questions posted around this but none of the answers worked.
I'll post the webpack configurations for your convenience.
Common:
const path = require('path');
const HtmlWebPackPlugin = require('html-webpack-plugin');
module.exports = {
entry: {
main: path.resolve(__dirname, "../src", "index.js"),
},
output: {
filename: '[name].[hash].js',
path: path.resolve(__dirname, '../dist'),
publicPath: "/"
},
devServer: {
port: 3042,
historyApiFallback: true,
overlay: true,
open: true,
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: [/node_modules/],
use: [{ loader: "babel-loader" }]
},
{
test: /.*\.(gif|png|jp(e*)g|svg)$/i,
use: [
{
loader: "url-loader",
options: {
limit: 21000,
name: "images/[name]_[hash:7].[ext]"
}
}
]
},
// Vendor CSS loader
// This is necessary to pack third party libraries like antd
{
test: /\.css$/,
include: path.resolve(__dirname, '../node_modules'),
use: [
'style-loader',
'css-loader'
],
},
]
},
plugins: [
new HtmlWebPackPlugin({
template: path.resolve(__dirname, '../public', 'index.html'),
}),
],
resolve: {
extensions: ['.js', '.jsx']
},
}
Dev:
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const mapStyle = process.env.MAP_STYLE === 'true';
module.exports = merge (common, {
mode: 'development',
devtool: 'inline-source-map',
devServer: {
port: 3042,
historyApiFallback: true,
overlay: true,
open: true,
stats: 'errors-only'
},
module: {
rules: [
{
test: /\.css$/,
use: [
{ loader: "style-loader" },
{ loader: mapStyle ? "css-loader?sourceMap" : "css-loader" }
]
},
{
test: /\.s(a|c)ss$/,
use: [
{ loader: "style-loader" },
{ loader: "css-loader" },
{ loader: "sass-loader" }
]
},
]
},
plugins: [
new MiniCssExtractPlugin({
filename: "[name].css",
}),
],
});
Prod:
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const OptimizeCssAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const ManifestPlugin = require('webpack-manifest-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const enableBundleAnalyzer = process.env.ENABLE_ANALYZER === 'true';
module.exports = merge(common, {
mode: 'production',
devtool: 'source-map',
module: {
rules: [
{
test: /\.css$/,
use: [
{ loader: MiniCssExtractPlugin.loader },
{ loader: "css-loader" }
]
},
{
test: /\.s(a|c)ss$/,
use: [
{ loader: MiniCssExtractPlugin.loader },
{ loader: "css-loader" },
{ loader: "sass-loader" }
]
},
]
},
optimization: {
splitChunks: {
chunks: 'all',
},
runtimeChunk: false,
},
plugins: [
new CleanWebpackPlugin([path.resolve(__dirname, '../dist')], {
root: process.cwd(),
verbose: true,
dry: false
}),
new OptimizeCssAssetsPlugin(),
new MiniCssExtractPlugin({
filename: "[name].[hash:8].css",
chunkFilename: "[id].[hash:8].css"
}),
new ManifestPlugin(),
new BundleAnalyzerPlugin({
analyzerMode: enableBundleAnalyzer === true ? 'static' : 'disabled',
openAnalyzer: true,
}),
],
});
And here is where I import them:
import React from 'react';
import ReactDOM from 'react-dom';
import {Provider} from 'react-redux';
import App from './components/App';
import store from './app/store';
import './assets/styles/style.sass';
import './assets/styles/style.css';
import './index.scss';
import 'primereact/resources/primereact.min.css';
import 'primeicons/primeicons.css';
import 'primeflex/primeflex.css';
import 'primereact/resources/themes/saga-blue/theme.css';
import '/src/assets/styles/customTheme.scss';
ReactDOM.render(
<React.StrictMode>
<Provider store={store}>
<App />
</Provider>
</React.StrictMode>,
document.getElementById('root')
);
// Check if hot reloading is enable. If it is, changes won't reload the page.
// This is related to webpack-dev-server and works on development only.
if (module.hot) {
module.hot.accept();
}
One of the questions answered this by saying that i needed the url-loader but, as you can see, the boilerplate contains that aswell.
I hope I gave you enough information. Thank you in advance.
I think I've found my answer. I needed to exclude node_modules from the css loader rules from both the dev and prod configurations since the common configuration was handling that. The error was thrown because there were 2 conflicting css loaders.
In my Vue app test file I'm pulling in import Users from '#/models/user';
I've cleared the cache before running the test but it doesn't seem to help..
In the src/models/user.js file I have:
export default class Users {
}
When I run the test I get the error:
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export default function _classCallCheck(instance, Constructor) {
^^^^^^
SyntaxError: Unexpected token export
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
at Object.<anonymous> (src/models/user.js:10:47)
jest.config.js is as follows:
module.exports = {
moduleFileExtensions: [
'js',
'jsx',
'json',
'vue'
],
transform: {
'^.+\\.vue$': 'vue-jest',
'.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub',
'^.+\\.jsx?$': 'babel-jest'
},
moduleNameMapper: {
'^#/(.*)$': '<rootDir>/src/$1'
},
snapshotSerializers: [
'jest-serializer-vue'
],
testMatch: [
'**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)'
],
testURL: 'http://localhost/'
}
and my babel.config.js is:
module.exports = {
presets: [
'#vue/app',
'#babel/preset-env'
]
}
I'm trying to deploy my VueJS Django app to Heroku but running into issues with running webpack on Heroku. I'm able to collect the static files but it doesn't seem like webpack is running (webpack not found) so the website isn't running webpack, which means not only will VueJs files not be transpiled to ES5, but my index.html page will not even call the bundled up code that webpack outputs. Any ideas why this is happening and how to fix it?
On somewhat related notes: I'm using Gunicorn as web server and whitenoise to serve my static files.
Also, once I am able to run webpack, how do I get ride of this error in the console even though I have put es2015 preset in my .babelrc
vendor.js:1 Uncaught SyntaxError: Unexpected token import
import Vue from 'vue'
import ElementUI from 'element-ui'
Here's what I have (mostly everything is based off of VueJS Element starter kit)
Package.json:
{
"name": "element-starter",
"description": "A Vue.js project",
"author": "yi.shyang#ele.me",
"private": true,
"scripts": {
"dev": "webpack-dev-server -d --inline --hot --env.dev",
"heroku-postbuild": "rimraf static && webpack -p --config ./webpack.config.js --progress"
},
"dependencies": {
"element-ui": "^1.1.2",
"vue": "^2.1.8"
},
"engines": {
"node": ">=6"
},
"devDependencies": {
"autoprefixer": "^6.6.0",
"babel-core": "^6.21.0",
"babel-eslint": "^7.1.1",
"babel-loader": "^6.4.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.24.1",
"babel-preset-es2015": "^6.13.2",
"css-loader": "^0.27.0",
"eslint": "^3.12.2",
"eslint-config-enough": "^0.2.2",
"eslint-loader": "^1.6.3",
"file-loader": "^0.10.1",
"html-loader": "^0.4.5",
"html-webpack-plugin": "^2.24.1",
"postcss-loader": "^1.3.3",
"rimraf": "^2.5.4",
"style-loader": "^0.13.2",
"url-loader": "^0.5.8",
"vue-loader": "^11.1.4",
"vue-template-compiler": "^2.1.8",
"webpack": "^2.4.1",
"webpack-dev-server": "^2.4.2"
}
}
Procfile:
web: ./manage.py collectstatic --noinput; npm install; npm run heroku-postbuild; gunicorn dashboard.wsgi --log-file -
.babelrc:
{
"presets": [
["es2015", { "modules": false }]
]
}
webpack.config.js
const {
resolve
} = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const url = require('url')
// where the static files will be accessed from publicly
const publicPath = '/static/'
module.exports = (options = {}) => ({
entry: {
vendor: './src/vendor',
index: './src/main.js'
},
output: {
path: resolve(__dirname, 'static'),
filename: options.dev ? '[name].js' : '[name].js?[chunkhash]',
chunkFilename: '[id].js?[chunkhash]',
publicPath: options.dev ? '/assets/' : publicPath
},
module: {
rules: [{
test: /\.vue$/,
use: ['vue-loader']
},
{
test: /\.js$/,
use: ['babel-loader'],
include: [resolve(__dirname, 'src'), resolve(__dirname, 'static')],
exclude: /node_modules/
},
{
test: /\.html$/,
use: [{
loader: 'html-loader',
options: {
root: resolve(__dirname, 'src'),
attrs: ['img:src', 'link:href']
}
}]
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader', 'postcss-loader']
},
{
test: /favicon\.png$/,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]?[hash]'
}
}]
},
{
test: /\.(png|jpg|jpeg|gif|eot|ttf|woff|woff2|svg|svgz)(\?.+)?$/,
exclude: /favicon\.png$/,
use: [{
loader: 'url-loader',
options: {
limit: 10000
}
}]
}
]
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
names: ['vendor', 'manifest']
}),
new HtmlWebpackPlugin({
template: 'src/index.html',
chunksSortMode: 'dependency'
})
// options:dev ? '' : new webpack.DefinePlugin({
// 'process.env': {
// NODE_ENV: '"production"'
// }
// }),
// options:dev ? '' : new webpack.optimize.UglifyJsPlugin({
// compress: {
// warnings: false
// }
// })
],
resolve: {
alias: {
'~': resolve(__dirname, 'src')
}
},
devServer: {
host: '127.0.0.1',
port: 8010,
proxy: {
'/api/': {
target: 'http://127.0.0.1:8080',
changeOrigin: true,
pathRewrite: {
'^/api': ''
}
}
},
historyApiFallback: {
index: url.parse(options.dev ? '/assets/' : publicPath).pathname
}
},
devtool: options.dev ? '#eval-source-map' : '#source-map'
})