js/chunk-962737f2.1555a4ea.js from UglifyJs Unexpected token: punc «{», expected: punc «;» [js/chunk-962737f2.1555a4ea.js:1,213] - vue.js

useing vue-cli4
Using UglifyJsPlugin then leads to a series of problems because I want to compress the package size of the component to optimize the server response
Babel. Config. Js es2015 has been replaced # Babel/preset - env I did the following configuration
There is still a syntax validation problem
package.json
"dependencies": {
"#babel/preset-react": "^7.9.4",
"#babel/preset-stage-3": "^7.8.3",
"babel": "^6.23.0",
"babel-plugin-transform-runtime": "^7.0.0-beta.3",
"babel-polyfill": "^6.26.0",
"bootstrap": "^4.4.1",
"bootstrap-vue": "^2.12.0",
"cli": "^1.0.1",
"core-js": "^3.6.4",
"markdown-loader": "^5.1.0",
"marked": "^0.8.2",
"mavon-editor": "^2.8.3",
"register-service-worker": "^1.7.1",
"transform-runtime": "0.0.0",
"uglifyjs-webpack-plugin": "^2.2.0",
"vue": "^2.6.11",
"vue-router": "^3.1.6"
},
"devDependencies": {
"#babel/cli": "^7.8.4",
"#babel/core": "^7.9.0",
"#babel/plugin-proposal-class-properties": "^7.4.4",
"#babel/plugin-transform-runtime": "^7.4.4",
"#babel/preset-env": "^7.9.5",
"#babel/runtime": "^7.4.5",
"#vue/cli-plugin-babel": "^4.3.1",
"#vue/cli-plugin-eslint": "^4.3.1",
"#vue/cli-plugin-pwa": "^4.3.1",
"#vue/cli-plugin-router": "^4.3.1",
"#vue/cli-service": "^4.3.1",
"babel-loader": "^7.1.5",
"compression-webpack-plugin": "^3.1.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.2.2",
"sass-loader": "^8.0.2",
"sass-resources-loader": "^2.0.3",
"style-loader": "^1.1.4",
"vue-markdown-loader": "^2.4.1",
"vue-template-compiler": "^2.6.11"
}
babel.config.js
module.exports = {
["#babel/preset-env", {
"targets": {
"browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
}
}]
}
vue.config.js
const path = require('path');
const CompressionPlugin = require('compression-webpack-plugin')
// 配置代码压缩
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
/*配置cdn 引用加速*/
const cdn = {
css: ['https://cdn.bootcss.com/element-ui/2.13.1/theme-chalk/index.css',
'https://cdn.bootcss.com/twitter-bootstrap/4.4.1/css/bootstrap.min.css'
],
js: [
'https://cdn.bootcss.com/jquery/3.5.0/jquery.min.js',
'https://unpkg.com/vue/dist/vue.js',
'https://unpkg.com/element-ui/lib/index.js',
'https://cdn.bootcss.com/element-ui/2.13.1/index.js',
]
}
module.exports = {
publicPath: './',
outputDir: 'dist',
lintOnSave: true,
chainWebpack: (config) => {
config.module
.rule('images')
.use('image-webpack-loader')
.loader('image-webpack-loader')
.options({bypassOnDebug: true})
.end()
config.module.rule('md')
.test(/\.md/)
.use('vue-loader')
.loader('vue-loader')
.end()
.use('vue-markdown-loader')
.loader('vue-markdown-loader/lib/markdown-compiler')
.options({
raw: true
})
config.module.rule('js').test(/\.js$/).use('babel-loader').loader('babel-loader')
/* 配置 babel-loader */
const babel_loader = config.module.rule('babel-loader')
babel_loader.exclude.add(/(node_modules|bower_components)/)
babel_loader.test(/\.(e|j)s$/).use('babel-loader').loader('babel-loader')
if (process.env.NODE_ENV === 'production') {
config.plugin('html')
.tap(args => {
args[0].cdn = cdn;
return args;
});
if (process.env.npm_config_report) {
config
.plugin('webpack-bundle-analyzer')
.use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
.end();
config.plugins.delete('prefetch')
}
} else {
config.plugin('html')
.tap(args => {
args[0].cdn = cdn;
return args;
});
}
},
configureWebpack: (config) => {
config.entry.app = ["babel-polyfill", "./src/main.js"];
if (process.env.NODE_ENV === 'production') {
// 为生产环境修改配置...
config.mode = 'production'
return {
optimization: {
minimizer: [
new UglifyJsPlugin({
uglifyOptions: {
warnings: false,
compress: {
pure_funcs: ['console.log', 'console.debug']//移除console
}
}
})
]
},
externals: {
/* 包名 : 全局变量名*/
'vue': 'Vue',
/*
'vuex': 'Vuex',
'vue-router': 'VueRouter',
'axios': 'axios',*/
// "Bootstrap": "bootstrap",
"elementui": 'ElementUI ',
},
plugins: [
//生产环境自动删除console
/* new UglifyJsPlugin({
uglifyOptions: {
compress: {
warnings: false,
pure_funcs: ['console.log']//移除console
},
/!* compress: {
warnings: false,
drop_debugger: true,
drop_console: true,
},*!/
},
sourceMap: false,
parallel: true,
}),*/ new CompressionPlugin({
test: /\.js$|\.html$|\.css/, //匹配文件名
threshold: 10240, //对超过10k的数据进行压缩
deleteOriginalAssets: false //是否删除原文件
})]
}
} else if (process.env.NODE_ENV === 'development') {
config.mode = 'development';
Object.assign(config, {
resolve: {
alias: {
'#': path.resolve(__dirname, './src'),
'#c': path.resolve(__dirname, './src/components')
}
}
});
return {
externals: {
'vue': 'Vue',
"elementui": 'ElementUI ',
},
plugins: [new CompressionPlugin({
test: /\.js$|\.html$|\.css/,
threshold: 10240,
deleteOriginalAssets: false
})]
}
}
},
productionSourceMap: false,
css: {
extract: false,
sourceMap: false,
loaderOptions: {},
requireModuleExtension: false
},
parallel: require('os').cpus().length > 1,
pwa: {},
devServer: {
open: process.platform === 'darwin',
host: '0.0.0.0',
port: 2001,
https: false,
hotOnly: false,
open: true,
proxy: {
'/data': {
target: 'http://localhost:7000',
changeORIGIN: true
}
},
before: (app) => {
}
},
pluginOptions: {}
}
The above is the full configuration of my project. This problem has been bothering me for many days. I have tried many methods, but they have no effect

Related

vuejs 3: not rendered template from sfc component

I have one project with webpack and i want to add vue to this.
Vue work (function via mounted() show console.log), but i can't render template from sfc component.
Not errors in console.
This trouble component Departments.vue:
<template lang="pug">
.cont
.department 111
</template>
<script>
export default {
name: 'departments',
data() {
return {
deps: '',
}
},
props: {
list: {
type: String,
default: ''
}
},
beforeMount() {
console.log('before');
},
mounted() {
console.log('mount');
}
}
</script>
html(just on the one single page):
<div id="app">
<hr/>
lala <br/>
<departments list='vue list'></departments>
<hr/>
<test></test>
</div>
in app.js:
import { createApp } from 'vue'
import departments from './components/Departments.vue';
const app = createApp({
data() {
return {
count: 134
}
},
// components: {
// departments,
// },
})
app.component('departments', departments)
app.component('test', {
template : '<div><h1>This is coming from component</h1></div>'
})
app.mount('#app')
For testing i added test component inline into app.js - and it's worked!
Here result:
my broken component showing '< ! ---- >' symbols...
package.json
{
"name": "---",
"version": "1.0.0",
"description": "just show me vue templates",
"main": "index.js",
"scripts": {
"dev": "webpack --mode development",
"build": "webpack --mode production"
},
"author": "",
"license": "ISC",
"devDependencies": {
"#vue/compiler-sfc": "^3.2.37",
"autoprefixer": "^10.4.7",
"babel-core": "^6.26.3",
"babel-loader": "^8.2.5",
"babel-preset-env": "^1.7.0",
"browser-sync": "^2.27.10",
"browser-sync-webpack-plugin": "^2.3.0",
"chartist-plugin-pointlabels": "^0.0.6",
"copy-webpack-plugin": "^11.0.0",
"css-loader": "^6.7.1",
"cssnano": "^5.1.12",
"html-webpack-plugin": "^5.5.0",
"jquery": "^3.6.0",
"jquery-mask-plugin": "^1.14.16",
"jquery.cookie": "^1.4.1",
"jquery.photoswipe": "^1.1.1",
"magnific-popup": "^1.1.0",
"mini-css-extract-plugin": "^2.6.1",
"node-loader": "^2.0.0",
"node-sass": "^7.0.1",
"nouislider": "^15.6.0",
"photoswipe": "^5.2.8",
"postcss-loader": "^7.0.1",
"pug": "^2.0.4",
"pug-html-loader": "^1.1.5",
"pug-plain-loader": "^1.1.0",
"resolve-url-loader": "^5.0.0",
"sass": "^1.53.0",
"sass-loader": "^13.0.2",
"style-loader": "^3.3.1",
"swiper": "^8.3.1",
"url-loader": "^4.1.1",
"vue-loader": "^17.0.0",
"vue-style-loader": "^4.1.3",
"vue-template-compiler": "^2.7.7",
"webpack": "^5.73.0",
"webpack-cli": "^4.10.0",
"webpack-node-externals": "^3.0.0"
},
"dependencies": {
"#babel/core": "^7.18.6",
"afterglowplayer": "^1.1.0",
"bigpicture": "^2.6.2",
"chartist": "^0.11.4",
"clean-webpack-plugin": "^4.0.0",
"file-loader": "^6.2.0",
"imagemin-mozjpeg": "^10.0.0",
"imagemin-webpack-plugin": "^2.4.2",
"lity": "^2.4.1",
"vue": "^3.2.37",
"vue-click-outside": "^1.1.0"
}
}
webpack.config.js
const path = require('path');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CleanWebpackPlugin = require('clean-webpack-plugin');
const ImageminPlugin = require('imagemin-webpack-plugin').default;
const CopyWebpackPlugin = require('copy-webpack-plugin');
const BrowserSyncPlugin = require('browser-sync-webpack-plugin')
const webpack = require('webpack');
const { VueLoaderPlugin } = require('vue-loader');
module.exports = {
entry: { main: './src/js/app.js' },
output: {
path: path.resolve(),
filename: '../js/bundle.js'
},
target: 'node',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.scss$/,
use: [
'style-loader',
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
url: false,
},
},
'postcss-loader',
'resolve-url-loader',
{
loader: 'sass-loader',
options: {
sourceMap: true
}
}
]
},
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts/'
}
}]
},
{
test: /\.(png|gif)(\?v=\d+\.\d+\.\d+)?$/,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'images/plugins'
}
}]
},
{
test: /\.vue$/,
loader: 'vue-loader'
},
{
test: /\.pug$/,
loader: 'pug-plain-loader'
}
]
},
plugins: [
new BrowserSyncPlugin({
host: 'localhost',
port: 3000,
server: { baseDir: [path] }
}),
new CopyWebpackPlugin({
patterns:[
{from: 'src/img/', to: '../images/',},
{from: 'src/fonts/', to: '../fonts/',}
]
}),
new ImageminPlugin({
pngquant: {
quality: '100'
},
}),
new MiniCssExtractPlugin({
filename: '../template_styles.css',
}),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery'
}),
new VueLoaderPlugin(),
],
};
can you help me with this error?

How to configure Tailwind + Postcss with VueJS in Laravel InertiaJS

I am new to setting up the tailwind/postcss configuration using Intertia.js/Vue.js and would appreciate some guidance with my configuration files!
My goal is to be able to write postcss/scss style within my vue components, with the ability to use the postcss #apply functionality for example, like so:
Navigation.vue:
<style lang="postcss">
.nav-items {
#apply bg-red;
}
</style>
With the current configuration setup I have, I am not getting any errors compiling however the style is not being applied, it doesn't appear in the Styles in console for the element.
webpack.mix.js
const mix = require('laravel-mix')
const path = require('path')
const purgecss = require('#fullhuman/postcss-purgecss')
const tailwindcss = require('tailwindcss')
mix.js('resources/js/app.js', 'public/js')
.postCss('resources/css/app.css', 'public/css/app.css')
.options({
postCss: [
tailwindcss('tailwind.config.js'),
...mix.inProduction() ? [
purgecss({
content: ['./resources/views/**/*.blade.php', './resources/js/**/*.vue'],
defaultExtractor: content => content.match(/[\w-/:.]+(?<!:)/g) || [],
whitelistPatternsChildren: [/nprogress/],
}),
] : [],
],
})
.webpackConfig({
output: { chunkFilename: 'js/[name].js?id=[chunkhash]' },
resolve: {
alias: {
vue$: 'vue/dist/vue.runtime.js',
'#': path.resolve('resources/js'),
ziggy: path.resolve('vendor/tightenco/ziggy/src/js/route.js'),
},
},
module: {
rules: [
{
test: /\.postcss$/,
loaders: [
"style-loader",
{
loader: "css-loader",
options: { modules: true, importLoaders: 1 }
},
"postcss-loader",
]
}
]
}
})
.version()
.sourceMaps()
tailwind.config.js:
const defaultTheme = require('tailwindcss/defaultTheme')
module.exports = {
purge: [
'./resources/views/**/*.blade.php',
'./resources/css/**/*.css',
],
sourceMap: false,
theme: {
//...
},
plugins: [],
}
postcss.config.js:
module.exports = {
plugins: [
require('postcss-import'),
require('tailwindcss'),
require('autoprefixer'),
],
};
package.json:
{
//...
"devDependencies": {
"#babel/preset-env": "^7.9.6",
"#tailwindcss/custom-forms": "^0.2.1",
"axios": "^0.19",
"cross-env": "^7.0",
"css-loader": "^3.5.3",
"laravel-mix": "^5.0.1",
"laravel-mix-tailwind": "^0.1.0",
"lodash": "^4.17.13",
"postcss-css-variables": "^0.17.0",
"postcss-loader": "^3.0.0",
"postcss-nesting": "^7.0.1",
"resolve-url-loader": "^3.1.0",
"sass": "^1.15.2",
"sass-loader": "^8.0.0",
"style-loader": "^1.2.1",
"tailwindcss": "^1.4",
"vue-svgicon": "^3.2.6",
"vue-template-compiler": "^2.6.11"
},
"dependencies": {
"#babel/plugin-syntax-dynamic-import": "^7.8.3",
"#inertiajs/inertia": "^0.1.9",
"#inertiajs/inertia-vue": "^0.1.4",
"alpinejs": "^2.3.5",
"popper.js": "^1.16.1",
"portal-vue": "^2.1.7",
"postcss-import": "^12.0.1",
"postcss-nested": "^4.2.1",
"postcss-nested-ancestors": "^2.0.0",
"vue": "^2.6.11",
"vue-i18n": "^8.17.7",
"vue-meta": "^2.3.3"
}
}
Add this to webpack.config.js :
module: {
rules: [
{
test: /\.(postcss)$/,
use: [
'vue-style-loader',
{ loader: 'css-loader', options: { importLoaders: 1 } },
'postcss-loader'
]
}
],
},
Found here https://github.com/JeffreyWay/laravel-mix/issues/2211#issuecomment-546123921

Nuxt Hot reloading for new components Is not working

Nuxt hot reloading somehow works for old components, but any new components that I have created today, doesn't seem to be watched by the app, and doesn't reload. I have to restart the app each time to see the changes applied to these new files.
The machine that I am using is MacOs latest Mojave system.
I realized people might ask for the package.json file so here is the file
{
"name": "theta",
"version": "1.0.0",
"description": "My fabulous Nuxt.js project",
"private": true,
"scripts": {
"dev": "NUXT_HOST=0.0.0.0 NUXT_PORT=3333 nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate",
"devHttps": "node server/index.js"
},
"dependencies": {
"#clampy-js/vue-clampy": "^1.0.6",
"#fortawesome/free-brands-svg-icons": "^5.9.0",
"#fortawesome/free-solid-svg-icons": "^5.9.0",
"#nuxtjs/auth": "^4.7.0",
"#nuxtjs/axios": "^5.5.4",
"#nuxtjs/component-cache": "^1.1.5",
"#nuxtjs/dotenv": "^1.3.0",
"#nuxtjs/google-adsense": "^1.1.3",
"#nuxtjs/google-analytics": "^2.2.0",
"#nuxtjs/moment": "^1.2.0",
"#nuxtjs/pwa": "^2.6.0",
"#nuxtjs/robots": "^2.2.0",
"#nuxtjs/style-resources": "^0.1.2",
"#nuxtjs/svg-sprite": "^0.2.1",
"#nuxtjs/toast": "^3.2.1",
"#nuxtjs/vuetify": "^0.5.6",
"#sum.cumo/nuxt-styleguide": "^5.3.0",
"atob": "^2.1.2",
"axios": "^0.19.0",
"browserslist": "^4.6.2",
"caniuse-lite": "^1.0.30000974",
"chart.js": "^2.8.0",
"cookie": "^0.3.1",
"cookie-parser": "^1.4.4",
"cookie-universal-nuxt": "^2.0.16",
"cross-env": "^5.2.0",
"echarts": "^4.2.1",
"element-ui": "^2.9.1",
"epic-spinners": "^1.1.0",
"fstream": "^1.0.12",
"imagemagick": "^0.1.3",
"intersection-observer": "^0.5.1",
"js-yaml": "^3.13.1",
"jwt-decode": "^2.2.0",
"lodash": "^4.17.11",
"lodash-es": "^4.17.11",
"moment": "^2.24.0",
"nuxt": "^2.8.1",
"nuxt-compress": "^1.0.2",
"nuxt-device-detect": "^1.1.5",
"nuxt-fontawesome": "^0.4.0",
"nuxt-stripe-module": "^2.0.0",
"nuxt-universal-storage": "^0.2.0",
"nuxt-validate": "^0.1.3",
"nuxt-webfontloader": "^1.1.0",
"swiper": "^4.5.0",
"tar": "^4.4.10",
"tb-skeleton": "^0.3.6",
"uuid": "^3.3.2",
"v-charts": "^1.19.0",
"v-click-outside-x": "^3.7.1",
"vee-validate": "^2.2.10",
"vue": "^2.6.10",
"vue-avatar-editor-improved": "^1.0.4",
"vue-awesome-swiper": "^3.1.3",
"vue-chartjs": "^3.4.2",
"vue-clamp": "^0.2.1",
"vue-count-to": "^1.0.13",
"vue-croppa": "^1.3.8",
"vue-infinite-loading": "^2.4.4",
"vue-line-clamp": "^1.3.2",
"vue-loaders": "^2.0.0",
"vue-match-media": "^1.0.3",
"vue-scrollama": "^1.1.1",
"vue-scroller": "^2.2.4",
"vue-scrollto": "^2.15.0",
"vue-server-renderer": "^2.6.10",
"vue-swipe-tab": "^2.0.4",
"vue-template-compiler": "^2.6.10",
"vue-text-dot": "^1.0.0",
"vue-the-mask": "^0.11.1",
"vue-tiny-lazyload-img": "^0.1.0",
"vue-truncate-collapsed": "^2.1.0",
"vue-zondicons": "^0.1.10",
"vue2-datepicker": "^2.11.2",
"vue2-editor": "^2.8.1",
"vue2-touch-events": "^1.1.2",
"vuetify-loader": "^1.2.2",
"vuetify-upload-button": "^1.2.2",
"vuex-router-sync": "^5.0.0"
},
"devDependencies": {
"autoprefixer": "^9.6.0",
"css-loader": "^2.1.1",
"moment-locales-webpack-plugin": "^1.0.7",
"node-sass": "^4.12.0",
"nodemon": "^1.19.1",
"postcss-gap-properties": "^2.0.0",
"sass-loader": "^7.1.0",
"style-loader": "^0.23.1",
"stylus": "^0.54.5",
"stylus-loader": "^3.0.2"
}
}
Here is my nuxt config file
const pkg = require('./package')
const webpack = require('webpack')
require('dotenv').config()
module.exports = {
mode: 'universal',
/*
** Headers of the page
*/
head: {
title: 'ノーブル',
meta: [{
charset: 'utf-8'
},
{
name: 'viewport',
content: 'width=device-width, initial-scale=1,minimum-scale=1, maximum-scale=1'
},
{
hid: 'description',
name: 'description',
content: '小説家・読者のプラットフォーム'
}
],
link: [{
rel: 'icon',
type: 'image/x-icon',
href: '/favicon.ico'
}],
script: [{
src: '/js/fb-sdk.js'
}, {
src: '/js/gg-sdk.js'
}]
},
/*
** Customize the progress-bar color
*/
loading: {
color: '#af9bd0',
height: '3px',
continuous: true
},
generate: {
routes: [
'/ads.txt',
]
},
/*
** Global CSS
*/
css: [
'element-ui/lib/theme-chalk/index.css',
'swiper/dist/css/swiper.css',
"assets/css/index.css",
"assets/css/main.scss",
'vue-loaders/dist/vue-loaders.css'
],
/*
** Plugins to load before mounting the App
*/
plugins: [
'#/plugins/element-ui',
'#/plugins/intercept',
{
src: '~plugins/vue-star-rating',
ssr: false
},
{
src: '~/plugins/swiper',
ssr: false
},
{
src: '~/plugins/intercept',
ssr: false
},
{
ssr: false,
src: '~/plugins/avatar'
},
{
ssr: false,
src: "~plugins/clickOutside"
}, {
ssr: false,
src: "~plugins/vueEditor"
}, {
src: '#/plugins/vueMask',
ssr: false
}, {
src: '#/plugins/zondiIcon',
ssr: false
}, {
src: '#/plugins/elementLoading',
ssr: false
}, {
src: '#/plugins/vue-swipe-tab',
ssr: false
},
{
src: '#/plugins/pull-to',
ssr: false
},
{
src: '#/plugins/datePicker',
ssr: false
}, {
src: '#/plugins/vuelineclamp',
ssr: false
}, {
src: '#/plugins/graphs',
ssr: false
}, {
src: '#/plugins/infinite',
ssr: false
}, {
src: '#/plugins/vueClamp',
ssr: false
}, {
src: '#/plugins/watchMedia',
ssr: false
}, {
src: '#/plugins/scrollama',
ssr: false
}, {
src: '#/plugins/countTo',
ssr: false
}, {
src: '#/plugins/chartLine',
ssr: false
}, {
src: '#/plugins/skeleton',
ssr: false
}, {
src: '#/plugins/gAuth',
ssr: false,
}, {
src: '#/plugins/epicSpinners',
ssr: false,
},
{
src: '#/plugins/auth',
}
],
/*
** Nuxt.js modules
*/
modules: [
['#nuxtjs/vuetify', {
treeShake: true
}],
'#nuxtjs/pwa',
'nuxt-device-detect',
'nuxt-webfontloader',
'#nuxtjs/axios',
'#nuxtjs/dotenv',
'#nuxtjs/svg-sprite',
'#nuxtjs/style-resources',
['nuxt-validate', {
lang: 'ja',
}],
['#nuxtjs/robots', {
UserAgent: '*',
Disallow: '/',
UserAgent: 'Googlebot',
Disallow: '',
UserAgent: 'Yahoo-slurp',
Disallow: '',
UserAgent: 'Msnbot',
Disallow: ''
}],
['#nuxtjs/moment', {
locales: ['ja'],
defaultLocale: 'ja'
}],
['#nuxtjs/component-cache', {
maxAge: 1000 * 60 * 60
}],
['#nuxtjs/google-adsense', {
id: 'pub-4438410171989811'
}],
'cookie-universal-nuxt',
['nuxt-fontawesome', {
component: 'fa',
imports: [{
set: '#fortawesome/free-solid-svg-icons',
icons: ['fas']
}, {
set: '#fortawesome/free-brands-svg-icons',
icons: ['fab']
}]
}],
['#nuxtjs/google-analytics', {
id: 'UA-119733183-2',
autoTracking: {
page: false
}
}],
['nuxt-universal-storage', {
storage: {
vuex: true, // boolean or {namespace}
localStorage: true, // boolean or {prefix }
cookie: true, // boolean or {prefix, options }
initialState: {}, // Object {}
ignoreExceptions: true //
}
}],
['#nuxtjs/dotenv', {
/* module options */
}],
['#nuxtjs/toast', {
position: 'top-right',
duration: 5000
}],
['nuxt-stripe-module', {
publishableKey: process.env.STRIPE_KEY,
version: 'v3', // Default
}],
"nuxt-compress",
],
/*
** Axios module configuration
*/
axios: {
baseURL: process.env.SERVER_URL || 'http://0.0.0.0:5000/api',
credentials: false,
proxyHeaders: false
},
auth: {
strategies: {
google: {
client_id: process.env.GOOGLE_CLIENT_ID,
user: false,
redirect_uri: 'http://127.0.0.1:3000/'
},
facebook: {
client_id: process.env.FACEBOOK_CLIENT_ID,
userinfo_endpoint: false,
scope: ['public_profile', 'email'],
redirect_uri: 'https://tolocalhost.com/'
},
local: {
_scheme: '~/auth/local.js',
endpoints: {
login: {
url: 'auth/login',
method: 'post',
propertyName: false
},
user: {
url: 'user/show',
method: 'get',
propertyName: false
},
logout: false
}
}
},
redirect: {
login: '/auth/login',
logout: '/',
callback: '/',
home: '/'
},
plugins: ['~/plugins/auth.js']
},
router: {
middleware: ['auth'],
linkActiveClass: 'active-link'
},
webfontloader: {
google: {
families: ['IBM Plex Sans:300,400,700', 'Noto Sans JP:400,500', 'Sniglet:400,800'] //Loads Lato font with weights 400 and 700
}
},
'manifest': {
name: 'ノーブル 小説',
short_name: 'ノーブル',
lang: 'ja'
},
/*
** Build configuration
*/
build: {
/*
** You can extend webpack config here
*/
extend(config, ctx) {
},
splitChunks: {
layouts: true
},
styleResources: {
sass: ['./assets/css/abstracts/main.scss']
},
transpile: ['vue-clamp', 'resize-detector'],
postcss: {
plugins: [
require('postcss-gap-properties')(),
require('autoprefixer')({
grid: true,
flexbox: true,
stats: {
warnings: false
}
})
]
},
plugins: [new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery'
})]
},
server: {
port: process.env.CLIENT_PORT || 4000, // default: 3000
host: process.env.API_HOST || '0.0.0.0', // default: localhost
},
}
I've searched everywhere online for the answer but none that seemed close to my current situation.
Oh I got it, it seems like there was a misspelling in importing of the component, and thus wasn't connected to the main nuxt network, meaning the component doesn't adhere to the hot reloading watched file.
Had the problem of hot reload not working.
Solved that by adding
watchers: {
webpack: {
aggregateTimeout: 300,
poll: 1000
}
}
in the nuxt.config.js file.

Webpack 2 bundle typescript files with same namespace into a single file

I am new to Webpack and bundling typescript files into a single file. I got the following setup where I would like to achieve a single JS files with all my typescript bundled.
tsconfig.json:
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"module": "commonjs",
"noEmitOnError": true,
"noImplicitAny": false,
"removeComments": true,
"sourceMap": true,
"target": "es6",
"moduleResolution": "node"
},
"exclude": [
"node_modules",
"libs"
]
}
Webpack.config.js
var path = require("path");
const { CheckerPlugin } = require('awesome-typescript-loader');
const config = {
entry: {
Bootstrap: "./Bootstrapper.ts"
},
output: {
//output file naming conventions https://webpack.js.org/configuration/output/#output-filename when having more different configs with outputs
filename: "[name].bundle.js",
path: path.resolve(__dirname, "wwwroot/dist")
},
context: path.resolve(__dirname, "App"),
devtool: "inline-source-map",
module: {
rules: [
{
test: /\.tsx?$/,
loader: "awesome-typescript-loader"
}
]
},
plugins: [
new CheckerPlugin()
]
}
module.exports = config;
Bootstrap typescript file where I incude some node_module that actually work. JQuery works for instance. But If I try to use the class and subclasses that I use from a single namespace I walk against a wall.
Bootstrapper.ts
import * as $ from "jquery";
import * as Konva from "konva";
import * as SignalR from "#aspnet/signalr";
import * as ko from "knockout";
//How do I use these classes that are in different files
import App = Project.Web.Core.App;
$("document").ready(() => {
let app = new App();
alert("This works if I leave the App reference out!");
});
This is the App.ts that I try to use (import App = Project.Web.Core.App;)
namespace Project.Web.Core {
export class App {
pageId: number = 0;
pageRequestId: string = "";
//drawingManager = new Managers.KonvaDrawManager();
signalRmanager = new Managers.SignalRmanager("");
constructor() {
$("document").ready(() => {
this.pageId = $("#container").data("pageid");
this.pageRequestId = $("#container").data("pagerequestid");
this.signalRmanager.pageRequestId = this.pageRequestId;
//this.signalRmanager.setupSignalRConnection(this.drawingManager);
this.loadCanvasData();
});
window.onresize = () => {
//this.drawingManager.rescale();
};
window.onunload = () => {
this.signalRmanager.notifyPageUnloaded();
}
}
loadCanvasData() {
this.pageId = $("#container").data("pageid");
$.get({
dataType: "json",
url: `api/page/${this.pageId}/stage`,
success: (data: any) => {
//this.drawingManager.initializeStage(data);
},
complete: (data: any) => {
if (data.status === 200) {
this.signalRmanager.notifyPageLoaded();
}
}
});
}
}
}
Packages I use
{
"name": "Project.Web_core",
"private": true,
"version": "0.0.0",
"scripts": {
"build": "./node_modules/.bin/webpack -d",
"build:prod": "./node_modules/.bin/webpack -p",
"watch": "./node_modules/.bin/webpack --watch",
"dev": "./node_modules/.bin/webpack-dev-server"
},
"devDependencies": {
"#types/jquery": "^3.3.1",
"#types/knockout": "^3.4.53",
"#types/knockout.mapping": "^2.0.33",
"#types/webpack-env": "1.13.5",
"aspnet-prerendering": "^3.0.1",
"aspnet-webpack": "^2.0.3",
"awesome-typescript-loader": "^5.0.0",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.4",
"event-source-polyfill": "0.0.12",
"json-loader": "0.5.7",
"node-sass": "^4.8.3",
"sass-loader": "^6.0.7",
"style-loader": "0.20.1",
"typescript": "2.7.1",
"uglifyjs-webpack-plugin": "^1.2.4",
"webpack": "^4.5.0",
"webpack-cli": "^2.0.14",
"webpack-dev-middleware": "^3.1.2",
"webpack-dev-server": "^3.1.3",
"webpack-merge": "4.1.1"
},
"dependencies": {
"#aspnet/signalr": "^1.0.0-preview1-update1",
"es5-shim": "^4.5.10",
"es6-shim": "^0.35.3",
"jquery": "3.3.1",
"knockout": "^3.4.2",
"knockout-mapping": "^2.6.0",
"konva": "^2.0.2",
"watchpack": "^1.4.0"
}
}
I hope someone can help me out clearify my wrong way of thinking.
There are several things:
Typescript config, you can copy. With your types
change import export and remove namespace
export class App { ... }
import { App } from '/path/to/your/file';
class needs a destroyer
and finally in webpack.config.js you can set properties
entry: {
Bootstrap: "./Bootstrapper.ts",
namespace: "./path-to-your-namespace.ts",
anotherNamespace: "./path-to-your-anotherNamespace.ts"
},
resolve: {
extensions: ['.js', '.ts', '.json']
}

.bind no longer working after upgrading to new Aurelia webpack plugins

I'm trying to update my Aurelia project that uses webpack so I can require .scss files in my templates. I've looked at the Aurelia Skeleton project for webpack and have followed this guide to come up with my webpack.config which is listed below. I have also included my package.json file.
I am able to load styles now, but have come across a perplexing issue. None of the my bind statements work anymore. The code itself didn't change and was working fine before this update attempt. I tried using two-way, one-way, etc, but that didn't work either. The #bindable property is always undefined.
<my-custom-element value.bind="something"></my-custom-element>
In MyCustomElement, value is always undefined although something is set properly.
I have tried walking back the package versions and I think it has to do with aurelia-bootstrapper, but I'm not sure.
I'm out of ideas on how to debug this issue. Any help would be much appreciated.
webpack.config.js
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const DashboardPlugin = require('webpack-dashboard/plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const { AureliaPlugin, ModuleDependenciesPlugin } = require('aurelia-webpack-plugin');
const { optimize: { CommonsChunkPlugin }, ProvidePlugin } = require('webpack')
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const project = require('./package.json');
// config helpers:
const ensureArray = (config) => config && (Array.isArray(config) ? config : [config]) || []
const when = (condition, config, negativeConfig) =>
condition ? ensureArray(config) : ensureArray(negativeConfig)
// primary config:
const title = 'Radar';
const outDir = path.resolve(__dirname, 'dist');
const srcDir = path.resolve(__dirname, 'src');
const nodeModulesDir = path.resolve(__dirname, 'node_modules');
const baseUrl = '/';
// If not done this way the plugin will try to load when only a build is required and cause it to hang.
const addDashboardPlugin = process.env.npm_lifecycle_event === 'webpack' ? [] : [new DashboardPlugin({
port: 3333
})];
const metadata = {
port: process.env.WEBPACK_PORT || 9000,
host: process.env.WEBPACK_HOST || 'localhost'
};
const cssRules = [
{ loader: 'css-loader' },
{
loader: 'postcss-loader',
options: { plugins: () => [require('autoprefixer')({ browsers: ['last 2 versions'] })] }
}
]
module.exports = ({ production, server, extractCss, coverage } = {}) => ({
resolve: {
extensions: ['.js'],
modules: [srcDir, 'node_modules'],
},
entry: {
app: ['aurelia-bootstrapper'],
aurelia: Object.keys(project.dependencies).filter(dep => dep.startsWith('aurelia-')),
vendor: Object.keys(project.dependencies).filter(dep => !dep.startsWith('aurelia-'))
},
devtool: production ? 'source-map' : 'inline-source-map',
output: {
path: outDir,
publicPath: baseUrl,
filename: production ? '[name].[chunkhash].bundle.js' : '[name].[hash].bundle.js',
sourceMapFilename: production ? '[name].[chunkhash].bundle.map' : '[name].[hash].bundle.map',
chunkFilename: production ? '[name].[chunkhash].chunk.js' : '[name].[hash].chunk.js',
},
devServer: {
contentBase: outDir,
// serve index.html for all 404 (required for push-state)
historyApiFallback: true,
port: metadata.port,
host: metadata.host,
watchOptions: {
aggregateTimeout: 300,
poll: 1000
}
},
module: {
rules: [
{
test: /\.scss$/i,
issuer: [{ not: [{ test: /\.html$/i }] }],
loaders: ['style-loader', 'css-loader?sourceMap', 'sass-loader?sourceMap']
},
{
test: /\.scss$/i,
issuer: [{ test: /\.html$/i }],
loaders: ['css-loader?sourceMap', 'sass-loader?sourceMap']
},
// CSS required in JS/TS files should use the style-loader that auto-injects it into the website
// only when the issuer is a .js/.ts file, so the loaders are not applied inside html templates
{
test: /\.css$/i,
issuer: [{ not: [{ test: /\.html$/i }] }],
use: extractCss ? ExtractTextPlugin.extract({
fallback: 'style-loader',
use: cssRules,
}) : ['style-loader', ...cssRules],
},
{
test: /\.css$/i,
issuer: [{ test: /\.html$/i }],
// CSS required in templates cannot be extracted safely
// because Aurelia would try to require it again in runtime
use: cssRules,
},
{ test: /\.html$/i, loader: 'html-loader' },
{
test: /\.js$/i, loader: 'babel-loader', exclude: nodeModulesDir,
options: coverage ? { sourceMap: 'inline', plugins: ['istanbul'] } : {},
},
{ test: /\.json$/i, loader: 'json-loader' },
// use Bluebird as the global Promise implementation:
{ test: /[\/\\]node_modules[\/\\]bluebird[\/\\].+\.js$/, loader: 'expose-loader?Promise' },
// embed small images and fonts as Data Urls and larger ones as files:
{ test: /\.(png|gif|jpg|cur)$/i, loader: 'url-loader', options: { limit: 8192 } },
{ test: /\.woff2(\?v=[0-9]\.[0-9]\.[0-9])?$/i, loader: 'url-loader', options: { limit: 10000, mimetype: 'application/font-woff2' } },
{ test: /\.woff(\?v=[0-9]\.[0-9]\.[0-9])?$/i, loader: 'url-loader', options: { limit: 10000, mimetype: 'application/font-woff' } },
// load these fonts normally, as files:
{ test: /\.(ttf|eot|svg|otf)(\?v=[0-9]\.[0-9]\.[0-9])?$/i, loader: 'file-loader' },
]
},
plugins: [
new AureliaPlugin(),
new ModuleDependenciesPlugin({
'aurelia-dialog': ['./ai-dialog', './ai-dialog-header', './ai-dialog-footer', './ai-dialog-body',
'./attach-focus', './dialog-configuration', './dialog-controller', './dialog-options', './dialog-renderer',
'./dialog-result', './dialog-service', './lifecycle', './renderer'],
'aurelia-chart': ['./elements/chart-element', './attributes/chart-attribute', './observers/model-observer']
}),
new ProvidePlugin({
'Promise': 'bluebird'
}),
new HtmlWebpackPlugin({
template: 'index.ejs',
minify: production ? {
removeComments: true,
collapseWhitespace: true
} : undefined,
metadata: {
title, server, baseUrl
},
}),
new CopyWebpackPlugin([
{ from: 'src/config', to: 'config' },
{ from: 'styles/img', to: 'img' }
]),
...when(extractCss, new ExtractTextPlugin({
filename: production ? '[contenthash].css' : '[id].css',
allChunks: true,
})),
...when(production, new CommonsChunkPlugin({
name: 'common'
})),
new OptimizeCssAssetsPlugin({
assetNameRegExp: /\.scss$/i,
cssProcessor: require('cssnano'),
cssProcessorOptions: { discardComments: { removeAll: true } },
canPrint: true
})
].concat(addDashboardPlugin)
})
package.json
"dependencies": {
"aurelia-animator-css": "^1.0.0",
"aurelia-application-insights": "^1.0.0",
"aurelia-binding": "^1.2.0",
"aurelia-bootstrapper": "^2.1.1",
"aurelia-chart": "^0.2.6",
"aurelia-configuration": "1.0.17",
"aurelia-dependency-injection": "^1.3.1",
"aurelia-dialog": "^1.0.0-beta.3.0.0",
"aurelia-event-aggregator": "^1.0.1",
"aurelia-fetch-client": "^1.1.2",
"aurelia-framework": "^1.1.0",
"aurelia-history": "^1.0.0",
"aurelia-history-browser": "^1.0.0",
"aurelia-logging": "^1.3.1",
"aurelia-logging-console": "^1.0.0",
"aurelia-metadata": "^1.0.3",
"aurelia-notify": "^0.8.1",
"aurelia-pal": "^1.3.0",
"aurelia-pal-browser": "^1.1.0",
"aurelia-path": "^1.0.0",
"aurelia-route-recognizer": "^1.0.0",
"aurelia-router": "^1.3.0",
"aurelia-task-queue": "^1.2.0",
"aurelia-templating": "^1.3.0",
"aurelia-templating-binding": "^1.3.0",
"aurelia-templating-resources": "^1.3.1",
"aurelia-templating-router": "^1.1.0",
"aurelia-validation": "^1.0.0",
"bluebird": "^3.3.5",
"json-loader": "^0.5.4",
... //omitted for clarity
},
"devDependencies": {
"aurelia-loader-nodejs": "^1.0.1",
"aurelia-pal-nodejs": "^1.0.0-beta.1.0.0",
"aurelia-tools": "^1.0.0",
"aurelia-webpack-plugin": "^2.0.0-rc.2",
"autoprefixer": "^7.0.0",
"babel-core": "^6.17.0",
"babel-eslint": "^7.2.3",
"babel-loader": "^7.0.0",
"babel-plugin-istanbul": "^4.1.3",
"babel-plugin-lodash": "^3.2.10",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-decorators": "^6.24.1",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-polyfill": "^6.16.0",
"babel-preset-env": "^1.5.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-1": "^6.24.1",
"babel-register": "^6.11.6",
"concurrently": "^2.2.0",
"copy-webpack-plugin": "^4.0.1",
"cross-env": "^3.1.3",
"css-loader": "^0.28.1",
"eslint": "^3.12.2",
"extract-text-webpack-plugin": "^2.1.0",
"file-loader": "^0.9.0",
"html-server": "^0.1.1",
"html-webpack-plugin": "^2.22.0",
"json-loader": "^0.5.4",
"node-sass": "^3.13.0",
"optimize-css-assets-webpack-plugin": "^1.3.2",
"package": "^1.0.1",
"postcss-loader": "^1.3.3",
"raw-loader": "^0.5.1",
"rimraf": "^2.5.2",
"sass-loader": "^4.0.2",
"style-loader": "^0.17.0",
"url-loader": "^0.5.8",
"webpack": "^2.6.1",
"webpack-dashboard": "^0.2.0",
"webpack-dev-server": "^2.4.5"
}
nav-bar.html
<template>
<require from='./_nav-bar.scss'></require>
<section class="nav-bar nav-bar__group" data-grid="full">
<div data-grid="full">
<main-menu router.bind="router" data-grid="21"></main-menu>
<user-panel data-grid="3"></user-panel>
</div>
</section>
</template>
main-menu.html
<template class="main-menu">
<ul class="main-menu__nav-list">
<li repeat.for="row of router.navigation">
<a href.bind="row.href"
data-appinsights-category="navigation"
data-appinsights-action="${row.title}"
data-text="${row.title}">
${row.title}
</a>
</li>
</ul>
</template>
main-menu.js
import { bindable, inject } from 'aurelia-framework';
#inject(Element)
export class MainMenuCustomElement {
//This value is always undefined now
#bindable router;
constructor(element) {
this.element = element;
}
toggleMenu() {
//removed for brevity
}
}
I got it to work after adding import babel-polyfill to main.js, changing .babelrc to reference `.babelrc.js like so:
{
"presets": [ "./.babelrc.js" ]
}
I also included .babelrc.js from the skeleton-navigation project.
.babelrc.js
// this file will be used by default by babel#7 once it is released
module.exports = {
"plugins": [
"transform-decorators-legacy",
"transform-class-properties"
],
"presets": [
[
"env", {
"targets": process.env.BABEL_TARGET === 'node' ? {
"node": process.env.IN_PROTRACTOR ? '6' : 'current'
} : {
"browsers": [
"last 2 versions",
"not ie <= 11"
],
"uglify": process.env.NODE_ENV === 'production',
},
"loose": true,
"modules": process.env.BABEL_TARGET === 'node' ? 'commonjs' : false,
"useBuiltIns": true
}
]
]
}