Last active
July 8, 2019 05:30
-
-
Save Jaroost/345678da2530a1463c98dd3fa756054d to your computer and use it in GitHub Desktop.
Webpacker+Vue compile fail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div id="app"> | |
<p>{{ message }}</p> | |
</div> | |
</template> | |
<script> | |
export default { | |
data: function () { | |
return { | |
message: "Hello Vue!" | |
} | |
} | |
} | |
</script> | |
<style scoped> | |
p { | |
font-size: 2em; | |
text-align: center; | |
} | |
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint no-console:0 */ | |
// This file is automatically compiled by Webpack, along with any other files | |
// present in this directory. You're encouraged to place your actual application logic in | |
// a relevant structure within app/javascript and only use these pack files to reference | |
// that code so it'll be compiled. | |
// | |
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate | |
// layout file, like app/views/layouts/application.html.erb | |
// Uncomment to copy all static images under ../images to the output folder and reference | |
// them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>) | |
// or the `imagePath` JavaScript helper below. | |
// | |
// const images = require.context('../images', true) | |
// const imagePath = (name) => images(name, true) | |
console.log('Hello World from Webpacker') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function(api) { | |
var validEnv = ['development', 'test', 'production'] | |
var currentEnv = api.env() | |
var isDevelopmentEnv = api.env('development') | |
var isProductionEnv = api.env('production') | |
var isTestEnv = api.env('test') | |
if (!validEnv.includes(currentEnv)) { | |
throw new Error( | |
'Please specify a valid `NODE_ENV` or ' + | |
'`BABEL_ENV` environment variables. Valid values are "development", ' + | |
'"test", and "production". Instead, received: ' + | |
JSON.stringify(currentEnv) + | |
'.' | |
) | |
} | |
return { | |
presets: [ | |
isTestEnv && [ | |
require('@babel/preset-env').default, | |
{ | |
targets: { | |
node: 'current' | |
} | |
} | |
], | |
(isProductionEnv || isDevelopmentEnv) && [ | |
require('@babel/preset-env').default, | |
{ | |
forceAllTransforms: true, | |
useBuiltIns: 'entry', | |
corejs: 3, | |
modules: false, | |
exclude: ['transform-typeof-symbol'] | |
} | |
] | |
].filter(Boolean), | |
plugins: [ | |
require('babel-plugin-macros'), | |
require('@babel/plugin-syntax-dynamic-import').default, | |
isTestEnv && require('babel-plugin-dynamic-import-node'), | |
require('@babel/plugin-transform-destructuring').default, | |
[ | |
require('@babel/plugin-proposal-class-properties').default, | |
{ | |
loose: true | |
} | |
], | |
[ | |
require('@babel/plugin-proposal-object-rest-spread').default, | |
{ | |
useBuiltIns: true | |
} | |
], | |
[ | |
require('@babel/plugin-transform-runtime').default, | |
{ | |
helpers: false, | |
regenerator: true, | |
corejs: false | |
} | |
], | |
[ | |
require('@babel/plugin-transform-regenerator').default, | |
{ | |
async: false | |
} | |
] | |
].filter(Boolean) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { environment } = require('@rails/webpacker') | |
const { VueLoaderPlugin } = require('vue-loader') | |
const vue = require('./loaders/vue') | |
environment.plugins.prepend('VueLoaderPlugin', new VueLoaderPlugin()) | |
environment.loaders.prepend('vue', vue) | |
/* | |
** CSS loader fixing issue, See https://github.com/rails/webpacker/issues/2162 | |
*/ | |
const cssLoader = environment.loaders.get('css') | |
var cssLoaderLength = cssLoader.use.length | |
for (var i = 0; i < cssLoaderLength; i++) { | |
var loader = cssLoader.use[i] | |
if (loader.loader === 'css-loader') { | |
// Copy localIdentName into modules | |
loader.options.modules = { | |
localIdentName: loader.options.localIdentName | |
} | |
// Delete localIdentName | |
delete loader.options.localIdentName | |
} | |
} | |
const sassLoader = environment.loaders.get('sass') | |
var sassLoaderLength = sassLoader.use.length | |
for (var j = 0; j < sassLoaderLength; j++) { | |
var loader = sassLoader.use[j] | |
if (loader.loader === 'css-loader') { | |
// Copy localIdentName into modules | |
loader.options.modules = { | |
localIdentName: loader.options.localIdentName | |
} | |
// Delete localIdentName | |
delete loader.options.localIdentName | |
} | |
} | |
module.exports = environment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { environment } = require('@rails/webpacker') | |
const { VueLoaderPlugin } = require('vue-loader') | |
const vue = require('./loaders/vue') | |
environment.plugins.prepend('VueLoaderPlugin', new VueLoaderPlugin()) | |
environment.loaders.prepend('vue', vue) | |
module.exports = environment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint no-console: 0 */ | |
// Run this example by adding <%= javascript_pack_tag 'hello_vue' %> (and | |
// <%= stylesheet_pack_tag 'hello_vue' %> if you have styles in your component) | |
// to the head of your layout file, | |
// like app/views/layouts/application.html.erb. | |
// All it does is render <div>Hello Vue</div> at the bottom of the page. | |
import Vue from 'vue' | |
import App from '../app.vue' | |
document.addEventListener('DOMContentLoaded', () => { | |
const app = new Vue({ | |
render: h => h(App) | |
}).$mount() | |
document.body.appendChild(app.$el) | |
console.log(app) | |
}) | |
// The above code uses Vue without the compiler, which means you cannot | |
// use Vue to target elements in your existing html templates. You would | |
// need to always use single file components. | |
// To be able to target elements in your existing html/erb templates, | |
// comment out the above code and uncomment the below | |
// Add <%= javascript_pack_tag 'hello_vue' %> to your layout | |
// Then add this markup to your html template: | |
// | |
// <div id='hello'> | |
// {{message}} | |
// <app></app> | |
// </div> | |
// import Vue from 'vue/dist/vue.esm' | |
// import App from '../app.vue' | |
// | |
// document.addEventListener('DOMContentLoaded', () => { | |
// const app = new Vue({ | |
// el: '#hello', | |
// data: { | |
// message: "Can you say hello?" | |
// }, | |
// components: { App } | |
// }) | |
// }) | |
// | |
// | |
// | |
// If the project is using turbolinks, install 'vue-turbolinks': | |
// | |
// yarn add vue-turbolinks | |
// | |
// Then uncomment the code block below: | |
// | |
// import TurbolinksAdapter from 'vue-turbolinks' | |
// import Vue from 'vue/dist/vue.esm' | |
// import App from '../app.vue' | |
// | |
// Vue.use(TurbolinksAdapter) | |
// | |
// document.addEventListener('turbolinks:load', () => { | |
// const app = new Vue({ | |
// el: '#hello', | |
// data: () => { | |
// return { | |
// message: "Can you say hello?" | |
// } | |
// }, | |
// components: { App } | |
// }) | |
// }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "myapp", | |
"private": true, | |
"dependencies": { | |
"@rails/webpacker": "^4.0.7", | |
"css-loader": "^3.0.0", | |
"vue": "^2.6.10", | |
"vue-loader": "^15.7.0", | |
"vue-template-compiler": "^2.6.10", | |
"webpack": "4.35.2" | |
}, | |
"devDependencies": { | |
"webpack-dev-server": "^3.7.2" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
D:\myapp>ruby .\bin\webpack-dev-server | |
i 「wds」: Project is running at http://localhost:3035/ | |
i 「wds」: webpack output is served from /packs/ | |
i 「wds」: Content not from webpack is served from D:\myapp\public\packs | |
i 「wds」: 404s will fallback to /index.html | |
× 「wdm」: Hash: 9a2c7744862b1d427f2d | |
Version: webpack 4.35.2 | |
Time: 7063ms | |
Built at: 2019-07-04 6:35:19 | |
Asset Size Chunks Chunk Names | |
js/application-8e9cd7377de630a2fb2f.js 386 KiB application [emitted] application | |
js/application-8e9cd7377de630a2fb2f.js.map 435 KiB application [emitted] application | |
js/hello_vue-714fb7aa466ba319db07.js 650 KiB hello_vue [emitted] hello_vue | |
js/hello_vue-714fb7aa466ba319db07.js.map 745 KiB hello_vue [emitted] hello_vue | |
manifest.json 689 bytes [emitted] | |
ERROR in ./app/javascript/app.vue?vue&type=style&index=0&id=6fb8108a&scoped=true&lang=css& (./node_modules/css-loader/dist/cjs.js??ref--3-1!./node_modules/vue-loader/lib/loaders/stylePostLoader.js!./node_modules/postcss-loader/src??ref--3-2!./node_modules/vue-loader/lib??vue-loader-options!./app/javascript/app.vue?vue&type=style&index=0&id=6fb8108a&scoped=true&lang=css&) | |
Module build failed (from ./node_modules/css-loader/dist/cjs.js): | |
ValidationError: CSS Loader Invalid Options | |
options should NOT have additional properties | |
at validateOptions (D:\myapp\node_modules\schema-utils\src\validateOptions.js:32:11) | |
at Object.loader (D:\myapp\node_modules\css-loader\dist\index.js:34:28) | |
i 「wdm」: Failed to compile. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Note: You must restart bin/webpack-dev-server for changes to take effect | |
default: &default | |
source_path: app/javascript | |
source_entry_path: packs | |
public_root_path: public | |
public_output_path: packs | |
cache_path: tmp/cache/webpacker | |
check_yarn_integrity: false | |
webpack_compile_output: false | |
# Additional paths webpack should lookup modules | |
# ['app/assets', 'engine/foo/app/assets'] | |
resolved_paths: [] | |
# Reload manifest.json on all requests so we reload latest compiled packs | |
cache_manifest: false | |
# Extract and emit a css file | |
extract_css: false | |
static_assets_extensions: | |
- .jpg | |
- .jpeg | |
- .png | |
- .gif | |
- .tiff | |
- .ico | |
- .svg | |
- .eot | |
- .otf | |
- .ttf | |
- .woff | |
- .woff2 | |
extensions: | |
- .vue | |
- .mjs | |
- .js | |
- .sass | |
- .scss | |
- .css | |
- .module.sass | |
- .module.scss | |
- .module.css | |
- .png | |
- .svg | |
- .gif | |
- .jpeg | |
- .jpg | |
development: | |
<<: *default | |
compile: true | |
# Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules | |
check_yarn_integrity: true | |
# Reference: https://webpack.js.org/configuration/dev-server/ | |
dev_server: | |
https: false | |
host: localhost | |
port: 3035 | |
public: localhost:3035 | |
hmr: false | |
# Inline should be set to true if using HMR | |
inline: true | |
overlay: true | |
compress: true | |
disable_host_check: true | |
use_local_ip: false | |
quiet: false | |
headers: | |
'Access-Control-Allow-Origin': '*' | |
watch_options: | |
ignored: '**/node_modules/**' | |
test: | |
<<: *default | |
compile: true | |
# Compile test packs to a separate directory | |
public_output_path: packs-test | |
production: | |
<<: *default | |
# Production depends on precompilation of packs prior to booting for performance. | |
compile: false | |
# Extract and emit a css file | |
extract_css: true | |
# Cache manifest.json for performance | |
cache_manifest: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
D:\myapp>rails webpacker:compile | |
Compiling… | |
Compilation failed: | |
D:\myapp> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment